Skip to content

Commit 1560261

Browse files
committed
Enforce single instance of app
1 parent 499eb49 commit 1560261

3 files changed

Lines changed: 30 additions & 2 deletions

File tree

AutoSubs-App/src-tauri/Cargo.lock

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

AutoSubs-App/src-tauri/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ tauri-plugin-process = "2"
3636
tauri-plugin-shell = "2"
3737
tauri-plugin-clipboard-manager = "2"
3838
tauri-plugin-opener = "2"
39+
tauri-plugin-single-instance = "2"
3940

4041
reqwest = { version = "0.11", features = ["json", "blocking"] }
4142

AutoSubs-App/src-tauri/src/main.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use tauri_plugin_shell::ShellExt; // for app.shell()
2121
use tauri_plugin_store::Builder as StoreBuilder;
2222
use tauri_plugin_clipboard_manager::init as clipboard_plugin;
2323
use tauri_plugin_opener::init as opener_plugin;
24+
use tauri_plugin_single_instance::init as single_instance_plugin;
2425
use tokio::process::Command as TokioCommand;
2526

2627
mod audio_preprocess;
@@ -75,20 +76,30 @@ fn main() {
7576
.plugin(shell_plugin())
7677
.plugin(clipboard_plugin())
7778
.plugin(opener_plugin())
79+
.plugin(single_instance_plugin(|app, _args, _cwd| {
80+
// Focus the existing window when a second instance is launched
81+
let _ = app.get_webview_window("main").map(|w| w.set_focus());
82+
}))
7883
.setup(|app| {
7984
// Initialize backend logging (file + in-memory ring buffer)
8085
crate::logging::init_logging(&app.handle());
8186

87+
// Set window title to "AutoSubs" on Windows and Linux for taskbar display
88+
#[cfg(any(target_os = "windows", target_os = "linux"))]
89+
{
90+
if let Some(window) = app.get_webview_window("main") {
91+
let _ = window.set_title("AutoSubs");
92+
}
93+
}
94+
8295
// Hide native titlebar on Windows so the custom HTML titlebar is used exclusively
8396
#[cfg(target_os = "windows")]
8497
{
8598
if let Some(window) = app.get_webview_window("main") {
8699
let _ = window.set_decorations(false);
87-
let _ = window.set_title("AutoSubs");
88100
}
89101
}
90102

91-
92103
// Set traffic light position programmatically on macOS.
93104
// `trafficLightPosition` in tauri.conf.json is only applied at window
94105
// creation and AppKit resets the button layout on various lifecycle

0 commit comments

Comments
 (0)