menu: add float on top
This commit is contained in:
74
index.js
74
index.js
@@ -7,7 +7,7 @@ var electron = require('electron')
|
|||||||
var path = require('path')
|
var path = require('path')
|
||||||
|
|
||||||
var app = electron.app
|
var app = electron.app
|
||||||
var mainWindow
|
var mainWindow, menu
|
||||||
|
|
||||||
// report crashes
|
// report crashes
|
||||||
// require('crash-reporter').start({
|
// require('crash-reporter').start({
|
||||||
@@ -23,7 +23,7 @@ app.on('open-url', onOpen)
|
|||||||
app.on('ready', function () {
|
app.on('ready', function () {
|
||||||
mainWindow = createMainWindow()
|
mainWindow = createMainWindow()
|
||||||
|
|
||||||
var menu = electron.Menu.buildFromTemplate(getMenuTemplate())
|
menu = electron.Menu.buildFromTemplate(getMenuTemplate())
|
||||||
electron.Menu.setApplicationMenu(menu)
|
electron.Menu.setApplicationMenu(menu)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -129,9 +129,7 @@ function setAspectRatio (aspectRatio, extraSize) {
|
|||||||
// Display string in dock badging area (OS X)
|
// Display string in dock badging area (OS X)
|
||||||
function setBadge (text) {
|
function setBadge (text) {
|
||||||
debug('setBadge %s', text)
|
debug('setBadge %s', text)
|
||||||
if (mainWindow) {
|
app.dock.setBadge(String(text))
|
||||||
app.dock.setBadge(String(text))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show progress bar. Valid range is [0, 1]. Remove when < 0; indeterminate when > 1.
|
// Show progress bar. Valid range is [0, 1]. Remove when < 0; indeterminate when > 1.
|
||||||
@@ -142,22 +140,35 @@ function setProgress (progress) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleDevTools (win) {
|
function toggleFullScreen () {
|
||||||
debug('toggleDevTools')
|
debug('toggleFullScreen')
|
||||||
win = win || electron.BrowserWindow.getFocusedWindow()
|
if (mainWindow) {
|
||||||
|
mainWindow.setFullScreen(!mainWindow.isFullScreen())
|
||||||
if (win) {
|
getMenuItem('Full Screen').checked = mainWindow.isFullScreen()
|
||||||
win.toggleDevTools()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function reloadWindow (win) {
|
// Sets whether the window should always show on top of other windows
|
||||||
debug('reloadWindow')
|
function toggleAlwaysOnTop () {
|
||||||
win = win || electron.BrowserWindow.getFocusedWindow()
|
debug('toggleAlwaysOnTop %s')
|
||||||
|
if (mainWindow) {
|
||||||
|
mainWindow.setAlwaysOnTop(!mainWindow.isAlwaysOnTop())
|
||||||
|
getMenuItem('Float on Top').checked = mainWindow.isAlwaysOnTop()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (win) {
|
function toggleDevTools () {
|
||||||
|
debug('toggleDevTools')
|
||||||
|
if (mainWindow) {
|
||||||
|
mainWindow.toggleDevTools()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function reloadWindow () {
|
||||||
|
debug('reloadWindow')
|
||||||
|
if (mainWindow) {
|
||||||
startTime = Date.now()
|
startTime = Date.now()
|
||||||
win.webContents.reloadIgnoringCache()
|
mainWindow.webContents.reloadIgnoringCache()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,14 +249,18 @@ function getMenuTemplate () {
|
|||||||
label: 'View',
|
label: 'View',
|
||||||
submenu: [
|
submenu: [
|
||||||
{
|
{
|
||||||
label: 'Toggle Full Screen',
|
label: 'Full Screen',
|
||||||
|
type: 'checkbox',
|
||||||
accelerator: (function () {
|
accelerator: (function () {
|
||||||
if (process.platform === 'darwin') return 'Ctrl+Command+F'
|
if (process.platform === 'darwin') return 'Ctrl+Command+F'
|
||||||
else return 'F11'
|
else return 'F11'
|
||||||
})(),
|
})(),
|
||||||
click: function (item, focusedWindow) {
|
click: toggleFullScreen
|
||||||
if (focusedWindow) focusedWindow.setFullScreen(!focusedWindow.isFullScreen())
|
},
|
||||||
}
|
{
|
||||||
|
label: 'Float on Top',
|
||||||
|
type: 'checkbox',
|
||||||
|
click: toggleAlwaysOnTop
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'separator'
|
type: 'separator'
|
||||||
@@ -253,19 +268,15 @@ function getMenuTemplate () {
|
|||||||
{
|
{
|
||||||
label: 'Reload',
|
label: 'Reload',
|
||||||
accelerator: 'CmdOrCtrl+R',
|
accelerator: 'CmdOrCtrl+R',
|
||||||
click: function (item, focusedWindow) {
|
click: reloadWindow
|
||||||
reloadWindow(focusedWindow)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: 'Toggle Developer Tools',
|
label: 'Developer Tools',
|
||||||
accelerator: (function () {
|
accelerator: (function () {
|
||||||
if (process.platform === 'darwin') return 'Alt+Command+I'
|
if (process.platform === 'darwin') return 'Alt+Command+I'
|
||||||
else return 'Ctrl+Shift+I'
|
else return 'Ctrl+Shift+I'
|
||||||
})(),
|
})(),
|
||||||
click: function (item, focusedWindow) {
|
click: toggleDevTools
|
||||||
toggleDevTools(focusedWindow)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -362,3 +373,12 @@ function getMenuTemplate () {
|
|||||||
|
|
||||||
return template
|
return template
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getMenuItem (label) {
|
||||||
|
for (var i = 0; i < menu.items.length; i++) {
|
||||||
|
var menuItem = menu.items[i].submenu.items.find(function (item) {
|
||||||
|
return item.label === label
|
||||||
|
})
|
||||||
|
if (menuItem) return menuItem
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user