const DownloadConfig = { template: `

Downloading config...


0%
`, created: function() { this.download_install_status(); }, methods: { download_install_status: function() { var that = this; // IE workaround ajax("/api/installation-status", function(e) { app.metadata = e; that.download_config(); }); }, download_config: function() { var that = this; // IE workaround ajax("/api/config", function(e) { app.config = e; that.choose_next_state(); }, function(e) { console.error("Got error while downloading config: " + e); if (app.metadata.is_launcher) { // Just launch the target application app.exit(); } else { router.replace({name: 'showerr', params: {msg: "Got error while downloading config: " + e}}); } }); }, choose_next_state: function() { // Update the updater if needed if (app.config.new_tool) { router.push("/install/updater"); return; } if (app.metadata.preexisting_install) { app.install_location = app.metadata.install_path; // Copy over installed packages for (var x = 0; x < app.config.packages.length; x++) { app.config.packages[x].default = false; app.config.packages[x].installed = false; } for (var i = 0; i < app.metadata.database.packages.length; i++) { // Find this config package for (var x = 0; x < app.config.packages.length; x++) { if (app.config.packages[x].name === app.metadata.database.packages[i].name) { app.config.packages[x].default = true; app.config.packages[x].installed = true; } } } if (app.metadata.is_launcher) { router.replace("/install/regular"); } else { router.replace("/modify"); } } else { for (var x = 0; x < app.config.packages.length; x++) { app.config.packages[x].installed = false; } // Need to do a bit more digging to get at the // install location. ajax("/api/default-path", function(e) { if (e.path != null) { app.install_location = e.path; } }); router.replace("/packages"); } } } }; const SelectPackages = { template: `

Select which packages you want to install:

{{ package.description }}

Install Location

Back

`, data: function() { return { advanced: false } }, methods: { select_file: function() { window.external.invoke(JSON.stringify({ SelectInstallDir: { callback_name: "selectFileCallback" } })); }, install: function() { router.push("/install/regular"); }, go_back: function() { router.go(-1); } } }; const InstallPackages = { template: `

Checking for updates...

Uninstalling...

Downloading self-update...

Installing...


{{ progress }}%
`, data: function() { return { progress: 0.0, progress_message: "Please wait...", is_uninstall: false, is_updater_update: false, is_update: false, failed_with_error: false } }, created: function() { this.is_uninstall = this.$route.params.kind === "uninstall"; this.is_updater_update = this.$route.params.kind === "updater"; this.is_update = this.$route.params.kind === "update"; console.log("Installer kind: " + this.$route.params.kind); this.install(); }, methods: { install: function() { var results = {}; for (var package_index = 0; package_index < app.config.packages.length; package_index++) { var current_package = app.config.packages[package_index]; if (current_package.default != null) { results[current_package.name] = current_package.default; } } results["path"] = app.install_location; var that = this; // IE workaround var targetUrl = "/api/start-install"; if (this.is_uninstall) { targetUrl = "/api/uninstall"; } if (this.is_updater_update) { targetUrl = "/api/update-updater"; } stream_ajax(targetUrl, function(line) { if (line.hasOwnProperty("Status")) { that.progress_message = line.Status[0]; that.progress = line.Status[1] * 100; } if (line.hasOwnProperty("Error")) { if (app.metadata.is_launcher) { app.exit(); } else { that.failed_with_error = true; router.replace({name: 'showerr', params: {msg: line.Error}}); } } }, function(e) { if (that.is_updater_update) { // Continue with what we were doing if (app.metadata.is_launcher) { router.replace("/install/regular"); } else { if (app.metadata.preexisting_install) { router.replace("/modify"); } else { router.replace("/packages"); } } } else { if (app.metadata.is_launcher) { app.exit(); } else if (!that.failed_with_error) { if (that.is_uninstall) { router.replace({name: 'complete', params: {uninstall: true, update: that.is_update}}); } else { router.replace({name: 'complete', params: {uninstall: false, update: that.is_update}}); } } } }, undefined, results); } } }; const ErrorView = { template: `

An error occurred:

{{ msg }}

Back

`, data: function() { return { msg: this.$route.params.msg, remaining: window.history.length > 1 } }, methods: { go_back: function() { router.go(-1); } } }; const CompleteView = { template: `

{{ $root.$data.attrs.name }} has been updated.

You can find your installed applications in your start menu.

Thanks for installing {{ $root.$data.attrs.name }}!

You can find your installed applications in your start menu.

{{ $root.$data.attrs.name }} has been uninstalled.

Exit

`, data: function() { return { was_install: !this.$route.params.uninstall, was_update: this.$route.params.update } }, methods: { exit: function() { app.exit(); } } }; const ModifyView = { template: `

Choose an option:

Update

Modify

Uninstall

`, data: function() { return { show_uninstall: false } }, methods: { update: function() { router.push("/install/update"); }, modify_packages: function() { router.push("/packages"); }, prepare_uninstall: function() { this.show_uninstall = true; }, cancel_uninstall: function() { this.show_uninstall = false; }, uninstall: function() { router.push("/install/uninstall"); }, } }; const router = new VueRouter({ routes: [ { path: '/config', name: 'config', component: DownloadConfig }, { path: '/packages', name: 'packages', component: SelectPackages }, { path: '/install/:kind', name: 'install', component: InstallPackages }, { path: '/showerr', name: 'showerr', component: ErrorView }, { path: '/complete/:uninstall/:update', name: 'complete', component: CompleteView }, { path: '/modify', name: 'modify', component: ModifyView }, { path: '/', redirect: '/config' } ] });