mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
239 lines
5.1 KiB
JavaScript
239 lines
5.1 KiB
JavaScript
var app = require('app') // Module to control application life.
|
|
var BrowserWindow = require('browser-window') // Module to create native browser window.
|
|
|
|
// Report crashes to our server.
|
|
require('crash-reporter').start()
|
|
|
|
// Keep a global reference of the window object, if you don't, the window will
|
|
// be closed automatically when the javascript object is GCed.
|
|
var mainWindow = null
|
|
|
|
// app.on('window-all-closed', function () {
|
|
// if (process.platform !== 'darwin') app.quit()
|
|
// })
|
|
|
|
var clipboard = require('clipboard')
|
|
|
|
var Tray = require('tray')
|
|
var appIcon = null
|
|
|
|
app.on('ready', function () {
|
|
appIcon = new Tray('./icon.png')
|
|
appIcon.setToolTip('This is my application.')
|
|
appIcon.on('clicked', function () {
|
|
if (mainWindow == null) {
|
|
makeNewMainWindow()
|
|
}
|
|
mainWindow.show()
|
|
})
|
|
|
|
makeNewMainWindow()
|
|
|
|
var globalShortcut = require('global-shortcut')
|
|
|
|
var popUpWindow = new BrowserWindow({
|
|
width: 600,
|
|
height: 400,
|
|
show: false,
|
|
frame: false,
|
|
'web-preferences': {
|
|
'overlay-scrollbars': true
|
|
}
|
|
})
|
|
|
|
popUpWindow.loadUrl('file://' + __dirname + '/electron_build/electron/popup/index.html')
|
|
|
|
app.on('activate-with-no-open-windows', function () {
|
|
if (mainWindow == null) {
|
|
makeNewMainWindow()
|
|
}
|
|
mainWindow.show()
|
|
})
|
|
|
|
popUpWindow.on('blur', function () {
|
|
popUpWindow.hide()
|
|
})
|
|
|
|
var hidePopUp = function () {
|
|
if (fromMain) {
|
|
|
|
} else {
|
|
mainWindow ? mainWindow.hide() : null
|
|
Menu.sendActionToFirstResponder('hide:')
|
|
}
|
|
|
|
popUpWindow.hide()
|
|
}
|
|
|
|
var ipc = require('ipc')
|
|
ipc.on('hidePopUp', function () {
|
|
hidePopUp()
|
|
})
|
|
ipc.on('writeCode', function (e, code) {
|
|
clipboard.writeText(code)
|
|
hidePopUp()
|
|
})
|
|
|
|
var fromMain
|
|
// Register a 'ctrl+x' shortcut listener.
|
|
var ret = globalShortcut.register('ctrl+tab+shift', function () {
|
|
if (popUpWindow.isVisible()) {
|
|
hidePopUp()
|
|
return
|
|
}
|
|
fromMain = mainWindow ? mainWindow.isFocused() : false
|
|
popUpWindow.show()
|
|
|
|
})
|
|
if (!ret) console.log('registerion fails')
|
|
|
|
// MENU
|
|
var Menu = require('menu')
|
|
var template = [
|
|
{
|
|
label: 'Electron',
|
|
submenu: [
|
|
{
|
|
label: 'About Electron',
|
|
selector: 'orderFrontStandardAboutPanel:'
|
|
},
|
|
{
|
|
type: 'separator'
|
|
},
|
|
{
|
|
label: 'Services',
|
|
submenu: []
|
|
},
|
|
{
|
|
type: 'separator'
|
|
},
|
|
{
|
|
label: 'Hide Electron',
|
|
accelerator: 'Command+H',
|
|
selector: 'hide:'
|
|
},
|
|
{
|
|
label: 'Hide Others',
|
|
accelerator: 'Command+Shift+H',
|
|
selector: 'hideOtherApplications:'
|
|
},
|
|
{
|
|
label: 'Show All',
|
|
selector: 'unhideAllApplications:'
|
|
},
|
|
{
|
|
type: 'separator'
|
|
},
|
|
{
|
|
label: 'Quit',
|
|
accelerator: 'Command+Q',
|
|
click: function () { app.quit() }
|
|
}
|
|
]
|
|
},
|
|
{
|
|
label: 'Edit',
|
|
submenu: [
|
|
{
|
|
label: 'Undo',
|
|
accelerator: 'Command+Z',
|
|
selector: 'undo:'
|
|
},
|
|
{
|
|
label: 'Redo',
|
|
accelerator: 'Shift+Command+Z',
|
|
selector: 'redo:'
|
|
},
|
|
{
|
|
type: 'separator'
|
|
},
|
|
{
|
|
label: 'Cut',
|
|
accelerator: 'Command+X',
|
|
selector: 'cut:'
|
|
},
|
|
{
|
|
label: 'Copy',
|
|
accelerator: 'Command+C',
|
|
selector: 'copy:'
|
|
},
|
|
{
|
|
label: 'Paste',
|
|
accelerator: 'Command+V',
|
|
selector: 'paste:'
|
|
},
|
|
{
|
|
label: 'Select All',
|
|
accelerator: 'Command+A',
|
|
selector: 'selectAll:'
|
|
}
|
|
]
|
|
},
|
|
{
|
|
label: 'View',
|
|
submenu: [
|
|
{
|
|
label: 'Reload',
|
|
accelerator: 'Command+R',
|
|
click: function () { BrowserWindow.getFocusedWindow().reloadIgnoringCache() }
|
|
},
|
|
{
|
|
label: 'Toggle DevTools',
|
|
accelerator: 'Alt+Command+I',
|
|
click: function () { BrowserWindow.getFocusedWindow().toggleDevTools() }
|
|
}
|
|
]
|
|
},
|
|
{
|
|
label: 'Window',
|
|
submenu: [
|
|
{
|
|
label: 'Minimize',
|
|
accelerator: 'Command+M',
|
|
selector: 'performMiniaturize:'
|
|
},
|
|
{
|
|
label: 'Close',
|
|
accelerator: 'Command+W',
|
|
selector: 'performClose:'
|
|
},
|
|
{
|
|
type: 'separator'
|
|
},
|
|
{
|
|
label: 'Bring All to Front',
|
|
selector: 'arrangeInFront:'
|
|
}
|
|
]
|
|
},
|
|
{
|
|
label: 'Help',
|
|
submenu: []
|
|
}
|
|
]
|
|
|
|
var menu = Menu.buildFromTemplate(template)
|
|
|
|
Menu.setApplicationMenu(menu)
|
|
|
|
function makeNewMainWindow () {
|
|
console.log('new Window!')
|
|
mainWindow = new BrowserWindow({
|
|
width: 800,
|
|
height: 600,
|
|
'web-preferences': {
|
|
'overlay-scrollbars': true
|
|
}
|
|
})
|
|
|
|
mainWindow.loadUrl('file://' + __dirname + '/electron_build/index.html')
|
|
|
|
mainWindow.on('closed', function () {
|
|
console.log('main closed')
|
|
mainWindow = null
|
|
app.dock.hide()
|
|
})
|
|
app.dock.show()
|
|
}
|
|
})
|