Make launcher mode behaviour more robust

This commit is contained in:
James 2019-07-03 14:09:07 +10:00
parent 9a28807423
commit e69443c22e
5 changed files with 36 additions and 28 deletions

View file

@ -12,6 +12,7 @@ use log::Level;
enum CallbackType { enum CallbackType {
SelectInstallDir { callback_name: String }, SelectInstallDir { callback_name: String },
Log { msg: String, kind: String }, Log { msg: String, kind: String },
Test {}
} }
/// Starts the main web UI. Will return when UI is closed. /// 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, _ => Level::Error,
}; };
log!(target: "liftinstall::frontend-js", kind, "{}", msg); log!(target: "liftinstall::frontend::js", kind, "{}", msg);
} }
CallbackType::Test {} => {}
} }
cb_result cb_result
}) })
.run() .run()

View file

@ -82,8 +82,6 @@ pub struct InstallerFramework {
// If we just completed an uninstall, and we should clean up after ourselves. // If we just completed an uninstall, and we should clean up after ourselves.
pub burn_after_exit: bool, pub burn_after_exit: bool,
pub launcher_path: Option<String>, pub launcher_path: Option<String>,
attempted_shutdown: bool,
} }
/// Contains basic properties on the status of the session. Subset of InstallationFramework. /// Contains basic properties on the status of the session. Subset of InstallationFramework.
@ -400,27 +398,22 @@ impl InstallerFramework {
/// Shuts down the installer instance. /// Shuts down the installer instance.
pub fn shutdown(&mut self) -> Result<(), String> { 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..."); 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); info!("Launching {:?}", v);
Command::new(v) Command::new(v)
.stdout(Stdio::null()) .stdout(Stdio::null())
.stderr(Stdio::null()) .stderr(Stdio::null())
.spawn() .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 { if self.burn_after_exit {
info!("Requesting that self be deleted after exit."); info!("Requesting that self be deleted after exit.");
native::burn_on_exit(&self.base_attributes.name); native::burn_on_exit(&self.base_attributes.name);
self.burn_after_exit = false;
} }
Ok(()) Ok(())
@ -437,7 +430,6 @@ impl InstallerFramework {
is_launcher: false, is_launcher: false,
burn_after_exit: false, burn_after_exit: false,
launcher_path: None, launcher_path: None,
attempted_shutdown: false,
} }
} }
@ -465,7 +457,6 @@ impl InstallerFramework {
is_launcher: false, is_launcher: false,
burn_after_exit: false, burn_after_exit: false,
launcher_path: None, launcher_path: None,
attempted_shutdown: false,
}) })
} }
} }

View file

@ -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 // Overwrite loggers with the logging backend
if (window.external !== undefined && window.external.invoke !== undefined) { if (has_external_interface) {
window.onerror = function (msg, url, line) { window.onerror = function (msg, url, line) {
old_onerror(msg, url, line)
window.external.invoke( window.external.invoke(
JSON.stringify({ JSON.stringify({
Log: { Log: {
@ -89,12 +99,13 @@ var app = new Vue({
'/api/exit', '/api/exit',
function () {}, function () {},
function (msg) { function (msg) {
alert( var search_location = app.metadata.install_path.length > 0 ? app.metadata.install_path :
'LiftInstall encountered an error while exiting: ' + "the location where this installer is";
msg +
'\nPlease upload the log file (in the same directory as the installer) to ' + app.$router.replace({ name: 'showerr', params: { msg: msg +
'the respective maintainers for this application (where you got it from!)' '\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 stream_ajax: stream_ajax
} }
}).$mount('#app') }).$mount('#app')
console.log("Vue started")

View file

@ -6,7 +6,8 @@
<div class="field is-grouped is-right-floating is-bottom-floating"> <div class="field is-grouped is-right-floating is-bottom-floating">
<p class="control"> <p class="control">
<a class="button is-primary is-medium" v-if="remaining" v-on:click="go_back">Back</a> <a class="button is-primary is-medium" v-if="remaining && !is_launcher" v-on:click="go_back">Back</a>
<a class="button is-primary is-medium" v-if="is_launcher" v-on:click="exit">Exit</a>
</p> </p>
</div> </div>
</div> </div>

View file

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