-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.js
105 lines (101 loc) · 3.04 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
** Nuxt
*/
const { autoUpdater } = require("electron-updater");
const http = require('http')
const { Nuxt, Builder } = require('nuxt')
let config = require('./nuxt.config.js')
config.rootDir = __dirname // for electron-builder
// Init Nuxt.js
const nuxt = new Nuxt(config)
const builder = new Builder(nuxt)
const server = http.createServer(nuxt.render)
// Build only in dev mode
if (config.dev) {
builder.build().catch(err => {
console.error(err) // eslint-disable-line no-console
process.exit(1)
})
}
// Listen the server
server.listen()
const _NUXT_URL_ = `http://localhost:${server.address().port}`
console.log(`Nuxt working on ${_NUXT_URL_}`)
/*
** Electron
*/
let win = null // Current window
const electron = require('electron')
const path = require('path')
const app = electron.app
const newWin = () => {
const options = {
type: "question",
buttons: ["No, thanks", "Yes, please"],
defaultId: 1,
title: "Question",
message: "Do you want to do this?"
};
autoUpdater.on("update-available", () => {
if (process.platform === "win32" || process.platform === "win64") {
options.title = "Update";
options.message = "Update available, download it ?";
dialog.showMessageBox(null, options, (response) => {
if (response === 1) {
autoUpdater.downloadUpdate();
autoUpdater.on("update-downloaded", () => {
autoUpdater.quitAndInstall();
});
}
});
} else {
options.title = "Update";
options.message = "Update available, download it ?";
dialog.showMessageBox(null, options, (response) => {
if (response === 1) {
let child = new BrowserWindow({ modal: false, show: false });
child.loadURL("https://github.com/romslf/system-companion/releases/latest");
child.once("ready-to-show", () => {
child.show();
});
}
});
}
});
autoUpdater.on("error", (err) => {
console.log(err);
});
win = new electron.BrowserWindow({
icon: path.join(__dirname, 'static/icons/win-icon.ico'),
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
enableRemoteModule: true,
},
autoHideMenuBar: true
})
//win.maximize()
win.on('closed', () => win = null)
if (config.dev) {
// Install vue dev tool and open chrome dev tools
const { default: installExtension, VUEJS_DEVTOOLS } = require('electron-devtools-installer')
installExtension(VUEJS_DEVTOOLS.id).then(name => {
console.log(`Added Extension: ${name}`)
win.webContents.openDevTools()
}).catch(err => console.log('An error occurred: ', err))
// Wait for nuxt to build
const pollServer = () => {
http.get(_NUXT_URL_, (res) => {
if (res.statusCode === 200) { win.loadURL(_NUXT_URL_) } else { setTimeout(pollServer, 300) }
}).on('error', pollServer)
}
pollServer()
} else { return win.loadURL(_NUXT_URL_) }
//this._create();
autoUpdater.autoDownload = false;
console.log("Checking updates ...")
autoUpdater.checkForUpdates();
}
app.on('ready', newWin)
app.on('window-all-closed', () => app.quit())
app.on('activate', () => win === null && newWin())