Skip to content

Commit

Permalink
fix: fix highlighting in single-instance plugin (tauri-apps#2786)
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir authored Oct 3, 2024
1 parent 165f743 commit f4d8bbe
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions src/content/docs/plugin/single-instance.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -95,31 +95,22 @@ So, the closure should look like below

By default, when you initiate a new instance while the application is already running, no action is taken. To focus the window of the running instance when user tries to open a new instance, alter the callback closure as follows:

```rust title="src-tauri/src/lib.rs" {1} {5-7} {12-21}
```rust title="src-tauri/src/lib.rs" {1} {5-12}
use tauri::{AppHandle, Manager};

pub fn run() {
let mut builder = tauri::Builder::default();
#[cfg(desktop)]
{
builder = builder.plugin(tauri_plugin_single_instance::init(|app, args, cwd| {
let _ = show_window(app);
let _ = app.get_webview_window("main")
.expect("no main window")
.set_focus();
}));
}

builder
.run(tauri::generate_context!())
.expect("error while running tauri application");
}

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");
}
```

0 comments on commit f4d8bbe

Please sign in to comment.