mirror of
https://github.com/OpenListTeam/OpenList-Desktop.git
synced 2025-11-25 19:27:33 +08:00
fix: fix a bug make auto update not woking on windows
This commit is contained in:
@@ -398,6 +398,7 @@ pub async fn install_update_and_restart(
|
|||||||
"linux" => install_linux_update(&path).await,
|
"linux" => install_linux_update(&path).await,
|
||||||
_ => Err("Unsupported platform for auto-update".to_string()),
|
_ => Err("Unsupported platform for auto-update".to_string()),
|
||||||
};
|
};
|
||||||
|
log::info!("Update installation result: {result:?}");
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
@@ -407,8 +408,8 @@ pub async fn install_update_and_restart(
|
|||||||
log::error!("Failed to emit install completed event: {e}");
|
log::error!("Failed to emit install completed event: {e}");
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(e) = app.emit("app-restarting", ()) {
|
if let Err(e) = app.emit("quit-app", ()) {
|
||||||
log::error!("Failed to emit app restarting event: {e}");
|
log::error!("Failed to emit app quit event: {e}");
|
||||||
}
|
}
|
||||||
|
|
||||||
tokio::time::sleep(Duration::from_millis(1000)).await;
|
tokio::time::sleep(Duration::from_millis(1000)).await;
|
||||||
@@ -423,29 +424,47 @@ pub async fn install_update_and_restart(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn install_windows_update(installer_path: &PathBuf) -> Result<(), String> {
|
async fn install_windows_update(installer_path: &PathBuf) -> Result<(), String> {
|
||||||
log::info!("Installing Windows update...");
|
log::info!("Installing Windows update...");
|
||||||
|
|
||||||
let mut cmd = Command::new(installer_path);
|
let mut cmd = Command::new("powershell");
|
||||||
cmd.arg("/SILENT");
|
cmd.args(&[
|
||||||
|
"-Command",
|
||||||
#[cfg(windows)]
|
&format!(
|
||||||
{
|
"Start-Process -FilePath '{}' -Verb runAs",
|
||||||
use std::os::windows::process::CommandExt;
|
installer_path.display()
|
||||||
cmd.creation_flags(0x08000000); // CREATE_NO_WINDOW
|
),
|
||||||
}
|
]);
|
||||||
|
log::info!("Running command: {cmd:?}");
|
||||||
|
|
||||||
let _ = tokio::task::spawn_blocking(move || {
|
let _ = tokio::task::spawn_blocking(move || {
|
||||||
cmd.spawn()
|
let child = cmd
|
||||||
.map_err(|e| format!("Failed to start Windows installer: {e}"))
|
.spawn()
|
||||||
|
.map_err(|e| format!("Failed to start Windows installer: {e}"))?;
|
||||||
|
log::info!("Started installer process with PID: {}", child.id());
|
||||||
|
let output = child
|
||||||
|
.wait_with_output()
|
||||||
|
.map_err(|e| format!("Failed to wait for installer: {e}"))?;
|
||||||
|
log::info!("Installer output: {:?}", output);
|
||||||
|
if output.status.success() {
|
||||||
|
log::info!(
|
||||||
|
"Installer completed successfully. Output: {}",
|
||||||
|
String::from_utf8_lossy(&output.stdout)
|
||||||
|
);
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
log::error!(
|
||||||
|
"Installer failed. Error: {}",
|
||||||
|
String::from_utf8_lossy(&output.stderr)
|
||||||
|
);
|
||||||
|
Err(format!("Installer exited with status: {:?}", output.status))
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.map_err(|e| format!("Task error: {e}"))?;
|
.map_err(|e| format!("Task error: {e}"))?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn install_macos_update(installer_path: &PathBuf) -> Result<(), String> {
|
async fn install_macos_update(installer_path: &PathBuf) -> Result<(), String> {
|
||||||
log::info!("Installing macOS update...");
|
log::info!("Installing macOS update...");
|
||||||
|
|
||||||
@@ -453,8 +472,25 @@ async fn install_macos_update(installer_path: &PathBuf) -> Result<(), String> {
|
|||||||
cmd.arg(installer_path);
|
cmd.arg(installer_path);
|
||||||
|
|
||||||
let _ = tokio::task::spawn_blocking(move || {
|
let _ = tokio::task::spawn_blocking(move || {
|
||||||
cmd.spawn()
|
let child = cmd
|
||||||
.map_err(|e| format!("Failed to start macOS installer: {e}"))
|
.spawn()
|
||||||
|
.map_err(|e| format!("Failed to start macOS installer: {e}"))?;
|
||||||
|
let output = child
|
||||||
|
.wait_with_output()
|
||||||
|
.map_err(|e| format!("Failed to wait for installer: {e}"))?;
|
||||||
|
if output.status.success() {
|
||||||
|
log::info!(
|
||||||
|
"Installer completed successfully. Output: {}",
|
||||||
|
String::from_utf8_lossy(&output.stdout)
|
||||||
|
);
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
log::error!(
|
||||||
|
"Installer failed. Error: {}",
|
||||||
|
String::from_utf8_lossy(&output.stderr)
|
||||||
|
);
|
||||||
|
Err(format!("Installer exited with status: {:?}", output.status))
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.map_err(|e| format!("Task error: {e}"))?;
|
.map_err(|e| format!("Task error: {e}"))?;
|
||||||
@@ -489,8 +525,25 @@ async fn install_linux_update(installer_path: &PathBuf) -> Result<(), String> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let _ = tokio::task::spawn_blocking(move || {
|
let _ = tokio::task::spawn_blocking(move || {
|
||||||
cmd.spawn()
|
let child = cmd
|
||||||
.map_err(|e| format!("Failed to start Linux installer: {e}"))
|
.spawn()
|
||||||
|
.map_err(|e| format!("Failed to start Linux installer: {e}"))?;
|
||||||
|
let output = child
|
||||||
|
.wait_with_output()
|
||||||
|
.map_err(|e| format!("Failed to wait for installer: {e}"))?;
|
||||||
|
if output.status.success() {
|
||||||
|
log::info!(
|
||||||
|
"Installer completed successfully. Output: {}",
|
||||||
|
String::from_utf8_lossy(&output.stdout)
|
||||||
|
);
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
log::error!(
|
||||||
|
"Installer failed. Error: {}",
|
||||||
|
String::from_utf8_lossy(&output.stderr)
|
||||||
|
);
|
||||||
|
Err(format!("Installer exited with status: {:?}", output.status))
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
.map_err(|e| format!("Task error: {e}"))?;
|
.map_err(|e| format!("Task error: {e}"))?;
|
||||||
@@ -641,16 +694,3 @@ pub async fn perform_background_update_check(app: AppHandle) -> Result<(), Strin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
|
||||||
pub async fn restart_app(app: AppHandle) {
|
|
||||||
log::info!("Restarting application...");
|
|
||||||
|
|
||||||
if let Err(e) = app.emit("app-restarting", ()) {
|
|
||||||
log::error!("Failed to emit app-restarting event: {e}");
|
|
||||||
}
|
|
||||||
|
|
||||||
tokio::time::sleep(Duration::from_millis(500)).await;
|
|
||||||
|
|
||||||
app.restart();
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ use cmd::binary::get_binary_version;
|
|||||||
use cmd::config::{load_settings, reset_settings, save_settings, save_settings_with_update_port};
|
use cmd::config::{load_settings, reset_settings, save_settings, save_settings_with_update_port};
|
||||||
use cmd::custom_updater::{
|
use cmd::custom_updater::{
|
||||||
check_for_updates, download_update, get_current_version, install_update_and_restart,
|
check_for_updates, download_update, get_current_version, install_update_and_restart,
|
||||||
is_auto_check_enabled, restart_app, set_auto_check_enabled,
|
is_auto_check_enabled, set_auto_check_enabled,
|
||||||
};
|
};
|
||||||
use cmd::http_api::{
|
use cmd::http_api::{
|
||||||
delete_process, get_process_list, restart_process, start_process, stop_process, update_process,
|
delete_process, get_process_list, restart_process, start_process, stop_process, update_process,
|
||||||
@@ -164,8 +164,7 @@ pub fn run() {
|
|||||||
install_update_and_restart,
|
install_update_and_restart,
|
||||||
get_current_version,
|
get_current_version,
|
||||||
set_auto_check_enabled,
|
set_auto_check_enabled,
|
||||||
is_auto_check_enabled,
|
is_auto_check_enabled
|
||||||
restart_app,
|
|
||||||
])
|
])
|
||||||
.setup(|app| {
|
.setup(|app| {
|
||||||
let app_handle = app.app_handle();
|
let app_handle = app.app_handle();
|
||||||
|
|||||||
@@ -119,6 +119,6 @@ export class TauriAPI {
|
|||||||
listen('download-progress', e => cb(e.payload as DownloadProgress)),
|
listen('download-progress', e => cb(e.payload as DownloadProgress)),
|
||||||
onInstallStarted: (cb: () => void) => listen('update-install-started', () => cb()),
|
onInstallStarted: (cb: () => void) => listen('update-install-started', () => cb()),
|
||||||
onInstallError: (cb: (err: string) => void) => listen('update-install-error', e => cb(e.payload as string)),
|
onInstallError: (cb: (err: string) => void) => listen('update-install-error', e => cb(e.payload as string)),
|
||||||
onAppRestarting: (cb: () => void) => listen('app-restarting', () => cb())
|
onAppQuit: (cb: () => void) => listen('quit-app', () => cb())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -177,7 +177,7 @@ let backgroundUpdateUnlisten: (() => void) | null = null
|
|||||||
let downloadProgressUnlisten: (() => void) | null = null
|
let downloadProgressUnlisten: (() => void) | null = null
|
||||||
let installStartedUnlisten: (() => void) | null = null
|
let installStartedUnlisten: (() => void) | null = null
|
||||||
let installErrorUnlisten: (() => void) | null = null
|
let installErrorUnlisten: (() => void) | null = null
|
||||||
let appRestartingUnlisten: (() => void) | null = null
|
let appQuitEventUnsubscriber: (() => void) | null = null
|
||||||
|
|
||||||
const checkForUpdates = async () => {
|
const checkForUpdates = async () => {
|
||||||
if (checking.value || downloading.value || installing.value) return
|
if (checking.value || downloading.value || installing.value) return
|
||||||
@@ -358,13 +358,13 @@ onMounted(async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
appRestartingUnlisten = await TauriAPI.updater.onAppRestarting(() => {
|
appQuitEventUnsubscriber = await TauriAPI.updater.onAppQuit(() => {
|
||||||
installationStatus.value = t('update.restartingApp')
|
installationStatus.value = t('update.quitApp')
|
||||||
installationStatusType.value = 'success'
|
installationStatusType.value = 'success'
|
||||||
})
|
})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn('App restarting listener not available:', err)
|
console.warn('App restarting listener not available:', err)
|
||||||
appRestartingUnlisten = null
|
appQuitEventUnsubscriber = null
|
||||||
}
|
}
|
||||||
if (autoCheckEnabled.value) {
|
if (autoCheckEnabled.value) {
|
||||||
await checkForUpdates()
|
await checkForUpdates()
|
||||||
@@ -400,7 +400,7 @@ onUnmounted(() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
appRestartingUnlisten?.()
|
appQuitEventUnsubscriber?.()
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.warn('Error unregistering app restarting listener:', err)
|
console.warn('Error unregistering app restarting listener:', err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -480,7 +480,7 @@
|
|||||||
"startingDownload": "Starting download...",
|
"startingDownload": "Starting download...",
|
||||||
"downloading": "Downloading",
|
"downloading": "Downloading",
|
||||||
"installingUpdate": "Installing update...",
|
"installingUpdate": "Installing update...",
|
||||||
"restartingApp": "Restarting application...",
|
"quitApp": "Quitting application...",
|
||||||
"noUpdatesFound": "No updates available",
|
"noUpdatesFound": "No updates available",
|
||||||
"aboutUpdates": "About Updates",
|
"aboutUpdates": "About Updates",
|
||||||
"autoCheckInfo": "Automatic update checks keep your app secure and up-to-date",
|
"autoCheckInfo": "Automatic update checks keep your app secure and up-to-date",
|
||||||
|
|||||||
@@ -480,7 +480,7 @@
|
|||||||
"startingDownload": "开始下载...",
|
"startingDownload": "开始下载...",
|
||||||
"downloading": "下载中...",
|
"downloading": "下载中...",
|
||||||
"installingUpdate": "安装更新中...",
|
"installingUpdate": "安装更新中...",
|
||||||
"restartingApp": "重启应用中...",
|
"quitApp": "退出应用中...",
|
||||||
"noUpdatesFound": "没有可用更新",
|
"noUpdatesFound": "没有可用更新",
|
||||||
"aboutUpdates": "关于更新",
|
"aboutUpdates": "关于更新",
|
||||||
"autoCheckInfo": "自动更新检查让您的应用保持安全和最新状态",
|
"autoCheckInfo": "自动更新检查让您的应用保持安全和最新状态",
|
||||||
|
|||||||
Reference in New Issue
Block a user