Skip to content

Commit

Permalink
add tauri-local-host plugin for sw
Browse files Browse the repository at this point in the history
  • Loading branch information
kfiven committed Sep 12, 2024
1 parent db5a2db commit 7844064
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
37 changes: 37 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-build = { version = "1.5.3", features = [] }
serde_json = "1.0.109"
serde = { version = "1.0.193", features = ["derive"] }
tauri = { version = "1.7.1", features = ["api-all", "devtools", "updater"] }
tauri-plugin-localhost = "0.1.0"

[features]
# by default Tauri runs in production mode
Expand Down
13 changes: 12 additions & 1 deletion src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,24 @@
#[cfg(target_os = "macos")]
mod menu;

use tauri::{utils::config::AppUrl, WindowUrl};

fn main() {
let port = 44548;

let mut context = tauri::generate_context!();
let url = format!("http://localhost:{}", port).parse().unwrap();
let window_url = WindowUrl::External(url);
// rewrite the config so the IPC is enabled on this URL
context.config_mut().build.dist_dir = AppUrl::Url(window_url.clone());
context.config_mut().build.dev_path = AppUrl::Url(window_url.clone());
let builder = tauri::Builder::default();

#[cfg(target_os = "macos")]
let builder = builder.menu(menu::menu());

builder
.run(tauri::generate_context!())
.plugin(tauri_plugin_localhost::Builder::new(port).build())
.run(context)
.expect("error while building tauri application")
}

0 comments on commit 7844064

Please sign in to comment.