feat #14740: settings, keyring, tray and manual recording
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
+78
-13
@@ -1,16 +1,81 @@
|
||||
mod commands;
|
||||
mod state;
|
||||
mod tray;
|
||||
|
||||
use recorder_core::secrets::KeyringSecrets;
|
||||
use recorder_core::store::Store;
|
||||
use tauri::{Manager, WindowEvent};
|
||||
use tauri_plugin_autostart::MacosLauncher;
|
||||
|
||||
use crate::state::AppState;
|
||||
|
||||
/// Command-line flag the login item starts the app with; the main window
|
||||
/// then stays hidden in the tray.
|
||||
const AUTOSTART_ARG: &str = "--autostart";
|
||||
|
||||
#[cfg_attr(mobile, tauri::mobile_entry_point)]
|
||||
pub fn run() {
|
||||
tauri::Builder::default()
|
||||
.setup(|app| {
|
||||
if cfg!(debug_assertions) {
|
||||
app.handle().plugin(
|
||||
tauri_plugin_log::Builder::default()
|
||||
.level(log::LevelFilter::Info)
|
||||
.build(),
|
||||
)?;
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while building tauri application");
|
||||
tauri::Builder::default()
|
||||
// Must be registered first: a second launch only focuses the first.
|
||||
.plugin(tauri_plugin_single_instance::init(|app, _argv, _cwd| {
|
||||
commands::show_main(app);
|
||||
}))
|
||||
.plugin(tauri_plugin_autostart::init(
|
||||
MacosLauncher::LaunchAgent,
|
||||
Some(vec![AUTOSTART_ARG]),
|
||||
))
|
||||
.setup(|app| {
|
||||
if cfg!(debug_assertions) {
|
||||
app.handle().plugin(
|
||||
tauri_plugin_log::Builder::default()
|
||||
.level(log::LevelFilter::Info)
|
||||
.build(),
|
||||
)?;
|
||||
}
|
||||
|
||||
let data_dir = app.path().app_data_dir()?;
|
||||
let config_dir = app.path().app_config_dir()?;
|
||||
std::fs::create_dir_all(&data_dir)?;
|
||||
let store = Store::open(&data_dir.join("calls.sqlite"))?;
|
||||
let recovery = store.startup_recovery()?;
|
||||
log::info!("startup recovery: {recovery:?}");
|
||||
|
||||
let state = AppState::new(
|
||||
store,
|
||||
Box::new(KeyringSecrets),
|
||||
config_dir.join("settings.json"),
|
||||
data_dir.join("recordings"),
|
||||
);
|
||||
let autostart = state.settings().autostart;
|
||||
app.manage(state);
|
||||
commands::apply_autostart(app.handle(), autostart);
|
||||
|
||||
tray::create(app.handle())?;
|
||||
if !std::env::args().any(|arg| arg == AUTOSTART_ARG) {
|
||||
commands::show_main(app.handle());
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
.on_window_event(|window, event| {
|
||||
// Closing a window only hides it; the app keeps running in the
|
||||
// tray (for call detection) until "Beenden".
|
||||
if let WindowEvent::CloseRequested { api, .. } = event {
|
||||
api.prevent_close();
|
||||
let _ = window.hide();
|
||||
}
|
||||
})
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
commands::get_settings,
|
||||
commands::save_settings,
|
||||
commands::set_api_key,
|
||||
commands::has_api_key,
|
||||
commands::list_devices,
|
||||
commands::test_devices,
|
||||
commands::get_recording_state,
|
||||
commands::start_manual_recording,
|
||||
commands::stop_recording,
|
||||
commands::discard_current_recording,
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while building tauri application");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user