mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-14 10:16:26 +00:00
Merge commit '80a0c59f878d899fc21b72f08eb8afeb1970f9ba'
* commit '80a0c59f878d899fc21b72f08eb8afeb1970f9ba': make it as prerelease bump up version MarkdownのCodeblockの行間をひろげる 編集中キャンセルを押しても消える情報があれば警告をだす データ移転バグ修正 最初以降からはUpdaterがエラーをださない。 Stream EPIPEエラー解決、データはこれからJSON保存 notification デバッグ intercept entry point using ipc but not working in production bump up electron version 0.34 -> 0.35.1 MarkdownでEmojiが使える Markdown内のコードにSyntax highlightenをいれる Conflicts: main.js
This commit is contained in:
145
main.js
145
main.js
@@ -1,43 +1,50 @@
|
||||
var app = require('app')
|
||||
var Menu = require('menu')
|
||||
var MenuItem = require('menu-item')
|
||||
var Tray = require('tray')
|
||||
var ipc = require('ipc')
|
||||
var jetpack = require('fs-jetpack')
|
||||
|
||||
require('crash-reporter').start()
|
||||
const electron = require('electron')
|
||||
const app = electron.app
|
||||
const Menu = electron.Menu
|
||||
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 () {
|
||||
// if (process.platform !== 'darwin') app.quit()
|
||||
// })
|
||||
|
||||
var autoUpdater = require('auto-updater')
|
||||
|
||||
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
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
autoUpdater
|
||||
.on('update-downloaded', function (event, releaseNotes, releaseName, releaseDate, updateUrl, quitAndUpdate) {
|
||||
update = quitAndUpdate
|
||||
|
||||
if (mainWindow != null) {
|
||||
mainWindow.webContents.send('notify', 'Ready to Update! ' + releaseName, 'Click update button on Main window.')
|
||||
notify('Ready to Update! ' + releaseName, 'Click update button on Main window.')
|
||||
mainWindow.webContents.send('update-available', 'Update available!')
|
||||
}
|
||||
})
|
||||
.on('error', function (err, message) {
|
||||
console.error(err)
|
||||
if (mainWindow != null && !versionNotified) {
|
||||
mainWindow.webContents.send('notify', 'Updater error!', message)
|
||||
if (!versionNotified) {
|
||||
notify('Updater error!', message)
|
||||
}
|
||||
})
|
||||
// .on('checking-for-update', function () {
|
||||
@@ -45,27 +52,27 @@ autoUpdater
|
||||
// console.log('checking...')
|
||||
// })
|
||||
.on('update-available', function () {
|
||||
if (mainWindow != null) {
|
||||
mainWindow.webContents.send('notify', 'Update is available!', 'Download started.. wait for the update ready.')
|
||||
}
|
||||
notify('Update is available!', 'Download started.. wait for the update ready.')
|
||||
})
|
||||
.on('update-not-available', function () {
|
||||
if (mainWindow != null && !versionNotified) {
|
||||
versionNotified = true
|
||||
mainWindow.webContents.send('notify', 'Latest Build!! ' + versionText, 'Hope you to enjoy our app :D')
|
||||
notify('Latest Build!! ' + versionText, 'Hope you to enjoy our app :D')
|
||||
}
|
||||
})
|
||||
|
||||
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-app/latest?version=' + version)
|
||||
autoUpdater.checkForUpdates()
|
||||
|
||||
// menu start
|
||||
var template = require('./atom-lib/menu-template')
|
||||
var menu = Menu.buildFromTemplate(template)
|
||||
Menu.setApplicationMenu(menu)
|
||||
|
||||
setInterval(function () {
|
||||
if (update == null) autoUpdater.checkForUpdates()
|
||||
@@ -82,28 +89,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
|
||||
@@ -111,6 +96,15 @@ app.on('ready', function () {
|
||||
mainWindow.hide()
|
||||
})
|
||||
mainWindow.webContents.on('did-finish-load', function () {
|
||||
if (finderProcess == null) {
|
||||
finderProcess = ChildProcess
|
||||
.execFile(process.execPath, [path.resolve(__dirname, 'finder.js'), '--finder'])
|
||||
finderProcess.stdout.setEncoding('utf8')
|
||||
finderProcess.stderr.setEncoding('utf8')
|
||||
finderProcess.stdout.on('data', format)
|
||||
finderProcess.stderr.on('data', errorFormat)
|
||||
}
|
||||
|
||||
if (update != null) {
|
||||
mainWindow.webContents.send('update-available', 'whoooooooh!')
|
||||
} else {
|
||||
@@ -118,14 +112,53 @@ 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), 'utf-8')
|
||||
}
|
||||
|
||||
var globalShortcut = require('global-shortcut')
|
||||
var userDataPath = app.getPath('userData')
|
||||
if (!jetpack.cwd(userDataPath).exists('keymap.json')) {
|
||||
jetpack.cwd(userDataPath).file('keymap.json', {content: '{}'})
|
||||
@@ -141,10 +174,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)
|
||||
@@ -160,10 +190,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) {
|
||||
@@ -173,12 +200,4 @@ app.on('ready', function () {
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
global.hideFinder = function () {
|
||||
if (!mainWindow.isVisible()) {
|
||||
Menu.sendActionToFirstResponder('hide:')
|
||||
} else {
|
||||
mainWindow.focus()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user