mirror of
https://gitlab.com/vyla-entertainment/home.git
synced 2026-11-13 05:37:21 -05:00
potentially fixed mac support
This commit is contained in:
@@ -44,6 +44,8 @@ static WINDOW_COUNTER: std::sync::atomic::AtomicUsize = std::sync::atomic::Atomi
|
||||
|
||||
static READY_URL: Mutex<Option<String>> = Mutex::new(None);
|
||||
|
||||
static APP_LOADED: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
|
||||
|
||||
fn js_log(app: &AppHandle, msg: &str) {
|
||||
debug_log(msg);
|
||||
if let Some(w) = app.get_webview_window("main") {
|
||||
@@ -94,6 +96,17 @@ fn kill_child_process(child: &mut Child) {
|
||||
.creation_flags(CREATE_NO_WINDOW)
|
||||
.output();
|
||||
}
|
||||
#[cfg(unix)]
|
||||
{
|
||||
let pgid = child.id() as i32;
|
||||
unsafe {
|
||||
libc::killpg(pgid, libc::SIGTERM);
|
||||
}
|
||||
std::thread::sleep(std::time::Duration::from_millis(400));
|
||||
unsafe {
|
||||
libc::killpg(pgid, libc::SIGKILL);
|
||||
}
|
||||
}
|
||||
let _ = child.kill();
|
||||
let _ = child.wait();
|
||||
}
|
||||
@@ -580,7 +593,7 @@ fn open_new_window(app: AppHandle, url: String) -> Result<(), String> {
|
||||
|
||||
fn handle_ready(w: &tauri::WebviewWindow, msg: &BackendMessage) {
|
||||
let url_str = match msg.data.get("url").and_then(|u| u.as_str()) {
|
||||
Some(u) => u,
|
||||
Some(u) => u.to_string(),
|
||||
None => return,
|
||||
};
|
||||
|
||||
@@ -592,19 +605,36 @@ fn handle_ready(w: &tauri::WebviewWindow, msg: &BackendMessage) {
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
use objc2::msg_send;
|
||||
use objc2::runtime::AnyObject;
|
||||
debug_log("Attempting with_webview on ready event");
|
||||
let result = w.with_webview(|webview| unsafe {
|
||||
debug_log("Inside with_webview closure");
|
||||
use objc2::runtime::{AnyObject, Sel};
|
||||
use objc2::sel;
|
||||
let _ = w.with_webview(|webview| unsafe {
|
||||
let wk_webview = webview.inner() as *mut AnyObject;
|
||||
let config: *mut AnyObject = msg_send![wk_webview, configuration];
|
||||
let _: () = msg_send![config, setUpgradeKnownHostsToHTTPS: false];
|
||||
debug_log("setUpgradeKnownHostsToHTTPS set to false");
|
||||
let selector: Sel = sel!(setUpgradeKnownHostsToHTTPS:);
|
||||
let supported: bool = msg_send![config, respondsToSelector: selector];
|
||||
if supported {
|
||||
let _: () = msg_send![config, setUpgradeKnownHostsToHTTPS: false];
|
||||
}
|
||||
});
|
||||
debug_log(&format!("with_webview result: {:?}", result));
|
||||
}
|
||||
|
||||
let _ = w.navigate(url_parsed);
|
||||
APP_LOADED.store(false, std::sync::atomic::Ordering::SeqCst);
|
||||
let _ = w.navigate(url_parsed.clone());
|
||||
|
||||
let watcher = w.clone();
|
||||
std::thread::spawn(move || {
|
||||
for attempt in 1..=8 {
|
||||
std::thread::sleep(std::time::Duration::from_secs(4));
|
||||
if APP_LOADED.load(std::sync::atomic::Ordering::SeqCst) {
|
||||
return;
|
||||
}
|
||||
debug_log(&format!("App page not loaded yet, retry {}", attempt));
|
||||
let target = serde_json::to_string(&url_str).unwrap_or_default();
|
||||
let _ = watcher.eval(&format!("window.location.replace({});", target));
|
||||
let _ = watcher.navigate(url_parsed.clone());
|
||||
}
|
||||
debug_log("App page never loaded after retries");
|
||||
});
|
||||
}
|
||||
|
||||
fn main() {
|
||||
@@ -663,6 +693,9 @@ fn main() {
|
||||
.initialization_script("window.__VYLA_WINDOW_LABEL = 'main';")
|
||||
.on_page_load(move |wv, payload| {
|
||||
if matches!(payload.event(), tauri::webview::PageLoadEvent::Finished) {
|
||||
if payload.url().host_str() == Some("127.0.0.1") {
|
||||
APP_LOADED.store(true, std::sync::atomic::Ordering::SeqCst);
|
||||
}
|
||||
if payload.url().host_str() != Some("127.0.0.1") {
|
||||
let known = READY_URL.lock().ok().and_then(|g| g.clone());
|
||||
if let Some(u) = known {
|
||||
@@ -726,6 +759,16 @@ fn main() {
|
||||
}
|
||||
};
|
||||
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
if let Ok(meta) = std::fs::metadata(&node_bin) {
|
||||
let mut perms = meta.permissions();
|
||||
perms.set_mode(0o755);
|
||||
let _ = std::fs::set_permissions(&node_bin, perms);
|
||||
}
|
||||
}
|
||||
|
||||
let vyla_files_str = clean_path(&vyla_files);
|
||||
|
||||
let mut cmd = Command::new(&node_bin);
|
||||
@@ -746,6 +789,12 @@ fn main() {
|
||||
cmd.creation_flags(CREATE_NO_WINDOW);
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use std::os::unix::process::CommandExt;
|
||||
cmd.process_group(0);
|
||||
}
|
||||
|
||||
match cmd.spawn() {
|
||||
Ok(mut child) => {
|
||||
debug_log(&format!(
|
||||
@@ -878,6 +927,16 @@ fn main() {
|
||||
}
|
||||
}
|
||||
})
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
.build(tauri::generate_context!())
|
||||
.expect("error while building tauri application")
|
||||
.run(|app, event| {
|
||||
if let tauri::RunEvent::Exit = event {
|
||||
let state: State<NodeServices> = app.state();
|
||||
if let Ok(mut lock) = state.0.lock() {
|
||||
if let Some(mut child) = lock.take() {
|
||||
kill_child_process(&mut child);
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user