Skip to content

feat: settings for running in the background and starting with Windows - #40

Merged
httpsphl merged 2 commits into
mainfrom
feat/background-settings
Sep 29, 2026
Merged

httpsphl merged 2 commits into
mainfrom
feat/background-settings

Conversation

@httpsphl

Copy link
Copy Markdown
Owner

What

Settings gets a section called In the background, with three switches. Each one has a line that says what the current choice does:

  • Keep working after you close Botloft (on by default). When it is off, closing the window hides it, stops the bots and then closes. The bots pick up where they left off when Botloft opens again, and the app says "Starting your bots…". This choice is stored by the app (botloft.whenClosed).
  • Start with Windows (on by default). When it is off, the bots wait after a restart until the owner opens Botloft.
  • Keep the computer awake while bots work (the existing keep_awake). It now changes without restarting anything.

The About section also gets Check for updates. It asks the release feed right away and either says this is the latest version or shows See the update.

How

  • Daemon settings API: new settings.get and settings.update calls. The daemon saves only the key that changed in config.toml, using toml_edit, so the owner's own lines and comments stay. The new file replaces the old one in a single rename.
  • Scheduled task: its triggers follow the choices.
    • While running: the 1-minute trigger, plus the sign-in trigger when Botloft starts with Windows.
    • After service stop: only the sign-in trigger, and only when Botloft starts with Windows.
  • New sign-in check: the 1-minute trigger also fires after a new sign-in. A daemon started by the task (--scheduled) compares the current sign-in with <home>\signin, which holds the session id and sign-in time from WTSQuerySessionInformationW. If Botloft does not start with Windows, it takes the triggers off and exits, until the app runs install. If the daemon crashes within the same sign-in, it still comes back.
  • App side: a new Tauri command, daemon_stop. The app also listens to onCloseRequested, which needs the hide and destroy permissions.
  • Refactor: the routine switch now uses the shared Switch component.
  • Spec: sections 6, 11.2, 14, 15.1 and 15.2.

Tests

  • cargo test (daemon, core, store), clippy -D warnings (including botloft-app), fmt, and pnpm check: all pass (151 app tests).
  • New tests:
    • task XML with each trigger combination;
    • the sign-in record;
    • saving settings keeps the owner's comments;
    • keep-awake follows the setting;
    • RPC settings;
    • the app: switches, a failed save rolls back, checking for updates, closing with and without stopping, reopening after a stop, and the welcome line.

Real test (Windows 11, a scratch data folder with its own task)

  • service install: the task has the sign-in trigger and the 1-minute trigger, the daemon runs, and signin is written.
  • service stop: only the sign-in trigger is left, the daemon stops, and it stayed stopped for 80 s.
  • Turning Start with Windows off through RPC: the task keeps only the 1-minute trigger, and config.toml keeps its comment and port. A UTF-8 file with a BOM was also read correctly.
  • Simulated new sign-in (a stale signin file, then the daemon was killed): the 1-minute trigger started it, the daemon logged that it is waiting to be opened, and it left the task with no triggers.
  • Crash within the same sign-in: the 1-minute trigger brought the daemon back.
  • Turning Start with Windows back on added the sign-in trigger back; service stop then left only the sign-in trigger.

Manual steps still open

  • A real sign-out and sign-in with Start with Windows off. Expected: the bots do not start until Botloft is opened.
  • Closing the WebView2 window with Keep working off. Expected: the window disappears at once and the daemon stops.

…nd keeps the computer awake

settings.get and settings.update read and change start_with_windows and
keep_awake in config.toml, written in place with toml_edit so the
owner's own lines and comments stay. keep_awake applies at once.

The scheduled task's triggers follow the owner's choices: while running,
the minute trigger plus the logon trigger when Botloft starts with
Windows; after `service stop` (the app closing with the bots), only the
logon trigger when it starts with Windows. The minute trigger also fires
after a new sign-in, so a daemon started by the task (`--scheduled`)
compares the sign-in with <home>\signin and, when Botloft does not start
with Windows, takes the triggers off and exits until the app opens it.

Spec 6, 11.2, 14, 15.1 and 15.2 describe it.
…ows and checking for updates

Settings gets "In the background" with three switches: keep working
after closing Botloft (the app's choice; off, closing hides the window,
stops the bots and closes), start with Windows and keep the computer
awake (the daemon's). About gets "Check for updates". Reopening after the
bots were stopped says "Starting your bots…", and the welcome line
follows the choices. The routine switch becomes the shared Switch.
@httpsphl
httpsphl merged commit 3c23957 into main Sep 29, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant