mirror of
https://github.com/tcsenpai/pensieve.git
synced 2025-06-10 13:07:15 +00:00
feat(init): add watch for init start
This commit is contained in:
parent
0906406b74
commit
a4d80cc7d3
@ -197,7 +197,9 @@ def watch_default_library(
|
|||||||
sparsity_factor: float = typer.Option(
|
sparsity_factor: float = typer.Option(
|
||||||
2.0, "--sparsity-factor", "-sf", help="Sparsity factor for file processing"
|
2.0, "--sparsity-factor", "-sf", help="Sparsity factor for file processing"
|
||||||
),
|
),
|
||||||
verbose: bool = typer.Option(False, "--verbose", "-v", help="Enable verbose logging")
|
verbose: bool = typer.Option(
|
||||||
|
False, "--verbose", "-v", help="Enable verbose logging"
|
||||||
|
),
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Watch the default library for file changes and sync automatically.
|
Watch the default library for file changes and sync automatically.
|
||||||
@ -211,7 +213,7 @@ def watch_default_library(
|
|||||||
folders=None,
|
folders=None,
|
||||||
window_size=window_size,
|
window_size=window_size,
|
||||||
sparsity_factor=sparsity_factor,
|
sparsity_factor=sparsity_factor,
|
||||||
verbose=verbose
|
verbose=verbose,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -233,14 +235,12 @@ def generate_windows_bat():
|
|||||||
activate_path = os.path.join(conda_prefix, "Scripts", "activate.bat")
|
activate_path = os.path.join(conda_prefix, "Scripts", "activate.bat")
|
||||||
content = f"""@echo off
|
content = f"""@echo off
|
||||||
call "{activate_path}"
|
call "{activate_path}"
|
||||||
start "" "{python_path}" -m memos.commands record
|
start "Memos" cmd /c ""{python_path}" -m memos.commands record & "{python_path}" -m memos.commands serve & timeout /t 5 /nobreak >nul & "{python_path}" -m memos.commands watch"
|
||||||
start "" "{python_path}" -m memos.commands serve
|
|
||||||
"""
|
"""
|
||||||
else:
|
else:
|
||||||
# If we're not in a Conda environment, use the original content
|
# If we're not in a Conda environment, use the original content
|
||||||
content = f"""@echo off
|
content = f"""@echo off
|
||||||
start "" "{python_path}" -m memos.commands record
|
start "Memos" cmd /c ""{python_path}" -m memos.commands record & "{python_path}" -m memos.commands serve & timeout /t 5 /nobreak >nul & "{python_path}" -m memos.commands watch"
|
||||||
start "" "{python_path}" -m memos.commands serve
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
bat_path = memos_dir / "launch.bat"
|
bat_path = memos_dir / "launch.bat"
|
||||||
@ -264,6 +264,12 @@ fi
|
|||||||
# run memos serve
|
# run memos serve
|
||||||
{python_path} -m memos.commands serve &
|
{python_path} -m memos.commands serve &
|
||||||
|
|
||||||
|
# wait for 5 seconds before starting memos watch
|
||||||
|
sleep 5
|
||||||
|
|
||||||
|
# run memos watch
|
||||||
|
{python_path} -m memos.commands watch &
|
||||||
|
|
||||||
# wait for all background processes
|
# wait for all background processes
|
||||||
wait
|
wait
|
||||||
"""
|
"""
|
||||||
@ -325,9 +331,29 @@ def generate_plist():
|
|||||||
return plist_path
|
return plist_path
|
||||||
|
|
||||||
|
|
||||||
|
def is_service_loaded(service_name):
|
||||||
|
try:
|
||||||
|
result = subprocess.run(
|
||||||
|
["launchctl", "list", service_name],
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
check=True,
|
||||||
|
)
|
||||||
|
return "0" in result.stdout
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def load_plist(plist_path):
|
def load_plist(plist_path):
|
||||||
subprocess.run(["launchctl", "unload", str(plist_path)], check=False)
|
user_domain = f"gui/{os.getuid()}"
|
||||||
subprocess.run(["launchctl", "load", str(plist_path)], check=True)
|
service_name = "com.user.memos"
|
||||||
|
|
||||||
|
if is_service_loaded(service_name):
|
||||||
|
subprocess.run(
|
||||||
|
["launchctl", "bootout", user_domain, str(plist_path)], check=False
|
||||||
|
)
|
||||||
|
|
||||||
|
subprocess.run(["launchctl", "bootstrap", user_domain, str(plist_path)], check=True)
|
||||||
|
|
||||||
|
|
||||||
def is_macos():
|
def is_macos():
|
||||||
@ -373,11 +399,19 @@ def disable():
|
|||||||
|
|
||||||
plist_path = Path.home() / "Library/LaunchAgents/com.user.memos.plist"
|
plist_path = Path.home() / "Library/LaunchAgents/com.user.memos.plist"
|
||||||
if plist_path.exists():
|
if plist_path.exists():
|
||||||
subprocess.run(["launchctl", "unload", str(plist_path)], check=False)
|
user_domain = f"gui/{os.getuid()}"
|
||||||
|
service_name = "com.user.memos"
|
||||||
|
|
||||||
|
if is_service_loaded(service_name):
|
||||||
|
subprocess.run(
|
||||||
|
["launchctl", "bootout", user_domain, str(plist_path)], check=False
|
||||||
|
)
|
||||||
|
typer.echo("Unloaded Memos service.")
|
||||||
|
else:
|
||||||
|
typer.echo("Memos service was not running.")
|
||||||
|
|
||||||
plist_path.unlink()
|
plist_path.unlink()
|
||||||
typer.echo(
|
typer.echo("Removed plist file. Memos will no longer run at startup.")
|
||||||
"Unloaded and removed plist file. Memos will no longer run at startup."
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
typer.echo("Plist file does not exist. Memos is not set to run at startup.")
|
typer.echo("Plist file does not exist. Memos is not set to run at startup.")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user