forked from hokein/electron-sample-apps
-
Notifications
You must be signed in to change notification settings - Fork 0
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
54 additions
and
58 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,56 +1,52 @@ | ||
var app = require('app'); | ||
var Tray = require('tray'); | ||
var Menu = require('menu'); | ||
var path = require('path'); | ||
var powerSaveBlocker = require('power-save-blocker'); | ||
var BrowserWindow = require('browser-window'); | ||
|
||
var appIcon = null; | ||
var win = null; | ||
var disabledIconPath = path.join(__dirname, 'images', 'night-19.png'); | ||
var appSuspensionIconPath = path.join(__dirname, 'images', 'sunset-19.png'); | ||
var displaySleepIconPath = path.join(__dirname, 'images', 'day-19.png'); | ||
|
||
app.on('ready', function(){ | ||
win = new BrowserWindow({show: false}); | ||
appIcon = new Tray(disabledIconPath); | ||
var blocker_id = null; | ||
var contextMenu = Menu.buildFromTemplate([ | ||
{ | ||
label: 'Prevent app suspension', | ||
type: 'radio', | ||
icon: appSuspensionIconPath, | ||
click: function() { | ||
if (blocker_id) | ||
powerSaveBlocker.stop(blocker_id); | ||
blocker_id = powerSaveBlocker.start('prevent-app-suspension'); | ||
} | ||
}, | ||
{ | ||
label: 'Prevent display sleep', | ||
type: 'radio', | ||
icon: displaySleepIconPath, | ||
click: function() { | ||
if (blocker_id) | ||
powerSaveBlocker.stop(blocker_id); | ||
blocker_id = powerSaveBlocker.start('prevent-display-sleep'); | ||
} | ||
}, | ||
{ | ||
label: 'Disable', | ||
type: 'radio', | ||
icon: disabledIconPath, | ||
checked: true, | ||
click: function() { | ||
if (blocker_id) | ||
powerSaveBlocker.stop(blocker_id); | ||
} | ||
}, | ||
{ label: 'Quit', | ||
accelerator: 'Command+Q', | ||
selector: 'terminate:', | ||
} | ||
]); | ||
appIcon.setToolTip('Keep system awake'); | ||
appIcon.setContextMenu(contextMenu); | ||
}); | ||
const {app, Tray, Menu, powerSaveBlocker, BrowserWindow} = require('electron'); | ||
const path = require('path'); | ||
|
||
let appIcon; | ||
let win; | ||
const disabledIconPath = path.join(__dirname, 'images', 'night-19.png'); | ||
const appSuspensionIconPath = path.join(__dirname, 'images', 'sunset-19.png'); | ||
const displaySleepIconPath = path.join(__dirname, 'images', 'day-19.png'); | ||
|
||
app.on('ready', function(){ | ||
win = new BrowserWindow({show: false}); | ||
appIcon = new Tray(disabledIconPath); | ||
let blocker_id = null; | ||
var contextMenu = Menu.buildFromTemplate([ | ||
{ | ||
label: 'Prevent app suspension', | ||
type: 'radio', | ||
icon: appSuspensionIconPath, | ||
click: function() { | ||
if (blocker_id) | ||
powerSaveBlocker.stop(blocker_id); | ||
blocker_id = powerSaveBlocker.start('prevent-app-suspension'); | ||
} | ||
}, | ||
{ | ||
label: 'Prevent display sleep', | ||
type: 'radio', | ||
icon: displaySleepIconPath, | ||
click: function() { | ||
if (blocker_id) | ||
powerSaveBlocker.stop(blocker_id); | ||
blocker_id = powerSaveBlocker.start('prevent-display-sleep'); | ||
} | ||
}, | ||
{ | ||
label: 'Disable', | ||
type: 'radio', | ||
icon: disabledIconPath, | ||
checked: true, | ||
click: function() { | ||
if (blocker_id) | ||
powerSaveBlocker.stop(blocker_id); | ||
} | ||
}, | ||
{ label: 'Quit', | ||
accelerator: 'Command+Q', | ||
selector: 'terminate:', | ||
} | ||
]); | ||
appIcon.setToolTip('Keep system awake'); | ||
appIcon.setContextMenu(contextMenu); | ||
}); |
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,5 +1,5 @@ | ||
{ | ||
"name" : "power-save-blocker-demo", | ||
"version" : "0.1.0", | ||
"version" : "1.1.0", | ||
"main" : "main.js" | ||
} |
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