Skip to content

Commit

Permalink
fix: single instance stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
SpikeHD committed Sep 3, 2024
1 parent 804d213 commit ae76f68
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 136 deletions.
108 changes: 16 additions & 92 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ serde = { version = "1", features = ["derive"] }

tauri = { version = "2.0.0-rc", features = ["macos-private-api", "devtools", "tray-icon", "image-png"] }
tauri-plugin-shell = "2.0.0-rc"
tauri-plugin-deep-link = "2.0.0-rc"
tauri-plugin-single-instance = "2.0.0-rc"
tauri-plugin-process = "2.0.0-rc"
tauri-plugin-autostart = "2.0.0-rc"
tauri-plugin-notification = { version = "2.0.0-rc", features = ["win7-notifications", "windows7-compat"] }
Expand Down
23 changes: 0 additions & 23 deletions src-tauri/src/deep_link.rs

This file was deleted.

6 changes: 0 additions & 6 deletions src-tauri/src/functionality/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use tauri_plugin_autostart::ManagerExt;
use tauri_plugin_window_state::{AppHandleExt, StateFlags};

use crate::config::get_config;
use crate::deep_link;
use crate::log;
use crate::util::window_helpers::window_zoom_level;
use crate::window::blur::apply_effect;
Expand Down Expand Up @@ -60,11 +59,6 @@ pub fn after_build(window: &tauri::WebviewWindow) {
super::hotkeys::start_keybind_watcher(window);
}

// Deep link registry
if !config.multi_instance.unwrap_or(false) {
deep_link::register_deep_link_handler(app);
}

// If we are opening on startup (which we know from the --startup arg), check to keep the window minimized
if !startup || !config.startup_minimized.unwrap_or(false) {
// Now that we are ready, and shouldn't start minimized, show the window
Expand Down
24 changes: 20 additions & 4 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ use crate::{
};

mod config;
mod deep_link;
mod functionality;
mod gpu;
mod injection;
Expand Down Expand Up @@ -125,15 +124,13 @@ fn main() {
.plugin(tauri_plugin_http::init())
.plugin(tauri_plugin_shell::init())
.plugin(tauri_plugin_notification::init())
.plugin(tauri_plugin_deep_link::init())
.plugin(tauri_plugin_window_state::Builder::new().build())
.plugin(tauri_plugin_autostart::init(
tauri_plugin_autostart::MacosLauncher::LaunchAgent,
None,
))
.plugin(tauri_plugin_process::init())
.plugin(tauri_plugin_notification::init())
.plugin(tauri_plugin_window_state::Builder::default().build())
.plugin(tauri_plugin_window_state::Builder::new().build())
.invoke_handler(tauri::generate_handler![
should_disable_plugins,
functionality::window::minimize,
Expand Down Expand Up @@ -241,6 +238,25 @@ fn main() {
// Set the user agent to one that enables all normal Discord features
set_user_agent(&win);

// Multi-instance check

Check warning on line 241 in src-tauri/src/main.rs

View workflow job for this annotation

GitHub Actions / rustfmt (windows-latest)

Diff in \\?\D:\a\Dorion\Dorion\src-tauri\src\main.rs

Check warning on line 241 in src-tauri/src/main.rs

View workflow job for this annotation

GitHub Actions / rustfmt (ubuntu-20.04)

Diff in /home/runner/work/Dorion/Dorion/src-tauri/src/main.rs

Check warning on line 241 in src-tauri/src/main.rs

View workflow job for this annotation

GitHub Actions / rustfmt (macos-latest)

Diff in /Users/runner/work/Dorion/Dorion/src-tauri/src/main.rs
if !config.multi_instance.unwrap_or(false) {
log!("Multi-instance disabled, registering single instance plugin...");

app.handle().plugin(tauri_plugin_single_instance::init(move |app, _argv, _cwd| {
let win = match app.get_webview_window("main") {
Some(win) => win,
None => {
log!("No windows open with name \"main\"(???)");
return;
},
};

win.set_focus().unwrap_or_default();
win.unminimize().unwrap_or_default();
win.show().unwrap_or_default();
})).unwrap_or_else(|_| log!("Failed to register single instance plugin"));
}

// If safemode is enabled, stop here
if safemode {
win.show().unwrap_or_default();
Expand Down
11 changes: 1 addition & 10 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,7 @@
"productName": "Dorion",
"version": "5.0.1",
"identifier": "com.dorion.dev",
"plugins": {
"deep-link": {
"mobile": [],
"desktop": {
"schemes": [
"dorion"
]
}
}
},
"plugins": {},
"app": {
"macOSPrivateApi": true,
"withGlobalTauri": true,
Expand Down

0 comments on commit ae76f68

Please sign in to comment.