Skip to content

Commit

Permalink
Old mac warning (UNTESTED)
Browse files Browse the repository at this point in the history
  • Loading branch information
Marekkon5 committed Oct 31, 2022
1 parent 45272d5 commit 61de2a6
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 1 deletion.
83 changes: 83 additions & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions crates/onetagger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
49 changes: 48 additions & 1 deletion crates/onetagger/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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);
}
Expand All @@ -61,4 +65,47 @@ struct Cli {
/// Windows only installer option
#[clap(long)]
bootstrap_webview2: bool,
}

/// Open in browser
#[clap(long)]
browser: bool,
}

/// Show warning for old macOS
#[cfg(target_os = "macos")]
fn old_macos_warning() -> Result<(), Box<dyn Error>> {
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<dyn Error>> { Ok(()) }
10 changes: 10 additions & 0 deletions crates/onetagger/src/ui.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::time::Duration;
use include_dir::Dir;
use onetagger_player::AudioSources;
use rouille::{router, Response};
Expand All @@ -14,6 +15,7 @@ pub struct StartContext {
pub server_mode: bool,
pub start_path: Option<String>,
pub expose: bool,
pub browser: bool,
}

// Start webview window
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 61de2a6

Please sign in to comment.