mirror of
https://gitlab.com/vyla-entertainment/go.git
synced 2026-11-09 13:07:21 -05:00
feat: launch player and frontend servers in a single Node process
This commit is contained in:
@@ -132,6 +132,28 @@ process.on('uncaughtException', (e) => console.error('uncaughtException', e && e
|
||||
process.on('unhandledRejection', (e) => console.error('unhandledRejection', e && e.stack || e));
|
||||
"#;
|
||||
|
||||
const LAUNCHER_SCRIPT: &str = r#"
|
||||
const path = require('path');
|
||||
const { pathToFileURL } = require('url');
|
||||
|
||||
async function boot(file, port) {
|
||||
process.env.PORT = String(port);
|
||||
try {
|
||||
await import(pathToFileURL(file).href);
|
||||
} catch (e) {
|
||||
console.error('failed to start ' + file, e && e.stack || e);
|
||||
} finally {
|
||||
process.env.PORT = '3000';
|
||||
}
|
||||
}
|
||||
|
||||
(async () => {
|
||||
const root = process.env.VYLA_ROOT;
|
||||
await boot(path.join(root, 'player', 'server.js'), 3000);
|
||||
await boot(path.join(root, 'frontend', 'server.js'), 3001);
|
||||
})();
|
||||
"#;
|
||||
|
||||
fn android_log(msg: &str) {
|
||||
#[cfg(target_os = "android")]
|
||||
{
|
||||
@@ -261,7 +283,10 @@ fn spawn_service_manager(base_dir: &std::path::Path) {
|
||||
);
|
||||
}
|
||||
|
||||
let server_js = server_script.to_string_lossy().to_string();
|
||||
let launcher_path = base_dir.join("launcher.js");
|
||||
let _ = std::fs::write(&launcher_path, LAUNCHER_SCRIPT);
|
||||
std::env::set_var("VYLA_ROOT", base_dir.to_string_lossy().to_string());
|
||||
let server_js = launcher_path.to_string_lossy().to_string();
|
||||
let player_dir_str = player_dir.to_string_lossy().to_string();
|
||||
|
||||
let _ = std::thread::Builder::new().stack_size(16 * 1024 * 1024).spawn(move || {
|
||||
@@ -300,6 +325,7 @@ fn spawn_service_manager(base_dir: &std::path::Path) {
|
||||
});
|
||||
|
||||
let _ = wait_for_port(3000, Duration::from_secs(45));
|
||||
let _ = wait_for_port(3001, Duration::from_secs(45));
|
||||
}
|
||||
|
||||
fn apply_directory_replacements(dir: &std::path::Path, find_val: &str, replace_val: &str) {
|
||||
@@ -355,7 +381,8 @@ async fn download_and_extract_payload(app: tauri::AppHandle, window: WebviewWind
|
||||
let marker = base_dir.join(".installed");
|
||||
let frontend_index = base_dir.join("frontend").join("index.html");
|
||||
let server_script = base_dir.join("player").join("server.js");
|
||||
if marker.exists() && frontend_index.exists() && server_script.exists() {
|
||||
let frontend_server = base_dir.join("frontend").join("server.js");
|
||||
if marker.exists() && frontend_index.exists() && server_script.exists() && frontend_server.exists() {
|
||||
android_log("App already installed, launching...");
|
||||
apply_patches(&base_dir);
|
||||
spawn_service_manager(&base_dir);
|
||||
@@ -363,7 +390,6 @@ async fn download_and_extract_payload(app: tauri::AppHandle, window: WebviewWind
|
||||
return Ok(base_dir);
|
||||
}
|
||||
|
||||
// 1. Check if a valid local archive already exists on device
|
||||
let local_payload_candidates = [
|
||||
base_dir.join("update-payload.zip"),
|
||||
base_dir.join("temp-payload.zip"),
|
||||
@@ -681,7 +707,7 @@ pub fn run() {
|
||||
Ok(_) => {
|
||||
std::thread::sleep(std::time::Duration::from_millis(400));
|
||||
let _ = window.eval(&format!(
|
||||
"{}; window.location.replace('http://vyla.localhost/frontend/index.html');",
|
||||
"{}; window.location.replace('http://localhost:3001/');",
|
||||
ANDROID_VIDEO_FIX_SCRIPT
|
||||
));
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user