Skip to content

Commit

Permalink
Added dialog module
Browse files Browse the repository at this point in the history
  • Loading branch information
klaudiosinani committed Dec 15, 2018
1 parent e15a14d commit abd207e
Showing 1 changed file with 104 additions and 0 deletions.
104 changes: 104 additions & 0 deletions src/dialog.js
@@ -0,0 +1,104 @@
'use strict';
const {app, clipboard, dialog, shell} = require('electron');
const os = require('os');
const {activate} = require('./win');
const {release} = require('./url');
const file = require('./file');

class Dialog {
get _systemInfo() {
return [
`Version: ${app.getVersion()}`,
`Electron: ${process.versions.electron}`,
`Chrome: ${process.versions.chrome}`,
`Node: ${process.versions.node}`,
`V8: ${process.versions.v8}`,
`OS: ${os.type()} ${os.arch()} ${os.release()}`
].join('\n');
}

_about() {
return this._create({
buttons: ['Done', 'Copy'],
detail: `Created by Klaus Sinani.\n\n${this._systemInfo}`,
message: `Tusk ${app.getVersion()} (${os.arch()})`,
title: 'About Tusk'
});
}

_create(options) {
return dialog.showMessageBox(
Object.assign({
cancelId: 1,
defaultId: 0,
icon: file.icon
}, options)
);
}

_signOut() {
return this._create({
buttons: ['Sign Out', 'Dismiss'],
detail: 'Are you sure you want to sign out?',
message: 'Sign out of Tusk',
title: 'Tusk - Sign Out Confirmation'
});
}

_restart() {
return this._create({
buttons: ['Restart', 'Dismiss'],
detail: 'Would you like to restart now?',
message: 'Restart Tusk to activate your new settings',
title: 'Tusk - Restart Required'
});
}

_update(version) {
return this._create({
buttons: ['Download', 'Dismiss'],
detail: 'Click Download to get it now',
message: `Version ${version} is now available`,
title: 'Update Tusk'
});
}

confirmAbout() {
if (this._about() === 1) {
clipboard.writeText(this._systemInfo);
}
}

confirmRestart() {
if (this._restart() === 0) {
app.quit();
app.relaunch();
}
}

confirmSignOut() {
if (this._signOut() === 0) {
activate('log-out');
}
}

updateError(content) {
return dialog.showErrorBox('Request to get update failed', content);
}

noUpdate() {
return this._create({
detail: `Tusk is running on the latest ${app.getVersion()} version`,
message: 'There are currently no updates available',
title: 'Tusk - No Update Available'
});
}

getUpdate(version) {
if (this._update(version) === 0) {
shell.openExternal(release);
}
}
}

module.exports = new Dialog();

0 comments on commit abd207e

Please sign in to comment.