const DownloadConfig = {
template: `
`,
created: function() {
this.download_install_status();
},
methods: {
download_install_status: function() {
ajax("/api/installation-status", (e) => {
app.metadata = e;
this.download_config();
});
},
download_config: function() {
ajax("/api/config", (e) => {
app.config = e;
this.choose_next_state();
}, (e) => {
console.error("Got error while downloading config: "
+ e);
if (app.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() {
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.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[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", (e) => {
if (e.path != null) {
app.install_location = e.path;
}
});
router.replace("/packages");
}
/*app.is_downloading_config = false;
if (e.preexisting_install) {
app.modify_install = true;
app.select_packages = false;
app.show_install_location = false;
app.install_location = e.install_path;
if (e.is_launcher) {
app.is_launcher = true;
app.install();
}
} else {
}*/
}
}
};
const SelectPackages = {
template: `
Select your preferred settings:
Install Location
Install!
`,
methods: {
select_file: function() {
window.external.invoke(JSON.stringify({
SelectInstallDir: {
callback_name: "selectFileCallback"
}
}));
},
install: function() {
router.push("/install/regular");
}
}
};
const InstallPackages = {
template: `
Checking for updates...
Uninstalling...
Installing...
`,
data: function() {
return {
progress: 0.0,
progress_message: "Please wait...",
is_uninstall: false,
failed_with_error: false
}
},
created: function() {
this.is_uninstall = this.$route.params.kind === "uninstall";
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;
stream_ajax(this.is_uninstall ? "/api/uninstall" :
"/api/start-install", (line) => {
if (line.hasOwnProperty("Status")) {
this.progress_message = line.Status[0];
this.progress = line.Status[1] * 100;
}
if (line.hasOwnProperty("Error")) {
if (app.metadata.is_launcher) {
app.exit();
} else {
this.failed_with_error = true;
router.replace({name: 'showerr', params: {msg: line.Error}});
}
}
}, (e) => {
if (app.metadata.is_launcher) {
app.exit();
} else if (!this.failed_with_error) {
router.push("/complete");
}
}, 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
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: '/',
redirect: '/config'
}
]
});