This repository has been archived by the owner on Jan 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
117 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,51 @@ | ||
const { app, Menu, ipcMain } = require("electron"); | ||
const { app, Menu, ipcMain } = require('electron') | ||
|
||
let mainWindow = null; | ||
let mainWindow = null | ||
|
||
const gotTheLock = app.requestSingleInstanceLock(); | ||
const gotTheLock = app.requestSingleInstanceLock() | ||
|
||
if (!gotTheLock) { | ||
app.quit(); | ||
app.quit() | ||
} else { | ||
app.on("second-instance", (event, commandLine, workingDirectory) => { | ||
app.on('second-instance', (event, commandLine, workingDirectory) => { | ||
if (mainWindow) { | ||
if (process.platform === "win32") { | ||
mainWindow.minimize(); | ||
mainWindow.restore(); | ||
if (process.platform === 'win32') { | ||
mainWindow.minimize() | ||
mainWindow.restore() | ||
} | ||
mainWindow.show(); | ||
mainWindow.focus(); | ||
mainWindow.show() | ||
mainWindow.focus() | ||
} | ||
}); | ||
}) | ||
|
||
app.on("ready", () => { | ||
mainWindow = require("./app-window")(app); | ||
require("./app-tray")(app, mainWindow); | ||
ipcMain.on("bringToFront", () => { | ||
if (process.platform === "win32") { | ||
mainWindow.minimize(); | ||
mainWindow.restore(); | ||
app.on('ready', () => { | ||
mainWindow = require('./app-window')(app) | ||
require('./app-tray')(app, mainWindow) | ||
ipcMain.on('bringToFront', () => { | ||
if (process.platform === 'win32') { | ||
mainWindow.minimize() | ||
mainWindow.restore() | ||
} | ||
mainWindow.show(); | ||
mainWindow.focus(); | ||
}); | ||
const template = require("./app-menu")(app, mainWindow); | ||
const menu = Menu.buildFromTemplate(template); | ||
mainWindow.show() | ||
mainWindow.focus() | ||
}) | ||
const template = require('./app-menu')(app, mainWindow) | ||
const menu = Menu.buildFromTemplate(template) | ||
switch (process.platform) { | ||
case "darwin": | ||
Menu.setApplicationMenu(menu); | ||
break; | ||
case "win32": | ||
mainWindow.setMenu(menu); | ||
break; | ||
case "linux": | ||
Menu.setApplicationMenu(menu); | ||
mainWindow.setMenu(menu); | ||
break; | ||
case 'darwin': | ||
Menu.setApplicationMenu(menu) | ||
break | ||
case 'win32': | ||
mainWindow.setMenu(menu) | ||
break | ||
case 'linux': | ||
Menu.setApplicationMenu(menu) | ||
mainWindow.setMenu(menu) | ||
break | ||
} | ||
}); | ||
}) | ||
|
||
app.on("before-quit", () => { | ||
mainWindow.shouldQuit(); | ||
}); | ||
app.on('before-quit', () => { | ||
mainWindow.shouldQuit() | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,73 @@ | ||
process.env.NODE_ENV = "dev"; | ||
const webpack = require("webpack"); | ||
const WebpackDevServer = require("webpack-dev-server"); | ||
const config = require("./webpack.config"); | ||
const signale = require("signale"); | ||
const { spawn } = require("child_process"); | ||
const electron = require("electron"); | ||
const port = 8000; | ||
let server = null; | ||
process.env.NODE_ENV = 'dev' | ||
const webpack = require('webpack') | ||
const WebpackDevServer = require('webpack-dev-server') | ||
const config = require('./webpack.config') | ||
const signale = require('signale') | ||
const { spawn } = require('child_process') | ||
const electron = require('electron') | ||
const port = 8000 | ||
let server = null | ||
|
||
const options = { | ||
publicPath: config.output.publicPath, | ||
hot: true, | ||
inline: true, | ||
quiet: true, | ||
sockHost: "localhost", | ||
sockHost: 'localhost', | ||
sockPort: port | ||
}; | ||
} | ||
|
||
function startServer() { | ||
config.plugins.push(new webpack.HotModuleReplacementPlugin()); | ||
config.entry.main.unshift("webpack/hot/dev-server"); | ||
const compiler = webpack(config); | ||
server = new WebpackDevServer(compiler, options); | ||
function startServer () { | ||
config.plugins.push(new webpack.HotModuleReplacementPlugin()) | ||
config.entry.main.unshift('webpack/hot/dev-server') | ||
const compiler = webpack(config) | ||
server = new WebpackDevServer(compiler, options) | ||
|
||
return new Promise((resolve, reject) => { | ||
server.listen(port, "localhost", function(err) { | ||
server.listen(port, 'localhost', function (err) { | ||
if (err) { | ||
reject(err); | ||
reject(err) | ||
} | ||
signale.success(`Webpack Dev Server listening at localhost:${port}`); | ||
signale.watch(`Waiting for webpack to bundle...`); | ||
compiler.hooks.done.tap("done", stats => { | ||
signale.success(`Webpack Dev Server listening at localhost:${port}`) | ||
signale.watch(`Waiting for webpack to bundle...`) | ||
compiler.hooks.done.tap('done', stats => { | ||
if (!stats.hasErrors()) { | ||
signale.success(`Bundle success !`); | ||
resolve(); | ||
signale.success(`Bundle success !`) | ||
resolve() | ||
} else { | ||
reject(stats.compilation.errors[0]); | ||
reject(stats.compilation.errors[0]) | ||
} | ||
}); | ||
}); | ||
}); | ||
}) | ||
}) | ||
}) | ||
} | ||
|
||
function startElectron() { | ||
spawn(electron, ["--hot", "./index.js"], { | ||
stdio: "inherit", | ||
function startElectron () { | ||
spawn(electron, ['--hot', './index.js'], { | ||
stdio: 'inherit', | ||
windowsHide: false | ||
}) | ||
.on("close", () => { | ||
server.close(); | ||
.on('close', () => { | ||
server.close() | ||
}) | ||
.on("error", err => { | ||
signale.error(err); | ||
server.close(); | ||
.on('error', err => { | ||
signale.error(err) | ||
server.close() | ||
}) | ||
.on("disconnect", () => { | ||
server.close(); | ||
.on('disconnect', () => { | ||
server.close() | ||
}) | ||
.on('exit', () => { | ||
server.close() | ||
}) | ||
.on("exit", () => { | ||
server.close(); | ||
}); | ||
} | ||
|
||
startServer() | ||
.then(() => { | ||
startElectron(); | ||
signale.success("Electron started"); | ||
startElectron() | ||
signale.success('Electron started') | ||
}) | ||
.catch(err => { | ||
signale.error(err); | ||
process.exit(1); | ||
}); | ||
signale.error(err) | ||
process.exit(1) | ||
}) |