aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-node/src/meshbay_node/cli/lifecycle.py
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-node/src/meshbay_node/cli/lifecycle.py')
-rw-r--r--packages/meshbay-node/src/meshbay_node/cli/lifecycle.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/packages/meshbay-node/src/meshbay_node/cli/lifecycle.py b/packages/meshbay-node/src/meshbay_node/cli/lifecycle.py
index b461055..1c9e026 100644
--- a/packages/meshbay-node/src/meshbay_node/cli/lifecycle.py
+++ b/packages/meshbay-node/src/meshbay_node/cli/lifecycle.py
@@ -179,6 +179,35 @@ def restart_daemon(args) -> None:
return
+# In the Store package the sign-in start is the package's startup task, which
+# Windows lists in Settings > Apps > Startup (platform.startup_task).
+STORE_SIGNIN = ("In MeshBay from the Microsoft Store, the node starts at sign-in through "
+ "the \"MeshBay Node\" entry of Windows Settings > Apps > Startup "
+ "(meshbay-node autostart install | remove).")
+
+
+def _store_autostart(sub: str) -> None:
+ """autostart install | remove | status in the Store package. The first line
+ is "startup task <state>", which the desktop app reads."""
+ from meshbay_node import platform as _plat
+ action = {"install": "enable", "remove": "disable", "status": "query"}[sub]
+ try:
+ state = _plat.startup_task(action)
+ except RuntimeError as e:
+ print(f"Could not reach {e}")
+ sys.exit(1)
+ print(f"startup task {state}")
+ if state == "DisabledByUser":
+ print("Switched off in Windows Settings > Apps > Startup (\"MeshBay Node\"): "
+ "only you can switch it back on, there.")
+ elif state.endswith("ByPolicy"):
+ print("Set by a policy on this computer.")
+ elif state == "Enabled":
+ print("meshbay-node starts at each sign-in (no window, no admin).")
+ if sub == "install" and not state.startswith("Enabled"):
+ sys.exit(1)
+
+
def autostart(args) -> None:
from meshbay_node import platform as _plat
if sys.platform != "win32":
@@ -186,6 +215,9 @@ def autostart(args) -> None:
"'systemctl --user enable --now meshbay-node'.")
sys.exit(1)
sub = args.subcommand or "status"
+ if sub in ("install", "remove", "status") and _plat.in_store_package():
+ _store_autostart(sub)
+ return
service_mode = _plat.service_status()["installed"]
if sub == "install":
if service_mode:
@@ -226,6 +258,11 @@ def service(args) -> None:
"'systemctl --user enable --now meshbay-node'.")
sys.exit(1)
sub = args.subcommand or "status"
+ if sub == "install" and _plat.in_store_package():
+ print("Starting the node at boot, before anyone signs in, needs MeshBay's .exe "
+ "installer: the Microsoft Store version starts it at sign-in at most. "
+ + STORE_SIGNIN)
+ sys.exit(1)
if sub == "install":
# A node already running in this session holds the control API's port:
# the service's own would exit at once, leaving the old one in charge.