mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 09:46:22 +00:00
Finder
This commit is contained in:
@@ -9,9 +9,9 @@ app.on('ready', function () {
|
||||
app.dock.hide()
|
||||
}
|
||||
|
||||
var template = require('./finder-menu')
|
||||
var menu = Menu.buildFromTemplate(template)
|
||||
Menu.setApplicationMenu(menu)
|
||||
// var template = require('./finder-menu')
|
||||
// var menu = Menu.buildFromTemplate(template)
|
||||
// Menu.setApplicationMenu(menu)
|
||||
|
||||
finderWindow = require('./finder-window')
|
||||
})
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -28,11 +28,12 @@
|
||||
<body>
|
||||
<div id="content"></div>
|
||||
<script src="../node_modules/ace-builds/src-min/ace.js"></script>
|
||||
<script src="../node_modules/ace-builds/src-min/ext-themelist.js"></script>
|
||||
<script src="../resources/katex.min.js"></script>
|
||||
<script src="../compiled/react.min.js"></script>
|
||||
<script src="../compiled/react-dom.min.js"></script>
|
||||
<script src="../compiled/redux.min.js"></script>
|
||||
<script src="../compiled/react-redux.min.js"></script>
|
||||
<script src="../compiled/react.js"></script>
|
||||
<script src="../compiled/react-dom.js"></script>
|
||||
<script src="../compiled/redux.js"></script>
|
||||
<script src="../compiled/react-redux.js"></script>
|
||||
<script>
|
||||
const electron = require('electron')
|
||||
electron.webFrame.setZoomLevelLimits(1, 1)
|
||||
|
||||
@@ -3,19 +3,8 @@ const ipc = electron.ipcMain
|
||||
const Menu = electron.Menu
|
||||
const globalShortcut = electron.globalShortcut
|
||||
const mainWindow = require('./main-window')
|
||||
// const nodeIpc = require('@rokt33r/node-ipc')
|
||||
|
||||
function emitToFinder (type, data) {
|
||||
var payload = {
|
||||
type: type,
|
||||
data: data
|
||||
}
|
||||
|
||||
// nodeIpc.server.broadcast('message', payload)
|
||||
}
|
||||
|
||||
function toggleFinder () {
|
||||
emitToFinder('open-finder')
|
||||
mainWindow.webContents.send('open-finder', {})
|
||||
}
|
||||
|
||||
@@ -33,11 +22,10 @@ function toggleMain () {
|
||||
mainWindow.minimize()
|
||||
mainWindow.restore()
|
||||
}
|
||||
mainWindow.webContents.send('top-focus-search')
|
||||
}
|
||||
}
|
||||
|
||||
ipc.on('CONFIG_RENEW', (e, payload) => {
|
||||
ipc.on('config-renew', (e, payload) => {
|
||||
globalShortcut.unregisterAll()
|
||||
var { config } = payload
|
||||
|
||||
|
||||
195
lib/main-app.js
195
lib/main-app.js
@@ -12,7 +12,6 @@ const GhReleases = require('electron-gh-releases')
|
||||
var mainWindow = null
|
||||
var finderProcess = null
|
||||
var finderWindow = null
|
||||
var update = null
|
||||
|
||||
const appRootPath = path.join(process.execPath, '../..')
|
||||
const updateDotExePath = path.join(appRootPath, 'Update.exe')
|
||||
@@ -58,20 +57,19 @@ var handleStartupEvent = function () {
|
||||
switch (squirrelCommand) {
|
||||
case '--squirrel-install':
|
||||
spawnUpdate(['--createShortcut', exeName], function (err) {
|
||||
quitApp()
|
||||
app.quit()
|
||||
})
|
||||
return true
|
||||
case '--squirrel-updated':
|
||||
quitApp()
|
||||
app.quit()
|
||||
return true
|
||||
case '--squirrel-uninstall':
|
||||
spawnUpdate(['--removeShortcut', exeName], function (err) {
|
||||
quitApp()
|
||||
app.quit()
|
||||
})
|
||||
quitApp()
|
||||
return true
|
||||
case '--squirrel-obsolete':
|
||||
quitApp()
|
||||
app.quit()
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -92,24 +90,13 @@ var shouldQuit = app.makeSingleInstance(function(commandLine, workingDirectory)
|
||||
})
|
||||
|
||||
if (shouldQuit) {
|
||||
quitApp()
|
||||
if (mainWindow != null) mainWindow.removeAllListeners()
|
||||
app.quit()
|
||||
return
|
||||
}
|
||||
|
||||
var appQuit = false
|
||||
|
||||
var version = app.getVersion()
|
||||
var versionText = (version == null || version.length === 0) ? 'DEV version' : 'v' + version
|
||||
var versionNotified = false
|
||||
|
||||
function notify (title, body) {
|
||||
if (mainWindow != null) {
|
||||
mainWindow.webContents.send('notify', {
|
||||
title: title,
|
||||
body: body
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
var isUpdateReady = false
|
||||
|
||||
@@ -129,17 +116,15 @@ function checkUpdate () {
|
||||
updater.check((err, status) => {
|
||||
if (err) {
|
||||
var isLatest = err.message === 'There is no newer version.'
|
||||
if (!isLatest && !versionNotified) console.error('Updater error! %s', err.message)
|
||||
if (!isLatest) console.error('Updater error! %s', err.message)
|
||||
}
|
||||
if (!err) {
|
||||
if (status) {
|
||||
notify('Update is available!', 'Download started.. wait for the update ready.')
|
||||
// Download start
|
||||
mainWindow.webContents.send('update-found', 'Update found!')
|
||||
updater.download()
|
||||
} else {
|
||||
if (!versionNotified) {
|
||||
versionNotified = true
|
||||
notify('Latest Build!! ' + versionText, 'Hope you to enjoy our app :D')
|
||||
}
|
||||
// Latest version
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -147,167 +132,73 @@ function checkUpdate () {
|
||||
|
||||
updater.on('update-downloaded', (info) => {
|
||||
if (mainWindow != null) {
|
||||
notify('Ready to Update!', 'Click update button on Main window.')
|
||||
mainWindow.webContents.send('update-available', 'Update available!')
|
||||
mainWindow.webContents.send('update-ready', 'Update available!')
|
||||
isUpdateReady = true
|
||||
}
|
||||
})
|
||||
|
||||
// nodeIpc.config.id = 'node'
|
||||
// nodeIpc.config.retry = 1500
|
||||
// nodeIpc.config.silent = true
|
||||
|
||||
// nodeIpc.serve(
|
||||
// path.join(app.getPath('userData'), 'boost.service'),
|
||||
// function () {
|
||||
// nodeIpc.server.on(
|
||||
// 'connect',
|
||||
// function (socket) {
|
||||
// socket.on('close', function () {
|
||||
// console.log('socket dead')
|
||||
// if (!appQuit) spawnFinder()
|
||||
// })
|
||||
// }
|
||||
// )
|
||||
// nodeIpc.server.on(
|
||||
// 'message',
|
||||
// function (data, socket) {
|
||||
// console.log('>>', data)
|
||||
// handleIpcEvent(data)
|
||||
// }
|
||||
// )
|
||||
// nodeIpc.server.on(
|
||||
// 'error',
|
||||
// function (err) {
|
||||
// console.log('>>', err)
|
||||
// }
|
||||
// )
|
||||
// }
|
||||
// )
|
||||
|
||||
function handleIpcEvent (payload) {
|
||||
switch (payload.type) {
|
||||
case 'show-main-window':
|
||||
switch (process.platform) {
|
||||
case 'darwin':
|
||||
mainWindow.show()
|
||||
case 'win32':
|
||||
mainWindow.minimize()
|
||||
mainWindow.restore()
|
||||
case 'linux':
|
||||
// Do nothing
|
||||
// due to bug of `app.focus()` some desktop Env
|
||||
}
|
||||
break
|
||||
case 'copy-finder':
|
||||
mainWindow.webContents.send('copy-finder')
|
||||
break
|
||||
case 'quit-app':
|
||||
quitApp()
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
function spawnFinder() {
|
||||
// if (process.platform === 'darwin') {
|
||||
// var finderArgv = [path.join(__dirname, 'finder-app.js'), '--finder']
|
||||
// if (_.find(process.argv, a => a === '--hot')) finderArgv.push('--hot')
|
||||
// finderProcess = ChildProcess
|
||||
// .execFile(process.execPath, finderArgv)
|
||||
// }
|
||||
}
|
||||
|
||||
function quitApp () {
|
||||
appQuit = true
|
||||
if (finderProcess) finderProcess.kill()
|
||||
app.quit()
|
||||
if (process.platform === 'darwin') {
|
||||
var finderArgv = [path.join(__dirname, 'finder-app.js'), '--finder']
|
||||
if (_.find(process.argv, a => a === '--hot')) finderArgv.push('--hot')
|
||||
finderProcess = ChildProcess
|
||||
.execFile(process.execPath, finderArgv)
|
||||
}
|
||||
}
|
||||
|
||||
app.on('ready', function () {
|
||||
app.on('before-quit', function () {
|
||||
appQuit = true
|
||||
if (finderProcess) finderProcess.kill()
|
||||
})
|
||||
|
||||
var template = require('./main-menu')
|
||||
if (process.platform === 'win32') {
|
||||
template.unshift({
|
||||
label: 'Boostnote',
|
||||
submenu: [
|
||||
{
|
||||
label: 'Quit',
|
||||
accelerator: 'Control+Q',
|
||||
click: function (e) {
|
||||
quitApp()
|
||||
}
|
||||
}
|
||||
]
|
||||
})
|
||||
}
|
||||
var menu = Menu.buildFromTemplate(template)
|
||||
if (process.platform === 'darwin' || process.platform === 'linux') {
|
||||
Menu.setApplicationMenu(menu)
|
||||
}
|
||||
|
||||
// Check update every 24 hours
|
||||
setInterval(function () {
|
||||
checkUpdate()
|
||||
}, 1000 * 60 * 60 * 24)
|
||||
|
||||
ipc.on('check-update', function (event, msg) {
|
||||
if (update == null) checkUpdate()
|
||||
checkUpdate()
|
||||
})
|
||||
|
||||
ipc.on('update-app', function (event, msg) {
|
||||
ipc.on('update-app-confirm', function (event, msg) {
|
||||
if (isUpdateReady) {
|
||||
appQuit = true
|
||||
mainWindow.removeAllListeners()
|
||||
updater.install()
|
||||
}
|
||||
})
|
||||
|
||||
ipc.on('quit-app-confirm', function () {
|
||||
mainWindow.removeAllListeners()
|
||||
app.quit()
|
||||
})
|
||||
|
||||
checkUpdate()
|
||||
|
||||
mainWindow = require('./main-window')
|
||||
if (process.platform === 'win32' || process.platform === 'linux') {
|
||||
mainWindow.setMenu(menu)
|
||||
}
|
||||
mainWindow.on('close', function (e) {
|
||||
if (appQuit || process.platform != 'darwin') {
|
||||
app.quit()
|
||||
} else {
|
||||
mainWindow.hide()
|
||||
e.preventDefault()
|
||||
}
|
||||
})
|
||||
// switch (process.platform) {
|
||||
// case 'darwin':
|
||||
// spawnFinder()
|
||||
// break
|
||||
// case 'win32':
|
||||
// finderWindow = require('./finder-window')
|
||||
// finderWindow.on('close', function (e) {
|
||||
// if (appQuit) return true
|
||||
// e.preventDefault()
|
||||
// finderWindow.hide()
|
||||
// })
|
||||
// break
|
||||
// case 'linux':
|
||||
// if (process.env.DESKTOP_SESSION === 'cinnamon') {
|
||||
// finderWindow = require('./finder-window')
|
||||
// finderWindow.on('close', function (e) {
|
||||
// if (appQuit) return true
|
||||
// e.preventDefault()
|
||||
// finderWindow.hide()
|
||||
// })
|
||||
// }
|
||||
// // Do nothing.
|
||||
// }
|
||||
|
||||
// nodeIpc.server.start(function (err) {
|
||||
// if (err.code === 'EADDRINUSE') {
|
||||
// notify('Error occurs!', 'You have to kill other Boostnote processes.')
|
||||
// quitApp()
|
||||
// }
|
||||
// })
|
||||
switch (process.platform) {
|
||||
case 'darwin':
|
||||
spawnFinder()
|
||||
break
|
||||
case 'win32':
|
||||
finderWindow = require('./finder-window')
|
||||
finderWindow.on('close', function (e) {
|
||||
e.preventDefault()
|
||||
finderWindow.hide()
|
||||
})
|
||||
break
|
||||
case 'linux':
|
||||
// Finder is available on cinnamon only.
|
||||
if (process.env.DESKTOP_SESSION === 'cinnamon') {
|
||||
finderWindow = require('./finder-window')
|
||||
}
|
||||
}
|
||||
|
||||
require('./hotkey')
|
||||
})
|
||||
|
||||
@@ -7,46 +7,61 @@ const OSX = process.platform === 'darwin'
|
||||
// const WIN = process.platform === 'win32'
|
||||
const LINUX = process.platform === 'linux'
|
||||
|
||||
var boost = {
|
||||
label: 'Boostnote',
|
||||
submenu: [
|
||||
{
|
||||
label: 'About Boostnote',
|
||||
selector: 'orderFrontStandardAboutPanel:'
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
label: 'Hide Boostnote',
|
||||
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',
|
||||
selector: 'terminate:'
|
||||
}
|
||||
]
|
||||
}
|
||||
var boost = OSX
|
||||
? {
|
||||
label: 'Boostnote',
|
||||
submenu: [
|
||||
{
|
||||
label: 'About Boostnote',
|
||||
selector: 'orderFrontStandardAboutPanel:'
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
label: 'Hide Boostnote',
|
||||
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 () {
|
||||
mainWindow.webContents.send('quit-app', {})
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
: {
|
||||
label: 'Boostnote',
|
||||
submenu: [
|
||||
{
|
||||
label: 'Quit',
|
||||
accelerator: 'Command+Q',
|
||||
click: function () {
|
||||
mainWindow.webContents.send('quit-app', {})
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
var file = {
|
||||
label: 'File',
|
||||
submenu: [
|
||||
{
|
||||
label: 'New Post',
|
||||
label: 'New Note',
|
||||
accelerator: OSX ? 'Command + N' : 'Control + N',
|
||||
click: function () {
|
||||
mainWindow.webContents.send('top:new-note')
|
||||
@@ -56,7 +71,7 @@ var file = {
|
||||
type: 'separator'
|
||||
},
|
||||
{
|
||||
label: 'Delete Post',
|
||||
label: 'Delete Note',
|
||||
accelerator: OSX ? 'Control + Backspace' : 'Control + Delete',
|
||||
click: function () {
|
||||
mainWindow.webContents.send('detail:delete')
|
||||
@@ -188,5 +203,5 @@ var help = {
|
||||
module.exports = process.platform === 'darwin'
|
||||
? [boost, file, edit, view, window, help]
|
||||
: process.platform === 'win32'
|
||||
? [file, view, help]
|
||||
? [boost, file, view, help]
|
||||
: [file, view, help]
|
||||
|
||||
@@ -32,6 +32,11 @@ mainWindow.webContents.sendInputEvent({
|
||||
keyCode: '\u0008'
|
||||
})
|
||||
|
||||
mainWindow.on('close', function (e) {
|
||||
mainWindow.hide()
|
||||
e.preventDefault()
|
||||
})
|
||||
|
||||
app.on('activate', function () {
|
||||
if (mainWindow == null) return null
|
||||
mainWindow.show()
|
||||
|
||||
Reference in New Issue
Block a user