Skip to content

Commit b03edd8

Browse files
committed
add start-at-login toggle
1 parent 5d151ef commit b03edd8

3 files changed

Lines changed: 35 additions & 1 deletion

File tree

index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ <h1>qol</h1>
3737
<input name="hotkey" type="text" placeholder="Super+Space" />
3838
</label>
3939

40+
<label class="row">
41+
<input name="autostart" type="checkbox" id="autostart" />
42+
Start qol at login
43+
</label>
44+
4045
<fieldset>
4146
<legend>LLM polish (OpenAI-compatible)</legend>
4247
<label class="row">

src-tauri/src/main.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use std::sync::{Arc, OnceLock};
1919
use tauri::menu::{Menu, MenuItem, PredefinedMenuItem};
2020
use tauri::tray::TrayIconBuilder;
2121
use tauri::{AppHandle, Manager, RunEvent};
22+
use tauri_plugin_autostart::ManagerExt;
2223
use tauri_plugin_global_shortcut::{Code, Modifiers, Shortcut, ShortcutState};
2324

2425
use crate::config::Config;
@@ -214,7 +215,9 @@ fn main() {
214215
save_config,
215216
test_aavaaz,
216217
set_polish_api_key,
217-
has_polish_api_key
218+
has_polish_api_key,
219+
get_autostart,
220+
set_autostart
218221
])
219222
.setup(|app| {
220223
{
@@ -325,6 +328,18 @@ fn has_polish_api_key(base_url: String) -> bool {
325328
polish::keyring_get(&base_url).is_some()
326329
}
327330

331+
/// Whether qol is registered to launch at login. OS state, not config.json.
332+
#[tauri::command]
333+
fn get_autostart(app: AppHandle) -> bool {
334+
app.autolaunch().is_enabled().unwrap_or(false)
335+
}
336+
337+
#[tauri::command]
338+
fn set_autostart(app: AppHandle, enabled: bool) -> Result<(), String> {
339+
let mgr = app.autolaunch();
340+
if enabled { mgr.enable() } else { mgr.disable() }.map_err(|e| e.to_string())
341+
}
342+
328343
#[cfg(test)]
329344
mod tests {
330345
// Both tray states must decode at runtime; set_recording_indicator relies

src/main.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const toneRows = document.getElementById("tone_rows") as HTMLDivElement;
3232
const addToneBtn = document.getElementById("add_tone") as HTMLButtonElement;
3333
const saveKeyBtn = document.getElementById("save_key") as HTMLButtonElement;
3434
const keyStatus = document.getElementById("key_status") as HTMLSpanElement;
35+
const autostart = document.getElementById("autostart") as HTMLInputElement;
3536
const apiKeyInput = () => form.elements.namedItem("polish_api_key") as HTMLInputElement;
3637
const baseUrlInput = () => form.elements.namedItem("polish_base_url") as HTMLInputElement;
3738

@@ -126,6 +127,18 @@ form.addEventListener("input", (e) => {
126127
}
127128
});
128129

130+
// Autostart is OS state (login item), not part of config.json, so apply it
131+
// immediately and revert the checkbox if the OS call fails.
132+
autostart.addEventListener("change", async () => {
133+
try {
134+
await invoke("set_autostart", { enabled: autostart.checked });
135+
setStatus(autostart.checked ? "Autostart enabled." : "Autostart disabled.");
136+
} catch (err) {
137+
autostart.checked = !autostart.checked;
138+
setStatus(`Autostart change failed: ${err}`, false);
139+
}
140+
});
141+
129142
function fill(cfg: Config) {
130143
(form.elements.namedItem("aavaaz_url") as HTMLInputElement).value = cfg.aavaaz_url;
131144
(form.elements.namedItem("model") as HTMLSelectElement).value = cfg.model;
@@ -174,6 +187,7 @@ let current: Config;
174187
current = await invoke<Config>("get_config");
175188
fill(current);
176189
await refreshKeyStatus();
190+
autostart.checked = await invoke<boolean>("get_autostart");
177191
})();
178192

179193
form.addEventListener("submit", async (e) => {

0 commit comments

Comments
 (0)