mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-21 13:41:40 +00:00
Finder
This commit is contained in:
@@ -2,80 +2,12 @@ const electron = require('electron')
|
||||
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 nodeIpc = require('@rokt33r/node-ipc')
|
||||
|
||||
var appQuit = false
|
||||
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(
|
||||
'error',
|
||||
function (err) {
|
||||
nodeIpc.log('<< ## err ##'.rainbow, nodeIpc.config.delay)
|
||||
nodeIpc.log(err)
|
||||
}
|
||||
)
|
||||
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)
|
||||
if (process.platform === 'darwin') {
|
||||
appQuit = true
|
||||
app.quit()
|
||||
}
|
||||
}
|
||||
)
|
||||
nodeIpc.of.main.on(
|
||||
'message',
|
||||
function (payload) {
|
||||
if (isFinderLoaded) {
|
||||
switch (payload.type) {
|
||||
case 'open-finder':
|
||||
if (finderWindow.isFocused()) {
|
||||
hideFinder()
|
||||
} else {
|
||||
openFinder()
|
||||
}
|
||||
break
|
||||
case 'config-apply': {
|
||||
finderWindow.webContents.send('config-apply', payload.data)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
function emit (type, data) {
|
||||
var payload = {
|
||||
type: type,
|
||||
data: data
|
||||
}
|
||||
nodeIpc.of.main.emit('message', payload)
|
||||
}
|
||||
|
||||
var config = {
|
||||
width: 640,
|
||||
height: 400,
|
||||
width: 840,
|
||||
height: 540,
|
||||
show: false,
|
||||
frame: false,
|
||||
resizable: false,
|
||||
@@ -107,11 +39,8 @@ finderWindow.on('blur', function () {
|
||||
})
|
||||
|
||||
finderWindow.on('close', function (e) {
|
||||
if (process.platform === 'darwin') {
|
||||
if (appQuit) return true
|
||||
e.preventDefault()
|
||||
finderWindow.hide()
|
||||
}
|
||||
e.preventDefault()
|
||||
finderWindow.hide()
|
||||
})
|
||||
|
||||
var appIcon = new Tray(path.join(__dirname, '../resources/tray-icon.png'))
|
||||
@@ -121,19 +50,21 @@ 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()
|
||||
finderWindow.webContents.send('open-main-from-tray')
|
||||
}
|
||||
}))
|
||||
if (process.env.platform !== 'linux' || process.env.DESKTOP_SESSION === 'cinnamon') {
|
||||
trayMenu.append(new MenuItem({
|
||||
label: 'Open Finder window',
|
||||
click: function () {
|
||||
finderWindow.webContents.send('open-finder-from-tray')
|
||||
}
|
||||
}))
|
||||
}
|
||||
trayMenu.append(new MenuItem({
|
||||
label: 'Quit',
|
||||
click: function () {
|
||||
emit('quit-app')
|
||||
finderWindow.webContents.send('quit-from-tray')
|
||||
}
|
||||
}))
|
||||
|
||||
@@ -143,21 +74,6 @@ appIcon.on('click', function (e) {
|
||||
appIcon.popUpContextMenu(trayMenu)
|
||||
})
|
||||
|
||||
ipcMain.on('copy-finder', function () {
|
||||
emit('copy-finder')
|
||||
})
|
||||
|
||||
ipcMain.on('hide-finder', function () {
|
||||
hideFinder()
|
||||
})
|
||||
|
||||
finderWindow.webContents.on('did-finish-load', function () {
|
||||
isFinderLoaded = true
|
||||
})
|
||||
|
||||
function openFinder () {
|
||||
if (isFinderLoaded) finderWindow.show()
|
||||
}
|
||||
function hideFinder () {
|
||||
if (process.platform === 'win32') {
|
||||
finderWindow.minimize()
|
||||
|
||||
Reference in New Issue
Block a user