mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
Finder behaviour for windows
This commit is contained in:
@@ -1,6 +1,55 @@
|
|||||||
const electron = require('electron')
|
const electron = require('electron')
|
||||||
const BrowserWindow = electron.BrowserWindow
|
const BrowserWindow = electron.BrowserWindow
|
||||||
|
const Menu = electron.Menu
|
||||||
|
const MenuItem = electron.MenuItem
|
||||||
|
const app = electron.app
|
||||||
|
const ipcMain = electron.ipcMain
|
||||||
|
const Tray = electron.Tray
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
const nodeIpc = require('node-ipc')
|
||||||
|
|
||||||
|
var isFinderLoaded = false
|
||||||
|
|
||||||
|
nodeIpc.config.id = 'finder'
|
||||||
|
nodeIpc.config.retry = 1500
|
||||||
|
nodeIpc.config.silent = true
|
||||||
|
|
||||||
|
nodeIpc.connectTo(
|
||||||
|
'main',
|
||||||
|
path.join(app.getPath('userData'), 'boost.service'),
|
||||||
|
function () {
|
||||||
|
nodeIpc.of.main.on(
|
||||||
|
'connect',
|
||||||
|
function () {
|
||||||
|
nodeIpc.log('<< ## connected to world ##'.rainbow, nodeIpc.config.delay)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
nodeIpc.of.main.on(
|
||||||
|
'disconnect',
|
||||||
|
function(){
|
||||||
|
nodeIpc.log('<< disconnected from main'.notice)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
nodeIpc.of.main.on(
|
||||||
|
'message',
|
||||||
|
function (payload) {
|
||||||
|
switch (payload.type) {
|
||||||
|
case 'open-finder':
|
||||||
|
if (isFinderLoaded) openFinder()
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
function emit (type, data) {
|
||||||
|
var payload = {
|
||||||
|
type: type,
|
||||||
|
data: data
|
||||||
|
}
|
||||||
|
nodeIpc.of.main.emit('message', payload)
|
||||||
|
}
|
||||||
|
|
||||||
var config = {
|
var config = {
|
||||||
width: 640,
|
width: 640,
|
||||||
@@ -25,9 +74,64 @@ var finderWindow = new BrowserWindow(config)
|
|||||||
var url = path.resolve(__dirname, '../browser/finder/index.html')
|
var url = path.resolve(__dirname, '../browser/finder/index.html')
|
||||||
|
|
||||||
finderWindow.loadURL('file://' + url)
|
finderWindow.loadURL('file://' + url)
|
||||||
|
finderWindow.setSkipTaskbar(true)
|
||||||
|
|
||||||
if (process.platform === 'darwin') {
|
if (process.platform === 'darwin') {
|
||||||
finderWindow.setVisibleOnAllWorkspaces(true)
|
finderWindow.setVisibleOnAllWorkspaces(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
finderWindow.on('blur', function () {
|
||||||
|
hideFinder()
|
||||||
|
})
|
||||||
|
|
||||||
|
finderWindow.webContents.on('did-finish-load', function () {
|
||||||
|
var appIcon = new Tray(path.join(__dirname, '../resources/tray-icon.png'))
|
||||||
|
appIcon.setToolTip('Boost')
|
||||||
|
|
||||||
|
var trayMenu = new Menu()
|
||||||
|
trayMenu.append(new MenuItem({
|
||||||
|
label: 'Open Main window',
|
||||||
|
click: function () {
|
||||||
|
emit('show-main-window')
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
trayMenu.append(new MenuItem({
|
||||||
|
label: 'Open Finder window',
|
||||||
|
click: function () {
|
||||||
|
openFinder()
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
trayMenu.append(new MenuItem({
|
||||||
|
label: 'Quit',
|
||||||
|
click: function () {
|
||||||
|
emit('quit-app')
|
||||||
|
} }))
|
||||||
|
|
||||||
|
appIcon.setContextMenu(trayMenu)
|
||||||
|
appIcon.on('click', function (e) {
|
||||||
|
e.preventDefault()
|
||||||
|
appIcon.popUpContextMenu(trayMenu)
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.on('copy-finder', function () {
|
||||||
|
emit('copy-finder')
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.on('hide-finder', function () {
|
||||||
|
hideFinder()
|
||||||
|
})
|
||||||
|
|
||||||
|
isFinderLoaded = true
|
||||||
|
})
|
||||||
|
|
||||||
|
function openFinder () {
|
||||||
|
finderWindow.show()
|
||||||
|
}
|
||||||
|
function hideFinder () {
|
||||||
|
if (process.platform === 'win32') {
|
||||||
|
finderWindow.minimize()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
finderWindow.hide()
|
||||||
|
}
|
||||||
module.exports = finderWindow
|
module.exports = finderWindow
|
||||||
|
|||||||
115
finder.js
115
finder.js
@@ -1,80 +1,10 @@
|
|||||||
const electron = require('electron')
|
const electron = require('electron')
|
||||||
const app = electron.app
|
const app = electron.app
|
||||||
const Tray = electron.Tray
|
|
||||||
const Menu = electron.Menu
|
const Menu = electron.Menu
|
||||||
const MenuItem = electron.MenuItem
|
|
||||||
const ipcMain = electron.ipcMain
|
const ipcMain = electron.ipcMain
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
|
||||||
const nodeIpc = require('node-ipc')
|
|
||||||
|
|
||||||
var finderWindow = null
|
var finderWindow = null
|
||||||
var isFinderLoaded = false
|
|
||||||
|
|
||||||
function hideFinder () {
|
|
||||||
if (!isFinderLoaded) return false
|
|
||||||
|
|
||||||
if (process.platform === 'darwin') {
|
|
||||||
Menu.sendActionToFirstResponder('hide:')
|
|
||||||
}
|
|
||||||
if (process.platform === 'win32') {
|
|
||||||
finderWindow.minimize()
|
|
||||||
}
|
|
||||||
finderWindow.hide()
|
|
||||||
}
|
|
||||||
|
|
||||||
function showFinder () {
|
|
||||||
if (!isFinderLoaded) return false
|
|
||||||
|
|
||||||
if (!finderWindow.isVisible()) {
|
|
||||||
finderWindow.show()
|
|
||||||
}
|
|
||||||
if (process.platform === 'win32') {
|
|
||||||
finderWindow.minimize()
|
|
||||||
finderWindow.restore()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
nodeIpc.config.id = 'finder'
|
|
||||||
nodeIpc.config.retry = 1500
|
|
||||||
nodeIpc.config.silent = true
|
|
||||||
|
|
||||||
nodeIpc.connectTo(
|
|
||||||
'main',
|
|
||||||
path.join(app.getPath('userData'), 'boost.service'),
|
|
||||||
function () {
|
|
||||||
nodeIpc.of.main.on(
|
|
||||||
'connect',
|
|
||||||
function () {
|
|
||||||
nodeIpc.log('<< ## connected to world ##'.rainbow, nodeIpc.config.delay)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
nodeIpc.of.main.on(
|
|
||||||
'disconnect',
|
|
||||||
function(){
|
|
||||||
nodeIpc.log('<< disconnected from main'.notice)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
nodeIpc.of.main.on(
|
|
||||||
'message',
|
|
||||||
function (payload) {
|
|
||||||
switch (payload.type) {
|
|
||||||
case 'open-finder':
|
|
||||||
showFinder()
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
function emit (type, data) {
|
|
||||||
var payload = {
|
|
||||||
type: type,
|
|
||||||
data: data
|
|
||||||
}
|
|
||||||
nodeIpc.of.main.emit('message', payload)
|
|
||||||
}
|
|
||||||
|
|
||||||
var appQuit = false
|
var appQuit = false
|
||||||
app.on('ready', function () {
|
app.on('ready', function () {
|
||||||
@@ -82,59 +12,16 @@ app.on('ready', function () {
|
|||||||
app.dock.hide()
|
app.dock.hide()
|
||||||
}
|
}
|
||||||
|
|
||||||
var appIcon = new Tray(__dirname + '/resources/tray-icon.png')
|
|
||||||
appIcon.setToolTip('Boost')
|
|
||||||
|
|
||||||
var template = require('./atom-lib/menu-template')
|
var template = require('./atom-lib/menu-template')
|
||||||
var menu = Menu.buildFromTemplate(template)
|
var menu = Menu.buildFromTemplate(template)
|
||||||
Menu.setApplicationMenu(menu)
|
Menu.setApplicationMenu(menu)
|
||||||
|
|
||||||
finderWindow = require('./atom-lib/finder-window')
|
finderWindow = require('./atom-lib/finder-window')
|
||||||
finderWindow.webContents.on('did-finish-load', function () {
|
|
||||||
var trayMenu = new Menu()
|
|
||||||
trayMenu.append(new MenuItem({
|
|
||||||
label: 'Open Main window',
|
|
||||||
click: function () {
|
|
||||||
emit('show-main-window')
|
|
||||||
}
|
|
||||||
}))
|
|
||||||
trayMenu.append(new MenuItem({
|
|
||||||
label: 'Open Finder window',
|
|
||||||
click: function () {
|
|
||||||
showFinder()
|
|
||||||
}
|
|
||||||
}))
|
|
||||||
trayMenu.append(new MenuItem({
|
|
||||||
label: 'Quit',
|
|
||||||
click: function () {
|
|
||||||
emit('quit-app')
|
|
||||||
}
|
|
||||||
}))
|
|
||||||
appIcon.setContextMenu(trayMenu)
|
|
||||||
appIcon.on('click', function (e) {
|
|
||||||
e.preventDefault()
|
|
||||||
appIcon.popUpContextMenu(trayMenu)
|
|
||||||
})
|
|
||||||
|
|
||||||
ipcMain.on('copy-finder', function () {
|
|
||||||
emit('copy-finder')
|
|
||||||
})
|
|
||||||
|
|
||||||
ipcMain.on('hide-finder', function () {
|
|
||||||
hideFinder()
|
|
||||||
})
|
|
||||||
|
|
||||||
isFinderLoaded = true
|
|
||||||
})
|
|
||||||
|
|
||||||
finderWindow.on('blur', function () {
|
|
||||||
hideFinder()
|
|
||||||
})
|
|
||||||
|
|
||||||
finderWindow.on('close', function (e) {
|
finderWindow.on('close', function (e) {
|
||||||
if (appQuit) return true
|
if (appQuit) return true
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
hideFinder()
|
finderWindow.hide()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
20
main.js
20
main.js
@@ -65,8 +65,8 @@ autoUpdater
|
|||||||
|
|
||||||
const nodeIpc = require('node-ipc')
|
const nodeIpc = require('node-ipc')
|
||||||
var isNodeIpcReady = false
|
var isNodeIpcReady = false
|
||||||
nodeIpc.config.id = 'node'
|
nodeIpc.config.id = 'node'
|
||||||
nodeIpc.config.retry= 1500
|
nodeIpc.config.retry = 1500
|
||||||
nodeIpc.config.silent = true
|
nodeIpc.config.silent = true
|
||||||
|
|
||||||
nodeIpc.serve(
|
nodeIpc.serve(
|
||||||
@@ -75,7 +75,7 @@ nodeIpc.serve(
|
|||||||
isNodeIpcReady = true
|
isNodeIpcReady = true
|
||||||
nodeIpc.server.on(
|
nodeIpc.server.on(
|
||||||
'message',
|
'message',
|
||||||
function (data, socket){
|
function (data, socket) {
|
||||||
console.log('>>', data)
|
console.log('>>', data)
|
||||||
format(data)
|
format(data)
|
||||||
}
|
}
|
||||||
@@ -83,7 +83,6 @@ nodeIpc.serve(
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
function format (payload) {
|
function format (payload) {
|
||||||
switch (payload.type) {
|
switch (payload.type) {
|
||||||
case 'show-main-window':
|
case 'show-main-window':
|
||||||
@@ -145,13 +144,22 @@ app.on('ready', function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mainWindow.webContents.on('did-finish-load', function () {
|
mainWindow.webContents.on('did-finish-load', function () {
|
||||||
if (finderProcess == null) {
|
if (finderProcess == null && process.platform === 'darwin') {
|
||||||
var finderArgv = [path.resolve(__dirname, 'finder.js'), '--finder']
|
var finderArgv = [path.join(__dirname, 'finder.js'), '--finder']
|
||||||
if (_.find(process.argv, a => a === '--hot')) finderArgv.push('--hot')
|
if (_.find(process.argv, a => a === '--hot')) finderArgv.push('--hot')
|
||||||
finderProcess = ChildProcess
|
finderProcess = ChildProcess
|
||||||
.execFile(process.execPath, finderArgv)
|
.execFile(process.execPath, finderArgv)
|
||||||
|
|
||||||
nodeIpc.server.start()
|
nodeIpc.server.start()
|
||||||
|
} else {
|
||||||
|
finderWindow = require('./atom-lib/finder-window')
|
||||||
|
|
||||||
|
finderWindow.on('close', function (e) {
|
||||||
|
if (appQuit) return true
|
||||||
|
e.preventDefault()
|
||||||
|
finderWindow.hide()
|
||||||
|
})
|
||||||
|
nodeIpc.server.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (update != null) {
|
if (update != null) {
|
||||||
|
|||||||
Reference in New Issue
Block a user