From 8224a76e49d35b09dc705ff74822d8e109b67d5b Mon Sep 17 00:00:00 2001 From: Steven Vandevelde Date: Sun, 25 Dec 2022 23:49:58 +0100 Subject: [PATCH] Tauri dev server issues --- src-tauri/Cargo.lock | 10 +++--- src-tauri/Cargo.toml | 8 ++--- src-tauri/src/main.rs | 76 +++++++++++++++++++++++++++++---------- src-tauri/tauri.conf.json | 9 +++++ 4 files changed, 76 insertions(+), 27 deletions(-) diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index 5e8e4151..739fe817 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -206,9 +206,9 @@ dependencies = [ [[package]] name = "cargo_toml" -version = "0.13.0" +version = "0.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa0e3586af56b3bfa51fca452bd56e8dbbbd5d8d81cbf0b7e4e35b695b537eb8" +checksum = "497049e9477329f8f6a559972ee42e117487d01d1e8c2cc9f836ea6fa23a9e1a" dependencies = [ "serde", "toml", @@ -500,7 +500,7 @@ dependencies = [ [[package]] name = "diffuse" -version = "3.2.0" +version = "3.3.0" dependencies = [ "serde", "serde_json", @@ -2625,9 +2625,9 @@ dependencies = [ [[package]] name = "tauri-plugin-localhost" version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f20786ccff879045f6bafec445fb5c6740c0c057372d2f992ae1281e4658c681" +source = "git+https://github.com/tauri-apps/tauri-plugin-localhost.git?rev=a759df6a42d1a3986c9551a7130dd7f81a47d248#a759df6a42d1a3986c9551a7130dd7f81a47d248" dependencies = [ + "http", "serde_json", "tauri", "tiny_http", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 6ff81eae..7a7f2ab0 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "diffuse" -version = "3.2.0" +version = "3.3.0" description = "A music player that connects to your cloud/distributed storage" -authors = ["you"] +authors = ["Steven Vandevelde"] license = "" repository = "" default-run = "diffuse" @@ -17,8 +17,8 @@ tauri-build = { version = "^1.2.1", features = [] } [dependencies] serde_json = "^1.0" serde = { version = "^1.0", features = ["derive"] } -tauri = { version = "^1.2.3", features = ["dialog-all", "fs-all", "http-all", "path-all", "shell-open", "shell-open-api", "window-all"] } -tauri-plugin-localhost = { version = "^0.1.0" } +tauri = { version = "^1.2.3", features = ["clipboard-all", "dialog-all", "fs-all", "global-shortcut-all", "http-all", "path-all", "protocol-all", "shell-open", "shell-open-api", "window-all"] } +tauri-plugin-localhost = { git = "https://github.com/tauri-apps/tauri-plugin-localhost.git", rev = "a759df6a42d1a3986c9551a7130dd7f81a47d248" } tauri-plugin-window-state = { version = "^0.1.0" } [features] diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 66983a4c..76958287 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -4,9 +4,14 @@ )] use std::path::PathBuf; -use tauri::TitleBarStyle; -use tauri::{utils::config::AppUrl, WindowBuilder, WindowUrl}; +use tauri::{TitleBarStyle, WindowBuilder, WindowUrl}; +use tauri::utils::config::AppUrl; + +// 🚀 PRODUCTION + + +#[cfg(not(dev))] fn main() { let port = 44999; let mut context = tauri::generate_context!("tauri.conf.json"); @@ -21,24 +26,59 @@ fn main() { .plugin(tauri_plugin_localhost::Builder::new(port).build()) .plugin(tauri_plugin_window_state::Builder::default().build()) .setup(move |app| { - WindowBuilder::new( - app, - "main", - WindowUrl::App(PathBuf::from("index.html")) - ) - .title("Diffuse") - .title_bar_style(TitleBarStyle::Overlay) - .hidden_title(true) - .maximized(true) - .resizable(true) - .theme(None) - .enable_clipboard_access() - .user_agent("Chrome") - .build()?; - - // Fin + build_window(app.handle()); + Ok(()) + }) + .run(context) + .expect("Error while running tauri application"); +} + + + +// 💣 DEVELOPMENT + + +#[cfg(dev)] +fn main() { + let mut context = tauri::generate_context!("tauri.conf.json"); + + // Need to run Diffuse's dev server command on port 8000 + // instead of Tauri's dev server which doesn't to work very well. + let url = format!("http://localhost:{}", 8000).parse().unwrap(); + let window_url = WindowUrl::External(url); + + context.config_mut().build.dist_dir = AppUrl::Url(window_url.clone()); + context.config_mut().build.dev_path = AppUrl::Url(window_url.clone()); + + tauri::Builder::default() + .plugin(tauri_plugin_window_state::Builder::default().build()) + .setup(move |app| { + build_window(app.handle()); Ok(()) }) .run(context) .expect("Error while running tauri application"); +} + + + +// WINDOWS + + +fn build_window(app: tauri::AppHandle) { + WindowBuilder::new( + &app, + "main", + WindowUrl::App(PathBuf::from("index.html")) + ) + .title("Diffuse") + .title_bar_style(TitleBarStyle::Overlay) + .hidden_title(true) + .maximized(true) + .resizable(true) + .theme(None) + .enable_clipboard_access() + .user_agent("Chrome") + .build() + .unwrap(); } \ No newline at end of file diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 5becfe73..2c1ceac0 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -43,12 +43,18 @@ "active": false }, "allowlist": { + "clipboard": { + "all": true + }, "dialog": { "all": true }, "fs": { "all": true }, + "globalShortcut": { + "all": true + }, "http": { "all": true, "request": true @@ -56,6 +62,9 @@ "path": { "all": true }, + "protocol": { + "all": true + }, "shell": { "open": ".*" }, -- knotmirror 0.0.1