diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 3088f78..99f9f18 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -2,7 +2,7 @@ //! registry; the frontend can never ask the backend to touch an arbitrary path (scan is read-only). use std::collections::HashSet; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use std::sync::{Arc, Mutex}; mod browse_preferences; @@ -1062,9 +1062,12 @@ async fn install_new( dest: String, package: Option, game_data: Option, -) -> std::result::Result { +) -> std::result::Result { if platform::flavor() == Flavor::Docker { - return docker_install::install(app, state, dest, package, game_data).await; + // The plugin host is Windows-only for now: a Linux server keeps the classic core. + return docker_install::install(app, state, dest, package, game_data) + .await + .map(|summary| InstalledServer { summary, preview_core_error: None, modules_off: Vec::new() }); } let cancel = Cancel::default(); *state @@ -1073,9 +1076,12 @@ async fn install_new( .map_err(|_| Error::Invalid("state poisoned".into()))? = Some(cancel.clone()); let registry = Registry::at(data_dir().join("installs.json")); let dest_path = PathBuf::from(dest); + // A package the owner picked by hand is installed as it is; otherwise the new server goes straight on to the + // preview core, so it starts out with modules as plugins instead of the classic core with them built in. + let to_preview = package.as_deref().map_or(true, |p| p.trim().is_empty()); let result = tauri::async_runtime::spawn_blocking(move || { let source = installation_source(package)?; - install::install_base( + let done = install::install_base( &install::Params { source, dest: dest_path, @@ -1086,14 +1092,89 @@ async fn install_new( &|step| { let _ = app.emit("install-progress", step); }, - ) + )?; + let (preview_core_error, modules_off) = match to_preview { + false => (None, Vec::new()), + true => match install_preview_core(&app, &PathBuf::from(&done.path)) { + Ok(off) => (None, off), + Err(e) => (Some(e), Vec::new()), + }, + }; + Ok::<_, Error>((done, preview_core_error, modules_off)) }) .await; if let Ok(mut c) = state.install_cancel.lock() { *c = None; } - let done = result.map_err(|e| Error::Invalid(e.to_string()))??; - Ok(summary(done.id, PathBuf::from(done.path))) + let (done, preview_core_error, modules_off) = result.map_err(|e| Error::Invalid(e.to_string()))??; + Ok(InstalledServer { + summary: summary(done.id, PathBuf::from(done.path)), + preview_core_error, + modules_off, + }) +} + +#[derive(Serialize)] +struct InstalledServer { + #[serde(flatten)] + summary: ServerSummary, + /// Set when the server is installed but stayed on the classic core: why the preview core did not go on. + preview_core_error: Option, + /// Modules that did not build for the preview core and were switched off, with the reason. + modules_off: Vec, +} + +/// Put the preview core on a server that was just installed from the stable image: the same signed update every +/// existing server takes, including building the recommended modules as plugins. A failure leaves the classic core +/// (the update rolls itself back) and is returned as text for the install screen; on success it returns the +/// modules that did not build and were switched off (the core goes on regardless). +fn install_preview_core(app: &AppHandle, root: &Path) -> std::result::Result, String> { + let run = || -> Result { + let (dir, meta) = install_meta(root)?; + let src = coa_core::update_route::select( + &meta, + update_source(None)?, + coa_core::signing::EMBEDDED_PUBLIC_KEY, + )? + .source; + let env = update::RepackEnv { + root, + meta_dir: &dir, + }; + update::apply( + &update::Params { + root, + meta_dir: &dir, + source: src, + trusted_key: coa_core::signing::EMBEDDED_PUBLIC_KEY, + cancel: Cancel::default(), + resolutions: BTreeMap::new(), + env: &env, + fail_after_ops: None, + }, + &|step, percent| { + let _ = app.emit( + "install-progress", + serde_json::json!({ "step": "Installing the modular core", "percent": percent, "detail": step }), + ); + }, + ) + }; + let outcome = run().map_err(|e| e.to_string())?; + if outcome.txn.state != update::State::Committed { + return Err(format!( + "the preview core update stopped in state {:?}; open Updates to finish or roll it back", + outcome.txn.state + )); + } + Ok(outcome + .modules + .iter() + .filter_map(|m| match m { + coa_core::rebuild::ModuleRebuild::Disabled { id, reason, .. } => Some(format!("{id}: {reason}")), + _ => None, + }) + .collect()) } #[tauri::command] diff --git a/src/i18n/locales/en.ts b/src/i18n/locales/en.ts index a6a4ff2..349fa80 100644 --- a/src/i18n/locales/en.ts +++ b/src/i18n/locales/en.ts @@ -267,6 +267,12 @@ const en = { "install.step.unpacking": "Unpacking", "install.step.database": "Preparing database", "install.step.finishing": "Finishing", + "install.step.modularCore": "Installing the modular core and building modules", + "install.modularCoreHint": "This step compiles the modules on this computer and can take several minutes.", + "install.classicCoreTitle": "The server stays on the classic core", + "install.classicCoreText": "The server is installed and works, but the modular core did not go on, so its modules are built into the core. You can try again from Updates.", + "install.modulesOffTitle": "Some modules were switched off", + "install.modulesOffText": "The modular core is installed, but these modules did not build on this computer. The server works without them; they are tried again on the next update.", "install.doneTitle": "Your server is ready", "install.doneText": "Everything is installed. Start it from the next screen.", "install.open": "OPEN MY SERVER", diff --git a/src/i18n/locales/ru.ts b/src/i18n/locales/ru.ts index 5bc0e36..9db3e4c 100644 --- a/src/i18n/locales/ru.ts +++ b/src/i18n/locales/ru.ts @@ -251,6 +251,12 @@ const ru: Partial> = { "install.step.unpacking": "Распаковка", "install.step.database": "Подготовка базы данных", "install.step.finishing": "Завершение", + "install.step.modularCore": "Установка модульного ядра и сборка модулей", + "install.modularCoreHint": "На этом шаге модули компилируются на вашем компьютере, это может занять несколько минут.", + "install.classicCoreTitle": "Сервер остался на классическом ядре", + "install.classicCoreText": "Сервер установлен и работает, но модульное ядро не встало, поэтому модули встроены в ядро. Можно повторить из раздела «Обновления».", + "install.modulesOffTitle": "Часть модулей выключена", + "install.modulesOffText": "Модульное ядро установлено, но эти модули не собрались на этом компьютере. Сервер работает без них; при следующем обновлении сборка повторится.", "install.doneTitle": "Ваш сервер готов", "install.doneText": "Всё установлено. Запустите сервер на следующем экране.", "install.open": "ОТКРЫТЬ МОЙ СЕРВЕР", diff --git a/src/lib/api.ts b/src/lib/api.ts index 4dc4a11..dda39e0 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -798,7 +798,7 @@ export const api = { accountSetAccess: (id: string, name: string, level: number) => invoke("account_set_access", { id, name, level }), accountRename: (id: string, name: string, newName: string, password: string) => invoke("account_rename", { id, name, newName, password }), accountDelete: (id: string, name: string) => invoke("account_delete", { id, name }), - installNew: (dest: string, pkg?: string, gameData?: string) => invoke("install_new", { dest, package: pkg ?? null, gameData: gameData ?? null }), + installNew: (dest: string, pkg?: string, gameData?: string) => invoke("install_new", { dest, package: pkg ?? null, gameData: gameData ?? null }), cancelInstall: () => invoke("cancel_install"), createAccount: (id: string, username: string, password: string, administrator: boolean) => invoke("create_account", { id, username, password, administrator }), diff --git a/src/screens/InstallServer.tsx b/src/screens/InstallServer.tsx index 230c5c4..c9606aa 100644 --- a/src/screens/InstallServer.tsx +++ b/src/screens/InstallServer.tsx @@ -16,6 +16,7 @@ const STEP_KEYS: Record = { Unpacking: "install.step.unpacking", "Preparing database": "install.step.database", Finishing: "install.step.finishing", + "Installing the modular core": "install.step.modularCore", }; type Phase = "choose" | "installing" | "done"; @@ -32,6 +33,8 @@ export function InstallServer(props: { canCancel: boolean; onCancel: () => void; const [showAdvanced, setShowAdvanced] = useState(false); const [pkg, setPkg] = useState(""); const [installed, setInstalled] = useState(null); + const [classicCore, setClassicCore] = useState(null); + const [modulesOff, setModulesOff] = useState([]); const [showDetails, setShowDetails] = useState(false); // What this computer installs. A repack (Windows) needs nothing more than a folder; Docker (Linux) also needs the game data // folder and a package, and Docker itself. @@ -87,8 +90,10 @@ export function InstallServer(props: { canCancel: boolean; onCancel: () => void; setPhase("installing"); setStep({ step: "Preparing your server", percent: 0, detail: null }); try { - const s = await api.installNew(dest, pkg.trim() || undefined, docker ? gameData.trim() : undefined); + const { preview_core_error, modules_off, ...s } = await api.installNew(dest, pkg.trim() || undefined, docker ? gameData.trim() : undefined); setInstalled(s); + setClassicCore(preview_core_error); + setModulesOff(modules_off); setPhase("done"); } catch (e) { setError(asUiError(e)); @@ -112,6 +117,7 @@ export function InstallServer(props: { canCancel: boolean; onCancel: () => void;
{step.detail &&

{step.detail}

} + {step.step === "Installing the modular core" &&

{t("install.modularCoreHint")}

} {step.step === "Downloading server" && (