feat(app): allow run only single application at same time
This commit is contained in:
parent
464da346d1
commit
ae8b35e685
@ -48,6 +48,7 @@ const resourcesPath = env.name === "production" ? process.resourcesPath : 'resou
|
|||||||
const spiderCall = require('./spider')
|
const spiderCall = require('./spider')
|
||||||
const appConfig = require('./config')
|
const appConfig = require('./config')
|
||||||
|
|
||||||
|
let mainWindow = undefined
|
||||||
let sphinx = undefined
|
let sphinx = undefined
|
||||||
let spider = undefined
|
let spider = undefined
|
||||||
|
|
||||||
@ -74,6 +75,22 @@ console.log('CPU Logic cores:', os.cpus().length)
|
|||||||
console.log('Total memory:', (os.totalmem() / (1024 * 1024)).toFixed(2), 'MB')
|
console.log('Total memory:', (os.totalmem() / (1024 * 1024)).toFixed(2), 'MB')
|
||||||
console.log('Free memory:', (os.freemem() / (1024 * 1024)).toFixed(2), 'MB')
|
console.log('Free memory:', (os.freemem() / (1024 * 1024)).toFixed(2), 'MB')
|
||||||
|
|
||||||
|
|
||||||
|
const shouldQuit = app.makeSingleInstance(function(commandLine, workingDirectory) {
|
||||||
|
// Someone tried to run a second instance, we should focus our window.
|
||||||
|
console.log('openned second application, just focus this one')
|
||||||
|
if (mainWindow) {
|
||||||
|
if (mainWindow.isMinimized())
|
||||||
|
mainWindow.restore();
|
||||||
|
mainWindow.focus();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (shouldQuit) {
|
||||||
|
console.log('closed because of second application')
|
||||||
|
app.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
const writeSphinxConfig = (path, dbPath) => {
|
const writeSphinxConfig = (path, dbPath) => {
|
||||||
let config = `
|
let config = `
|
||||||
index torrents
|
index torrents
|
||||||
@ -241,7 +258,7 @@ app.on("ready", () => {
|
|||||||
startSphinx(() => {
|
startSphinx(() => {
|
||||||
setApplicationMenu();
|
setApplicationMenu();
|
||||||
|
|
||||||
const mainWindow = createWindow("main", {
|
mainWindow = createWindow("main", {
|
||||||
width: 1000,
|
width: 1000,
|
||||||
height: 600
|
height: 600
|
||||||
});
|
});
|
||||||
@ -269,6 +286,9 @@ app.on("ready", () => {
|
|||||||
mainWindow.on('hide', () => {
|
mainWindow.on('hide', () => {
|
||||||
tray.setHighlightMode('never')
|
tray.setHighlightMode('never')
|
||||||
})
|
})
|
||||||
|
mainWindow.on('closed', () => {
|
||||||
|
mainWindow = undefined
|
||||||
|
})
|
||||||
|
|
||||||
mainWindow.on('minimize', (event) => {
|
mainWindow.on('minimize', (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
Loading…
Reference in New Issue
Block a user