1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 17:56:25 +00:00

hotkey config

This commit is contained in:
Dick Choi
2016-07-22 08:39:25 +09:00
parent a6e3dbd825
commit 40410eb10f
6 changed files with 43 additions and 74 deletions

View File

@@ -37,7 +37,11 @@ button
font-size 12px font-size 12px
&:focus, &.focus &:focus, &.focus
outline none outline none
&:disabled
cursor not-allowed
input
&:disabled
cursor not-allowed
.noSelect .noSelect
noSelect() noSelect()

View File

@@ -1,6 +1,8 @@
import _ from 'lodash' import _ from 'lodash'
const OSX = global.process.platform === 'darwin' const OSX = global.process.platform === 'darwin'
const electron = require('electron')
const { ipcRenderer } = electron
const defaultConfig = { const defaultConfig = {
zoom: 1, zoom: 1,
@@ -64,8 +66,17 @@ function set (updates) {
let newConfig = Object.assign({}, defaultConfig, currentConfig, updates) let newConfig = Object.assign({}, defaultConfig, currentConfig, updates)
if (!validate(newConfig)) throw new Error('INVALID CONFIG') if (!validate(newConfig)) throw new Error('INVALID CONFIG')
_save(newConfig) _save(newConfig)
ipcRenderer.send('CONFIG_RENEW', {
config: get(),
silent: false
})
} }
ipcRenderer.send('CONFIG_RENEW', {
config: get(),
silent: true
})
export default { export default {
get, get,
set, set,

View File

@@ -25,7 +25,7 @@ class ConfigTab extends React.Component {
this.handleSettingDone = () => { this.handleSettingDone = () => {
this.setState({keymapAlert: { this.setState({keymapAlert: {
type: 'success', type: 'success',
message: 'Successfully done!' message: 'Successfully applied!'
}}) }})
} }
this.handleSettingError = (err) => { this.handleSettingError = (err) => {
@@ -43,20 +43,17 @@ class ConfigTab extends React.Component {
ipc.removeListener('APP_SETTING_ERROR', this.handleSettingError) ipc.removeListener('APP_SETTING_ERROR', this.handleSettingError)
} }
submitHotKey () {
ipc.send('hotkeyUpdated', this.state.keymap)
}
submitConfig () {
ipc.send('configUpdated', this.state.config)
}
handleSaveButtonClick (e) { handleSaveButtonClick (e) {
this.submitHotKey() let newConfig = {
hotkey: this.state.config.hotkey
} }
handleConfigSaveButtonClick (e) { ConfigManager.set(newConfig)
this.submitConfig()
store.dispatch({
type: 'SET_UI',
config: newConfig
})
} }
handleKeyDown (e) { handleKeyDown (e) {
@@ -183,6 +180,7 @@ class ConfigTab extends React.Component {
ref='toggleFinder' ref='toggleFinder'
value={config.hotkey.toggleFinder} value={config.hotkey.toggleFinder}
type='text' type='text'
disabled
/> />
</div> </div>
</div> </div>

View File

@@ -34,6 +34,8 @@
border solid 1px $border-color border solid 1px $border-color
border-radius 2px border-radius 2px
padding 0 5px padding 0 5px
&:disabled
background-color $ui-input--disabled-backgroundColor
.group-checkBoxSection .group-checkBoxSection
margin-bottom 15px margin-bottom 15px
@@ -47,6 +49,12 @@
box-sizing border-box box-sizing border-box
height 40px height 40px
text-align right text-align right
:global
.alert
font-size 12px
line-height 30px
padding 0 5px
float right
.group-control-leftButton .group-control-leftButton
float left float left
colorDefaultButton() colorDefaultButton()

View File

@@ -2,9 +2,9 @@ import React, { PropTypes } from 'react'
import CSSModules from 'browser/lib/CSSModules' import CSSModules from 'browser/lib/CSSModules'
import styles from './InfoTab.styl' import styles from './InfoTab.styl'
const appVersion = global.process.version
const electron = require('electron') const electron = require('electron')
const { shell } = electron const { shell, remote } = electron
const appVersion = remote.app.getVersion()
class InfoTab extends React.Component { class InfoTab extends React.Component {
constructor (props) { constructor (props) {

View File

@@ -1,43 +1,9 @@
const electron = require('electron') const electron = require('electron')
const app = electron.app
const ipc = electron.ipcMain const ipc = electron.ipcMain
const Menu = electron.Menu const Menu = electron.Menu
const globalShortcut = electron.globalShortcut const globalShortcut = electron.globalShortcut
const jetpack = require('fs-jetpack')
const mainWindow = require('./main-window') const mainWindow = require('./main-window')
const nodeIpc = require('@rokt33r/node-ipc') const nodeIpc = require('@rokt33r/node-ipc')
const _ = require('lodash')
const OSX = global.process.platform === 'darwin'
const defaultKeymap = {
toggleFinder: OSX ? 'Cmd + Alt + S' : 'Super + Alt + S',
toggleMain: OSX ? 'Cmd + Alt + L' : 'Super + Alt + E'
}
const keymapFilename = 'keymap.json'
var userDataPath = app.getPath('userData')
function getKeymap () {
var userDataPath = app.getPath('userData')
if (jetpack.cwd(userDataPath).exists(keymapFilename)) {
try {
return JSON.parse(jetpack.cwd(userDataPath).read(keymapFilename, 'utf-8'))
} catch (err) {}
}
return {}
}
function saveKeymap () {
var content
try {
content = JSON.stringify(global.keymap)
} catch (e) {
global.keymap = {}
content = JSON.stringify(global.keymap)
}
jetpack.cwd(userDataPath).file(keymapFilename, { content })
}
function emitToFinder (type, data) { function emitToFinder (type, data) {
var payload = { var payload = {
@@ -71,31 +37,22 @@ function toggleMain () {
} }
} }
// Init ipc.on('CONFIG_RENEW', (e, payload) => {
global.keymap = Object.assign({}, defaultKeymap, getKeymap()) globalShortcut.unregisterAll()
var { config } = payload
function registerKey (name, callback) {
if (_.isString(global.keymap[name]) && global.keymap[name].trim().length > 0) {
globalShortcut.register(global.keymap[name], callback)
}
}
function registerAllKeys (broadcast) {
if (broadcast == null) broadcast = true
var errors = [] var errors = []
try { try {
registerKey('toggleFinder', toggleFinder) globalShortcut.register(config.hotkey.toggleFinder, toggleFinder)
} catch (err) { } catch (err) {
errors.push('toggleFinder') errors.push('toggleFinder')
} }
try { try {
registerKey('toggleMain', toggleMain) globalShortcut.register(config.hotkey.toggleMain, toggleMain)
} catch (err) { } catch (err) {
errors.push('toggleMain') errors.push('toggleMain')
} }
if (!config.silent) {
if (broadcast) {
if (errors.length === 0) { if (errors.length === 0) {
mainWindow.webContents.send('APP_SETTING_DONE', {}) mainWindow.webContents.send('APP_SETTING_DONE', {})
} else { } else {
@@ -104,13 +61,4 @@ function registerAllKeys (broadcast) {
}) })
} }
} }
}
registerAllKeys(false)
ipc.on('hotkeyUpdated', function (event, newKeymap) {
global.keymap = Object.assign({}, defaultKeymap, global.keymap, newKeymap)
saveKeymap()
globalShortcut.unregisterAll()
registerAllKeys()
}) })