mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
using ipc but not working in production
This commit is contained in:
@@ -16,11 +16,8 @@ export function searchArticle (input) {
|
||||
}
|
||||
}
|
||||
|
||||
export function refreshData () {
|
||||
export function refreshData (data) {
|
||||
console.log('refreshing data')
|
||||
let data = JSON.parse(localStorage.getItem('local'))
|
||||
if (data == null) return null
|
||||
|
||||
let { folders, articles } = data
|
||||
|
||||
return {
|
||||
|
||||
@@ -8,10 +8,10 @@ import FinderList from './FinderList'
|
||||
import FinderDetail from './FinderDetail'
|
||||
import { selectArticle, searchArticle, refreshData } from './actions'
|
||||
import _ from 'lodash'
|
||||
import activityRecord from 'boost/activityRecord'
|
||||
|
||||
const electron = require('electron')
|
||||
const { remote, clipboard } = electron
|
||||
const ipc = electron.ipcRenderer
|
||||
|
||||
var hideFinder = remote.getGlobal('hideFinder')
|
||||
|
||||
@@ -63,7 +63,6 @@ class FinderMain extends React.Component {
|
||||
saveToClipboard () {
|
||||
let { activeArticle } = this.props
|
||||
clipboard.writeText(activeArticle.content)
|
||||
activityRecord.emit('FINDER_COPY')
|
||||
|
||||
notify('Saved to Clipboard!', {
|
||||
body: 'Paste it wherever you want!'
|
||||
@@ -214,10 +213,13 @@ var Finder = connect(remap)(FinderMain)
|
||||
var store = createStore(reducer)
|
||||
|
||||
window.onfocus = e => {
|
||||
store.dispatch(refreshData())
|
||||
activityRecord.emit('FINDER_OPEN')
|
||||
ipc.send('request-data')
|
||||
}
|
||||
|
||||
ipc.on('refresh-data', function (e, data) {
|
||||
store.dispatch(refreshData(data))
|
||||
})
|
||||
|
||||
ReactDOM.render((
|
||||
<Provider store={store}>
|
||||
<Finder/>
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import { combineReducers } from 'redux'
|
||||
import { SELECT_ARTICLE, SEARCH_ARTICLE, REFRESH_DATA } from './actions'
|
||||
|
||||
let data = JSON.parse(localStorage.getItem('local'))
|
||||
|
||||
let initialArticles = data != null ? data.articles : []
|
||||
let initialFolders = data != null ? data.folders : []
|
||||
let initialArticles = []
|
||||
let initialFolders = []
|
||||
let initialStatus = {
|
||||
articleKey: null,
|
||||
search: ''
|
||||
|
||||
@@ -11,6 +11,7 @@ require('../styles/main/index.styl')
|
||||
import { openModal } from 'boost/modal'
|
||||
import Tutorial from 'boost/components/modal/Tutorial'
|
||||
import activityRecord from 'boost/activityRecord'
|
||||
import dataStore from 'boost/dataStore'
|
||||
const electron = require('electron')
|
||||
const ipc = electron.ipcRenderer
|
||||
|
||||
@@ -29,6 +30,10 @@ ipc.on('notify', function (title, message) {
|
||||
})
|
||||
})
|
||||
|
||||
ipc.on('request-data', function () {
|
||||
ipc.send('refresh-data', dataStore.getData())
|
||||
})
|
||||
|
||||
let routes = (
|
||||
<Route path='/' component={MainPage}>
|
||||
<IndexRoute name='home' component={HomePage}/>
|
||||
|
||||
82
finder.js
Executable file
82
finder.js
Executable file
@@ -0,0 +1,82 @@
|
||||
const electron = require('electron')
|
||||
const app = electron.app
|
||||
const Tray = electron.Tray
|
||||
const Menu = electron.Menu
|
||||
const MenuItem = electron.MenuItem
|
||||
const ipc = electron.ipcMain
|
||||
|
||||
process.stdin.setEncoding('utf8')
|
||||
|
||||
console.log = function () {
|
||||
process.stdout.write(JSON.stringify({
|
||||
type: 'log',
|
||||
data: JSON.stringify(Array.prototype.slice.call(arguments).join(' '))
|
||||
}))
|
||||
}
|
||||
|
||||
function emit (type, data) {
|
||||
process.stdout.write(JSON.stringify({
|
||||
type: type,
|
||||
data: JSON.stringify(data)
|
||||
}))
|
||||
}
|
||||
|
||||
var finderWindow
|
||||
app.on('ready', function () {
|
||||
app.dock.hide()
|
||||
var appIcon = new Tray(__dirname + '/resources/tray-icon.png')
|
||||
appIcon.setToolTip('Boost')
|
||||
|
||||
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',
|
||||
click: function () {
|
||||
finderWindow.show()
|
||||
}
|
||||
}))
|
||||
trayMenu.append(new MenuItem({
|
||||
label: 'Quit',
|
||||
click: function () {
|
||||
emit('quit-app')
|
||||
}
|
||||
}))
|
||||
appIcon.setContextMenu(trayMenu)
|
||||
|
||||
ipc.on('request-data', function () {
|
||||
emit('request-data')
|
||||
})
|
||||
|
||||
process.stdin.on('data', function (payload) {
|
||||
try {
|
||||
payload = JSON.parse(payload)
|
||||
} catch (e) {
|
||||
console.log('Not parsable payload : ', payload)
|
||||
return
|
||||
}
|
||||
console.log('from main >> ', payload.type)
|
||||
switch (payload.type) {
|
||||
case 'open-finder':
|
||||
finderWindow.show()
|
||||
break
|
||||
case 'refresh-data':
|
||||
finderWindow.webContents.send('refresh-data', payload.data)
|
||||
break
|
||||
}
|
||||
})
|
||||
|
||||
emit('request-data')
|
||||
})
|
||||
|
||||
global.hideFinder = function () {
|
||||
Menu.sendActionToFirstResponder('hide:')
|
||||
}
|
||||
})
|
||||
|
||||
113
main.js
113
main.js
@@ -1,19 +1,16 @@
|
||||
const electron = require('electron')
|
||||
const app = electron.app
|
||||
const Menu = electron.Menu
|
||||
const MenuItem = electron.MenuItem
|
||||
const Tray = electron.Tray
|
||||
const ipc = electron.ipcMain
|
||||
const globalShortcut = electron.globalShortcut
|
||||
const autoUpdater = electron.autoUpdater
|
||||
const jetpack = require('fs-jetpack')
|
||||
const path = require('path')
|
||||
const ChildProcess = require('child_process')
|
||||
electron.crashReporter.start()
|
||||
|
||||
var mainWindow = null
|
||||
var appIcon = null
|
||||
var menu = null
|
||||
var finderWindow = null
|
||||
|
||||
var finderProcess
|
||||
var update = null
|
||||
|
||||
// app.on('window-all-closed', function () {
|
||||
@@ -58,12 +55,15 @@ autoUpdater
|
||||
|
||||
app.on('ready', function () {
|
||||
app.on('before-quit', function () {
|
||||
if (finderProcess) finderProcess.kill()
|
||||
appQuit = true
|
||||
})
|
||||
console.log('Version ' + version)
|
||||
autoUpdater.setFeedUrl('http://orbital.b00st.io/rokt33r/boost-dev/latest?version=' + version)
|
||||
// menu start
|
||||
|
||||
autoUpdater.setFeedURL('http://orbital.b00st.io/rokt33r/boost-dev/latest?version=' + version)
|
||||
|
||||
var template = require('./atom-lib/menu-template')
|
||||
var menu = Menu.buildFromTemplate(template)
|
||||
Menu.setApplicationMenu(menu)
|
||||
|
||||
setInterval(function () {
|
||||
if (update == null) autoUpdater.checkForUpdates()
|
||||
@@ -80,28 +80,6 @@ app.on('ready', function () {
|
||||
}
|
||||
})
|
||||
|
||||
menu = Menu.buildFromTemplate(template)
|
||||
|
||||
Menu.setApplicationMenu(menu)
|
||||
// menu end
|
||||
appIcon = new Tray(__dirname + '/resources/tray-icon.png')
|
||||
appIcon.setToolTip('Boost')
|
||||
|
||||
var trayMenu = new Menu()
|
||||
trayMenu.append(new MenuItem({
|
||||
label: 'Open main window',
|
||||
click: function () {
|
||||
if (mainWindow != null) mainWindow.show()
|
||||
}
|
||||
}))
|
||||
trayMenu.append(new MenuItem({
|
||||
label: 'Quit',
|
||||
click: function () {
|
||||
app.quit()
|
||||
}
|
||||
}))
|
||||
appIcon.setContextMenu(trayMenu)
|
||||
|
||||
mainWindow = require('./atom-lib/main-window')
|
||||
mainWindow.on('close', function (e) {
|
||||
if (appQuit) return true
|
||||
@@ -109,6 +87,13 @@ app.on('ready', function () {
|
||||
mainWindow.hide()
|
||||
})
|
||||
mainWindow.webContents.on('did-finish-load', function () {
|
||||
finderProcess = ChildProcess
|
||||
.execFile(process.execPath, [path.resolve(__dirname, 'finder.js')], {
|
||||
stdio: 'pipe'
|
||||
})
|
||||
finderProcess.stdout.on('data', format)
|
||||
finderProcess.stderr.on('data', errorFormat)
|
||||
|
||||
if (update != null) {
|
||||
mainWindow.webContents.send('update-available', 'whoooooooh!')
|
||||
} else {
|
||||
@@ -116,12 +101,56 @@ app.on('ready', function () {
|
||||
}
|
||||
})
|
||||
|
||||
app.on('activate-with-no-open-windows', function () {
|
||||
app.on('activate', function () {
|
||||
if (mainWindow == null) return null
|
||||
mainWindow.show()
|
||||
})
|
||||
|
||||
finderWindow = require('./atom-lib/finder-window')
|
||||
function format (payload) {
|
||||
// console.log('from finder >> ', payload)
|
||||
try {
|
||||
payload = JSON.parse(payload)
|
||||
} catch (e) {
|
||||
console.log('Not parsable payload : ', payload)
|
||||
return
|
||||
}
|
||||
switch (payload.type) {
|
||||
case 'log':
|
||||
console.log('FINDER(stdout): ' + payload.data)
|
||||
break
|
||||
case 'show-main-window':
|
||||
if (mainWindow != null) {
|
||||
mainWindow.show()
|
||||
}
|
||||
break
|
||||
case 'request-data':
|
||||
mainWindow.webContents.send('request-data')
|
||||
break
|
||||
case 'quit-app':
|
||||
appQuit = true
|
||||
app.quit()
|
||||
break
|
||||
}
|
||||
}
|
||||
function errorFormat (output) {
|
||||
console.error('FINDER(stderr):' + output)
|
||||
}
|
||||
|
||||
function emitToFinder (type, data) {
|
||||
if (!finderProcess) {
|
||||
console.log('finder process is not ready')
|
||||
return
|
||||
}
|
||||
var payload = {
|
||||
type: type,
|
||||
data: data
|
||||
}
|
||||
finderProcess.stdin.write(JSON.stringify(payload))
|
||||
}
|
||||
|
||||
ipc.on('refresh-data', function (e, data) {
|
||||
emitToFinder('refresh-data', data)
|
||||
})
|
||||
|
||||
var userDataPath = app.getPath('userData')
|
||||
if (!jetpack.cwd(userDataPath).exists('keymap.json')) {
|
||||
@@ -138,10 +167,7 @@ app.on('ready', function () {
|
||||
|
||||
try {
|
||||
globalShortcut.register(toggleFinderKey, function () {
|
||||
if (mainWindow != null && !mainWindow.isFocused()) {
|
||||
mainWindow.hide()
|
||||
}
|
||||
finderWindow.show()
|
||||
emitToFinder('open-finder')
|
||||
})
|
||||
} catch (err) {
|
||||
console.log(err.name)
|
||||
@@ -157,10 +183,7 @@ app.on('ready', function () {
|
||||
var toggleFinderKey = global.keymap.toggleFinder != null ? global.keymap.toggleFinder : 'ctrl+tab+shift'
|
||||
try {
|
||||
globalShortcut.register(toggleFinderKey, function () {
|
||||
if (mainWindow != null && !mainWindow.isFocused()) {
|
||||
mainWindow.hide()
|
||||
}
|
||||
finderWindow.show()
|
||||
emitToFinder('open-finder')
|
||||
})
|
||||
mainWindow.webContents.send('APP_SETTING_DONE', {})
|
||||
} catch (err) {
|
||||
@@ -170,12 +193,4 @@ app.on('ready', function () {
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
global.hideFinder = function () {
|
||||
if (!mainWindow.isVisible()) {
|
||||
Menu.sendActionToFirstResponder('hide:')
|
||||
} else {
|
||||
mainWindow.focus()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user