From e69443c22eb4cb009dfade296478d39105b0872e Mon Sep 17 00:00:00 2001 From: James Date: Wed, 3 Jul 2019 14:09:07 +1000 Subject: [PATCH] Make launcher mode behaviour more robust --- src/frontend/ui/mod.rs | 5 ++++- src/installer.rs | 15 +++------------ ui/src/main.js | 29 +++++++++++++++++++++-------- ui/src/views/ErrorView.vue | 3 ++- ui/src/views/InstallPackages.vue | 12 ++++++------ 5 files changed, 36 insertions(+), 28 deletions(-) diff --git a/src/frontend/ui/mod.rs b/src/frontend/ui/mod.rs index d18e359..149a67b 100644 --- a/src/frontend/ui/mod.rs +++ b/src/frontend/ui/mod.rs @@ -12,6 +12,7 @@ use log::Level; enum CallbackType { SelectInstallDir { callback_name: String }, Log { msg: String, kind: String }, + Test {} } /// Starts the main web UI. Will return when UI is closed. @@ -58,9 +59,11 @@ pub fn start_ui(app_name: &str, http_address: &str, is_launcher: bool) { _ => Level::Error, }; - log!(target: "liftinstall::frontend-js", kind, "{}", msg); + log!(target: "liftinstall::frontend::js", kind, "{}", msg); } + CallbackType::Test {} => {} } + cb_result }) .run() diff --git a/src/installer.rs b/src/installer.rs index 78f208d..b64df8b 100644 --- a/src/installer.rs +++ b/src/installer.rs @@ -82,8 +82,6 @@ pub struct InstallerFramework { // If we just completed an uninstall, and we should clean up after ourselves. pub burn_after_exit: bool, pub launcher_path: Option, - - attempted_shutdown: bool, } /// Contains basic properties on the status of the session. Subset of InstallationFramework. @@ -400,27 +398,22 @@ impl InstallerFramework { /// Shuts down the installer instance. pub fn shutdown(&mut self) -> Result<(), String> { - if self.attempted_shutdown { - return Err("Cannot attempt shutdown twice!".to_string()); - } - - self.attempted_shutdown = true; - info!("Shutting down installer framework..."); - if let Some(ref v) = self.launcher_path { + if let Some(ref v) = self.launcher_path.take() { info!("Launching {:?}", v); Command::new(v) .stdout(Stdio::null()) .stderr(Stdio::null()) .spawn() - .map_err(|x| format!("Unable to start child process: {:?}", x))?; + .map_err(|x| format!("Unable to start application: {:?}", x))?; } if self.burn_after_exit { info!("Requesting that self be deleted after exit."); native::burn_on_exit(&self.base_attributes.name); + self.burn_after_exit = false; } Ok(()) @@ -437,7 +430,6 @@ impl InstallerFramework { is_launcher: false, burn_after_exit: false, launcher_path: None, - attempted_shutdown: false, } } @@ -465,7 +457,6 @@ impl InstallerFramework { is_launcher: false, burn_after_exit: false, launcher_path: None, - attempted_shutdown: false, }) } } diff --git a/ui/src/main.js b/ui/src/main.js index 49d91c1..d69b257 100644 --- a/ui/src/main.js +++ b/ui/src/main.js @@ -21,10 +21,20 @@ function intercept (method) { } } +// See if we have access to the JSON interface +var has_external_interface = false; +try { + window.external.invoke(JSON.stringify({ + Test: {} + })) + has_external_interface = true; +} catch (e) { + console.warn("Running without JSON interface - unexpected behaviour may occur!") +} + // Overwrite loggers with the logging backend -if (window.external !== undefined && window.external.invoke !== undefined) { +if (has_external_interface) { window.onerror = function (msg, url, line) { - old_onerror(msg, url, line) window.external.invoke( JSON.stringify({ Log: { @@ -89,12 +99,13 @@ var app = new Vue({ '/api/exit', function () {}, function (msg) { - alert( - 'LiftInstall encountered an error while exiting: ' + - msg + - '\nPlease upload the log file (in the same directory as the installer) to ' + - 'the respective maintainers for this application (where you got it from!)' - ) + var search_location = app.metadata.install_path.length > 0 ? app.metadata.install_path : + "the location where this installer is"; + + app.$router.replace({ name: 'showerr', params: { msg: msg + + '\n\nPlease upload the log file (in ' + search_location + ') to ' + + 'the ' + app.attrs.name + ' team' + }}); } ) }, @@ -102,3 +113,5 @@ var app = new Vue({ stream_ajax: stream_ajax } }).$mount('#app') + +console.log("Vue started") diff --git a/ui/src/views/ErrorView.vue b/ui/src/views/ErrorView.vue index acb17e3..b3e1dea 100644 --- a/ui/src/views/ErrorView.vue +++ b/ui/src/views/ErrorView.vue @@ -6,7 +6,8 @@

- Back + Back + Exit

diff --git a/ui/src/views/InstallPackages.vue b/ui/src/views/InstallPackages.vue index d00d8b5..ab936e6 100644 --- a/ui/src/views/InstallPackages.vue +++ b/ui/src/views/InstallPackages.vue @@ -60,6 +60,8 @@ export default { } this.$root.stream_ajax(targetUrl, function (line) { + // On progress line received from server + if (line.hasOwnProperty('Status')) { that.progress_message = line.Status[0] that.progress = line.Status[1] * 100 @@ -70,14 +72,12 @@ export default { } if (line.hasOwnProperty('Error')) { - if (app.metadata.is_launcher) { - app.exit() - } else { - that.failed_with_error = true - that.$router.replace({ name: 'showerr', params: { msg: line.Error } }) - } + that.failed_with_error = true + that.$router.replace({ name: 'showerr', params: { msg: line.Error } }) } }, function (e) { + // On request completed + if (that.is_updater_update) { // Continue with what we were doing if (app.metadata.is_launcher) {