diff --git a/Cargo.lock b/Cargo.lock index bae9926b..665885f7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -908,6 +908,16 @@ dependencies = [ "dirs-sys", ] +[[package]] +name = "dirs-next" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1" +dependencies = [ + "cfg-if 1.0.0", + "dirs-sys-next", +] + [[package]] name = "dirs-sys" version = "0.3.7" @@ -919,6 +929,17 @@ dependencies = [ "winapi", ] +[[package]] +name = "dirs-sys-next" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + [[package]] name = "dispatch" version = "0.2.0" @@ -2048,6 +2069,26 @@ dependencies = [ "getrandom 0.2.7", ] +[[package]] +name = "native-dialog" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ab637f328b31bd0855c43bd38a4a4455e74324d9e74e0aac6a803422f43abc6" +dependencies = [ + "block", + "cocoa", + "dirs-next", + "objc", + "objc-foundation", + "objc_id", + "once_cell", + "raw-window-handle 0.4.3", + "thiserror", + "wfd", + "which", + "winapi", +] + [[package]] name = "native-tls" version = "0.2.10" @@ -2373,6 +2414,26 @@ dependencies = [ "malloc_buf", ] +[[package]] +name = "objc-foundation" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9" +dependencies = [ + "block", + "objc", + "objc_id", +] + +[[package]] +name = "objc_id" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c92d4ddb4bd7b50d730c215ff871754d0da6b2178849f8a2a2ab69712d0c073b" +dependencies = [ + "objc", +] + [[package]] name = "object" version = "0.29.0" @@ -2433,6 +2494,7 @@ dependencies = [ "log", "mime", "mime_guess", + "native-dialog", "once_cell", "onetagger-autotag", "onetagger-platforms", @@ -4607,6 +4669,27 @@ version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9193164d4de03a926d909d3bc7c30543cecb35400c02114792c2cae20d5e2dbb" +[[package]] +name = "wfd" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e713040b67aae5bf1a0ae3e1ebba8cc29ab2b90da9aa1bff6e09031a8a41d7a8" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "which" +version = "4.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c831fbbee9e129a8cf93e7747a82da9d95ba8e16621cae60ec2cdc849bacb7b" +dependencies = [ + "either", + "libc", + "once_cell", +] + [[package]] name = "widestring" version = "0.5.1" diff --git a/crates/onetagger/Cargo.toml b/crates/onetagger/Cargo.toml index 6bc18ed3..7a06e3b5 100644 --- a/crates/onetagger/Cargo.toml +++ b/crates/onetagger/Cargo.toml @@ -50,6 +50,10 @@ winapi = { version = "0.3", features = ["winuser", "consoleapi"] } [target.'cfg(windows)'.build-dependencies] winres = "0.1" +# MacOS specific +[target.'cfg(target_os = "macos")'.dependencies] +native-dialog = "0.6.3" + [package.metadata.bundle] name = "OneTagger" diff --git a/crates/onetagger/src/main.rs b/crates/onetagger/src/main.rs index c3a3fd1d..d08bc1bb 100644 --- a/crates/onetagger/src/main.rs +++ b/crates/onetagger/src/main.rs @@ -4,6 +4,7 @@ #[macro_use] extern crate include_dir; #[macro_use] extern crate onetagger_shared; +use std::error::Error; use clap::Parser; use onetagger_shared::{VERSION, COMMIT}; @@ -33,12 +34,15 @@ fn main() { info!("\n\nStarting OneTagger v{VERSION} Commit: {COMMIT} OS: {}\n\n", std::env::consts::OS); + // MacOS + old_macos_warning().ok(); // Start let context = StartContext { start_path: cli.path, server_mode: cli.server, expose: cli.expose, + browser: cli.browser }; ui::start_all(context); } @@ -61,4 +65,47 @@ struct Cli { /// Windows only installer option #[clap(long)] bootstrap_webview2: bool, -} \ No newline at end of file + + /// Open in browser + #[clap(long)] + browser: bool, +} + +/// Show warning for old macOS +#[cfg(target_os = "macos")] +fn old_macos_warning() -> Result<(), Box> { + use std::process::Command; + use native_dialog::MessageDialog; + + // Get version + let output = Command::new("sw_vers") + .arg("-productVersion") + .output()? + .stdout; + let version = String::from_utf8(output)?; + // Show warning + if version.starts_with("10.") && !version.contains("10.15") { + let server_version = MessageDialog::new() + .set_title("Unsupported version") + .set_text("This version of MacOS is unsupported and might cause crashes, because of outdated WebKit. Would you like to run the server version and open it in the browser?") + .show_confirm()?; + + if server_version { + Command::new("osascript") + .arg("-e") + .arg(format!( + "tell application \"Terminal\" to do script \"{} --server --browser\"", + std::env::args().next().unwrap() + )) + .output() + .ok(); + std::process::exit(0); + } + } + Ok(()) + +} + +/// Show warning for old macOS +#[cfg(not(target_os = "macos"))] +fn old_macos_warning() -> Result<(), Box> { Ok(()) } \ No newline at end of file diff --git a/crates/onetagger/src/ui.rs b/crates/onetagger/src/ui.rs index 8d809574..a42a93df 100644 --- a/crates/onetagger/src/ui.rs +++ b/crates/onetagger/src/ui.rs @@ -1,3 +1,4 @@ +use std::time::Duration; use include_dir::Dir; use onetagger_player::AudioSources; use rouille::{router, Response}; @@ -14,6 +15,7 @@ pub struct StartContext { pub server_mode: bool, pub start_path: Option, pub expose: bool, + pub browser: bool, } // Start webview window @@ -116,6 +118,14 @@ pub fn start_all(context: StartContext) { false => info!("Starting server on http://127.0.0.1:36913 ws://127.0.0.1:36912") } + // Open in browser with 1s delay to allow the srever to load + if context.browser { + std::thread::spawn(move || { + std::thread::sleep(Duration::from_secs(1)); + webbrowser::open("http://127.0.0.1:36913").ok(); + }); + } + // Server mode if context.server_mode { start_webserver_thread(&context);