mirror of
https://github.com/BoostIo/Boostnote
synced 2026-01-28 08:07:16 +00:00
Finder
This commit is contained in:
@@ -12,6 +12,7 @@ import _ from 'lodash'
|
||||
import ConfigManager from 'browser/main/lib/ConfigManager'
|
||||
import modal from 'browser/main/lib/modal'
|
||||
import InitModal from 'browser/main/modals/InitModal'
|
||||
import ipc from 'browser/main/lib/ipc'
|
||||
|
||||
class Main extends React.Component {
|
||||
constructor (props) {
|
||||
|
||||
@@ -58,7 +58,7 @@
|
||||
.folderList-item
|
||||
display block
|
||||
width 100%
|
||||
height 3 0px
|
||||
height 30px
|
||||
background-color transparent
|
||||
color $ui-inactive-text-color
|
||||
padding 0
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
position absolute
|
||||
right 60px
|
||||
height 24px
|
||||
width 125px
|
||||
border-width 0 0 0 1px
|
||||
border-style solid
|
||||
border-color $ui-borderColor
|
||||
|
||||
@@ -15,13 +15,17 @@ class StatusBar extends React.Component {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
updateAvailable: false
|
||||
updateReady: false
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount () {
|
||||
ipc.on('update-available', function (message) {
|
||||
this.setState({updateAvailable: true})
|
||||
ipc.on('update-ready', function (message) {
|
||||
this.setState({
|
||||
updateReady: true
|
||||
}, () => {
|
||||
this.updateApp()
|
||||
})
|
||||
}.bind(this))
|
||||
}
|
||||
|
||||
@@ -34,7 +38,7 @@ class StatusBar extends React.Component {
|
||||
})
|
||||
|
||||
if (index === 0) {
|
||||
ipc.send('update-app', 'Deal with it.')
|
||||
remote.getCurrentWindow().webContents.send('update-app')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,9 +72,9 @@ class StatusBar extends React.Component {
|
||||
styleName='root'
|
||||
>
|
||||
<div styleName='pathname'>{location.pathname + location.search}</div>
|
||||
{this.state.updateAvailable
|
||||
{this.state.updateReady
|
||||
? <button onClick={this.updateApp} styleName='update'>
|
||||
<i styleName='update-icon' className='fa fa-cloud-download'/> Update is available!
|
||||
<i styleName='update-icon' className='fa fa-cloud-download'/> Update is ready!
|
||||
</button>
|
||||
: null
|
||||
}
|
||||
|
||||
@@ -10,18 +10,9 @@ import { syncHistoryWithStore } from 'react-router-redux'
|
||||
|
||||
const electron = require('electron')
|
||||
const ipc = electron.ipcRenderer
|
||||
const path = require('path')
|
||||
const remote = electron.remote
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
window.addEventListener('keydown', function (e) {
|
||||
if (e.keyCode === 73 && e.metaKey && e.altKey) {
|
||||
remote.getCurrentWindow().toggleDevTools()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
activityRecord.init()
|
||||
ipc.send('check-update', 'check-update')
|
||||
window.addEventListener('online', function () {
|
||||
ipc.send('check-update', 'check-update')
|
||||
})
|
||||
@@ -35,28 +26,6 @@ document.addEventListener('dragover', function (e) {
|
||||
e.stopPropagation()
|
||||
})
|
||||
|
||||
function notify (title, options) {
|
||||
if (process.platform === 'win32') {
|
||||
options.icon = path.join('file://', global.__dirname, '../../resources/app.png')
|
||||
options.silent = false
|
||||
}
|
||||
console.log(options)
|
||||
return new window.Notification(title, options)
|
||||
}
|
||||
|
||||
ipc.on('notify', function (e, payload) {
|
||||
notify(payload.title, {
|
||||
body: payload.body
|
||||
})
|
||||
})
|
||||
|
||||
ipc.on('copy-finder', function () {
|
||||
activityRecord.emit('FINDER_COPY')
|
||||
})
|
||||
ipc.on('open-finder', function () {
|
||||
activityRecord.emit('FINDER_OPEN')
|
||||
})
|
||||
|
||||
let el = document.getElementById('content')
|
||||
const history = syncHistoryWithStore(hashHistory, store)
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import _ from 'lodash'
|
||||
|
||||
const OSX = global.process.platform === 'darwin'
|
||||
const electron = require('electron')
|
||||
const { ipcRenderer } = electron
|
||||
const { remote } = electron
|
||||
|
||||
const defaultConfig = {
|
||||
zoom: 1,
|
||||
@@ -66,17 +66,13 @@ function set (updates) {
|
||||
let newConfig = Object.assign({}, defaultConfig, currentConfig, updates)
|
||||
if (!validate(newConfig)) throw new Error('INVALID CONFIG')
|
||||
_save(newConfig)
|
||||
ipcRenderer.send('CONFIG_RENEW', {
|
||||
|
||||
remote.getCurrentWindow().webContents.send('config-renew', {
|
||||
config: get(),
|
||||
silent: false
|
||||
})
|
||||
}
|
||||
|
||||
ipcRenderer.send('CONFIG_RENEW', {
|
||||
config: get(),
|
||||
silent: true
|
||||
})
|
||||
|
||||
export default {
|
||||
get,
|
||||
set,
|
||||
|
||||
138
browser/main/lib/ipc.js
Normal file
138
browser/main/lib/ipc.js
Normal file
@@ -0,0 +1,138 @@
|
||||
import store from 'browser/main/store'
|
||||
import ConfigManager from 'browser/main/lib/ConfigManager'
|
||||
|
||||
const nodeIpc = require('node-ipc')
|
||||
const { remote, ipcRenderer } = require('electron')
|
||||
const { app, Menu } = remote
|
||||
const path = require('path')
|
||||
|
||||
nodeIpc.config.id = 'node'
|
||||
nodeIpc.config.retry = 1500
|
||||
nodeIpc.config.silent = true
|
||||
console.log('Initializing IPC Server')
|
||||
|
||||
// TODO: IPC SERVER WILL BE MOVED TO MAIN PROCESS FROM MAIN WINDOW PROCESS(RENDERER)
|
||||
nodeIpc.serve(
|
||||
path.join(app.getPath('userData'), 'boostnote.service'),
|
||||
function () {
|
||||
console.log('IPC Server Started')
|
||||
ipcRenderer.on('open-finder', function () {
|
||||
console.log('Open finder')
|
||||
nodeIpc.server.broadcast('open-finder')
|
||||
})
|
||||
|
||||
/** Quit Sequence
|
||||
1. `quit-app` Main process -> Main window by Electron IPC
|
||||
2. `quit-finder-app` Main window -> Finder window by Node IPC(socket)
|
||||
3. Finder window (and Finder main process: OSX only) killed by remote API
|
||||
4. `quit-finder-app-confirm` Finder window -> Main window by NodeIPC
|
||||
5. `quit-app-confirm` Main window -> Main process by Electron IPC
|
||||
6. Main process discard close preventer and terminate Main window and itself.
|
||||
|
||||
If the platform is a linux without cinnamon, the app will skip 2.-4. because it doesn't launch finder window.
|
||||
`quit-app` will fires directly `quit-app-confirm`.
|
||||
*/
|
||||
ipcRenderer.on('quit-app', function () {
|
||||
// Finder app exists only in the linux with cinnamon.
|
||||
if (global.process.env.platform === 'linux' && global.process.env.DESKTOP_SESSION !== 'cinnamon') {
|
||||
ipcRenderer.send('quit-app-confirm')
|
||||
return
|
||||
}
|
||||
let confirmHandler = function () {
|
||||
ipcRenderer.send('quit-app-confirm')
|
||||
}
|
||||
nodeIpc.server.on('quit-finder-app-confirm', confirmHandler)
|
||||
setTimeout(() => {
|
||||
nodeIpc.server.removeListener('quit-finder-app-confirm', confirmHandler)
|
||||
}, 1000)
|
||||
nodeIpc.server.broadcast('quit-finder-app')
|
||||
})
|
||||
|
||||
/** Update Sequence
|
||||
1. `update-ready` Main process -> Main window by Electron IPC
|
||||
2. `update-app` Main window -> Main window by Electron IPC
|
||||
3. `quit-finder-app` Main window -> Finder window by Node IPC
|
||||
4. Finder window (and Finder main process: OSX only) killed by remote API
|
||||
5. `quit-finder-app-confirm` Finder window -> Main window by NodeIPC
|
||||
6. `update-app-confirm` Main window -> Main process by Electron IPC
|
||||
7. Main process discard close preventer and start updating.
|
||||
|
||||
Handlers of 1. and 2. can be found in StatusBar component.
|
||||
*/
|
||||
ipcRenderer.on('update-app', function () {
|
||||
// Linux app doesn't support auto updater
|
||||
if (global.process.env.platform === 'linux') {
|
||||
return
|
||||
}
|
||||
let confirmHandler = function () {
|
||||
ipcRenderer.send('update-app-confirm')
|
||||
}
|
||||
nodeIpc.server.on('quit-finder-app-confirm', confirmHandler)
|
||||
setTimeout(() => {
|
||||
nodeIpc.server.removeListener('quit-finder-app-confirm', confirmHandler)
|
||||
}, 1000)
|
||||
nodeIpc.server.broadcast('quit-finder-app')
|
||||
})
|
||||
|
||||
ipcRenderer.on('update-found', function () {
|
||||
console.log('Update found')
|
||||
})
|
||||
|
||||
let config = ConfigManager.get()
|
||||
nodeIpc.server.broadcast('config-renew', config)
|
||||
ipcRenderer.send('config-renew', {
|
||||
config: config,
|
||||
silent: true
|
||||
})
|
||||
ipcRenderer.on('config-renew', function (e, data) {
|
||||
nodeIpc.server.broadcast('config-renew', data.config)
|
||||
ipcRenderer.send('config-renew', data)
|
||||
})
|
||||
|
||||
nodeIpc.server.on('open-main-from-finder', function () {
|
||||
let mainWindow = remote.getCurrentWindow()
|
||||
console.log('open main from finder')
|
||||
if (mainWindow.isFocused()) {
|
||||
if (global.process.platform === 'darwin') {
|
||||
Menu.sendActionToFirstResponder('hide:')
|
||||
} else {
|
||||
mainWindow.minimize()
|
||||
}
|
||||
} else {
|
||||
if (global.process.platform === 'darwin') {
|
||||
mainWindow.show()
|
||||
} else {
|
||||
mainWindow.minimize()
|
||||
mainWindow.restore()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
nodeIpc.server.on('quit-from-finder', function () {
|
||||
ipcRenderer.send('quit-app-confirm')
|
||||
})
|
||||
|
||||
nodeIpc.server.on('connect', function (socket) {
|
||||
console.log('connected')
|
||||
socket.on('close', function () {
|
||||
console.log('socket dead')
|
||||
})
|
||||
})
|
||||
nodeIpc.server.on('error', function (err) {
|
||||
console.error('Node IPC error', err)
|
||||
})
|
||||
nodeIpc.server.on('request-data', function (data, socket) {
|
||||
let state = store.getState()
|
||||
nodeIpc.server.broadcast('throttle-data', {
|
||||
storages: state.storages,
|
||||
notes: state.notes
|
||||
})
|
||||
})
|
||||
}
|
||||
)
|
||||
const ipc = {
|
||||
|
||||
}
|
||||
|
||||
nodeIpc.server.start()
|
||||
module.exports = ipc
|
||||
11
browser/main/lib/notify.js
Normal file
11
browser/main/lib/notify.js
Normal file
@@ -0,0 +1,11 @@
|
||||
const path = require('path')
|
||||
|
||||
function notify (title, options) {
|
||||
if (process.platform === 'win32') {
|
||||
options.icon = path.join('file://', global.__dirname, '../../resources/app.png')
|
||||
options.silent = false
|
||||
}
|
||||
return new window.Notification(title, options)
|
||||
}
|
||||
|
||||
export default notify
|
||||
@@ -180,7 +180,6 @@ class ConfigTab extends React.Component {
|
||||
ref='toggleFinder'
|
||||
value={config.hotkey.toggleFinder}
|
||||
type='text'
|
||||
disabled
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user