Skip to content

Commit

Permalink
feat(app): allow run only single application at same time
Browse files Browse the repository at this point in the history
  • Loading branch information
DEgITx committed Feb 12, 2018
1 parent 45c408f commit e942c03
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/background/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const resourcesPath = env.name === "production" ? process.resourcesPath : 'resou
const spiderCall = require('./spider')
const appConfig = require('./config')

let mainWindow = undefined
let sphinx = undefined
let spider = undefined

Expand All @@ -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('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) => {
let config = `
index torrents
Expand Down Expand Up @@ -241,7 +258,7 @@ app.on("ready", () => {
startSphinx(() => {
setApplicationMenu();

const mainWindow = createWindow("main", {
mainWindow = createWindow("main", {
width: 1000,
height: 600
});
Expand All @@ -268,7 +285,10 @@ app.on("ready", () => {
})
mainWindow.on('hide', () => {
tray.setHighlightMode('never')
})
})
mainWindow.on('closed', () => {
mainWindow = undefined
})

mainWindow.on('minimize', (event) => {
event.preventDefault();
Expand Down

0 comments on commit e942c03

Please sign in to comment.