Skip to content

Commit

Permalink
added single instance
Browse files Browse the repository at this point in the history
  • Loading branch information
0PandaDEV committed May 10, 2024
1 parent 3de9537 commit f9b4cd6
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
46 changes: 46 additions & 0 deletions src-tauri/Cargo.lock

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

1 change: 1 addition & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ tauri-plugin-dialog = "2.0.0-beta"
tauri-plugin-updater = "2.0.0-beta"
tauri-plugin-global-shortcut = "2.0.0-beta"
tauri-plugin-window-state = "2.0.0-beta"
tauri-plugin-single-instance = "2.0.0-beta"
serde_json = "1.0"
lazy_static = "1.4"
tokio = { version = "1", features = ["full"] }
Expand Down
14 changes: 13 additions & 1 deletion src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ use reqwest::Client;
use rusty_ytdl::Video;
use std::path::PathBuf;
use tauri::async_runtime;
use tauri::AppHandle;
use tauri::Error as TauriError;
use tauri_plugin_dialog::DialogExt;
use tauri_plugin_dialog::MessageDialogKind;
use tauri_plugin_updater::UpdaterExt;
use tokio::time::Instant;
use tauri::{AppHandle, Manager};

#[tauri::command]
pub async fn download(url: String, name: String) -> Result<(), TauriError> {
Expand Down Expand Up @@ -122,3 +122,15 @@ pub async fn check_for_updates(app: AppHandle) {
}
}
}


pub fn show_window(app: &AppHandle) {
let windows = app.webview_windows();

windows
.values()
.next()
.expect("Sorry, no window found")
.set_focus()
.expect("Can't Bring Window to Focus");
}
3 changes: 3 additions & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ fn main() {
.plugin(tauri_plugin_dialog::init())
.plugin(tauri_plugin_updater::Builder::new().build())
.plugin(tauri_plugin_window_state::Builder::new().build())
.plugin(tauri_plugin_single_instance::init(|app, _args, _cwd| {
let _ = commands::show_window(app);
}))
.invoke_handler(tauri::generate_handler![
discord_rpc::update_activity,
discord_rpc::clear_activity,
Expand Down

0 comments on commit f9b4cd6

Please sign in to comment.