mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 09:46:22 +00:00
hotkey config
This commit is contained in:
@@ -37,7 +37,11 @@ button
|
||||
font-size 12px
|
||||
&:focus, &.focus
|
||||
outline none
|
||||
|
||||
&:disabled
|
||||
cursor not-allowed
|
||||
input
|
||||
&:disabled
|
||||
cursor not-allowed
|
||||
.noSelect
|
||||
noSelect()
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import _ from 'lodash'
|
||||
|
||||
const OSX = global.process.platform === 'darwin'
|
||||
const electron = require('electron')
|
||||
const { ipcRenderer } = electron
|
||||
|
||||
const defaultConfig = {
|
||||
zoom: 1,
|
||||
@@ -64,8 +66,17 @@ function set (updates) {
|
||||
let newConfig = Object.assign({}, defaultConfig, currentConfig, updates)
|
||||
if (!validate(newConfig)) throw new Error('INVALID CONFIG')
|
||||
_save(newConfig)
|
||||
ipcRenderer.send('CONFIG_RENEW', {
|
||||
config: get(),
|
||||
silent: false
|
||||
})
|
||||
}
|
||||
|
||||
ipcRenderer.send('CONFIG_RENEW', {
|
||||
config: get(),
|
||||
silent: true
|
||||
})
|
||||
|
||||
export default {
|
||||
get,
|
||||
set,
|
||||
|
||||
@@ -25,7 +25,7 @@ class ConfigTab extends React.Component {
|
||||
this.handleSettingDone = () => {
|
||||
this.setState({keymapAlert: {
|
||||
type: 'success',
|
||||
message: 'Successfully done!'
|
||||
message: 'Successfully applied!'
|
||||
}})
|
||||
}
|
||||
this.handleSettingError = (err) => {
|
||||
@@ -43,20 +43,17 @@ class ConfigTab extends React.Component {
|
||||
ipc.removeListener('APP_SETTING_ERROR', this.handleSettingError)
|
||||
}
|
||||
|
||||
submitHotKey () {
|
||||
ipc.send('hotkeyUpdated', this.state.keymap)
|
||||
}
|
||||
|
||||
submitConfig () {
|
||||
ipc.send('configUpdated', this.state.config)
|
||||
}
|
||||
|
||||
handleSaveButtonClick (e) {
|
||||
this.submitHotKey()
|
||||
}
|
||||
let newConfig = {
|
||||
hotkey: this.state.config.hotkey
|
||||
}
|
||||
|
||||
handleConfigSaveButtonClick (e) {
|
||||
this.submitConfig()
|
||||
ConfigManager.set(newConfig)
|
||||
|
||||
store.dispatch({
|
||||
type: 'SET_UI',
|
||||
config: newConfig
|
||||
})
|
||||
}
|
||||
|
||||
handleKeyDown (e) {
|
||||
@@ -183,6 +180,7 @@ class ConfigTab extends React.Component {
|
||||
ref='toggleFinder'
|
||||
value={config.hotkey.toggleFinder}
|
||||
type='text'
|
||||
disabled
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -34,6 +34,8 @@
|
||||
border solid 1px $border-color
|
||||
border-radius 2px
|
||||
padding 0 5px
|
||||
&:disabled
|
||||
background-color $ui-input--disabled-backgroundColor
|
||||
|
||||
.group-checkBoxSection
|
||||
margin-bottom 15px
|
||||
@@ -47,6 +49,12 @@
|
||||
box-sizing border-box
|
||||
height 40px
|
||||
text-align right
|
||||
:global
|
||||
.alert
|
||||
font-size 12px
|
||||
line-height 30px
|
||||
padding 0 5px
|
||||
float right
|
||||
.group-control-leftButton
|
||||
float left
|
||||
colorDefaultButton()
|
||||
|
||||
@@ -2,9 +2,9 @@ import React, { PropTypes } from 'react'
|
||||
import CSSModules from 'browser/lib/CSSModules'
|
||||
import styles from './InfoTab.styl'
|
||||
|
||||
const appVersion = global.process.version
|
||||
const electron = require('electron')
|
||||
const { shell } = electron
|
||||
const { shell, remote } = electron
|
||||
const appVersion = remote.app.getVersion()
|
||||
|
||||
class InfoTab extends React.Component {
|
||||
constructor (props) {
|
||||
|
||||
@@ -1,43 +1,9 @@
|
||||
const electron = require('electron')
|
||||
const app = electron.app
|
||||
const ipc = electron.ipcMain
|
||||
const Menu = electron.Menu
|
||||
const globalShortcut = electron.globalShortcut
|
||||
const jetpack = require('fs-jetpack')
|
||||
const mainWindow = require('./main-window')
|
||||
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) {
|
||||
var payload = {
|
||||
@@ -71,31 +37,22 @@ function toggleMain () {
|
||||
}
|
||||
}
|
||||
|
||||
// Init
|
||||
global.keymap = Object.assign({}, defaultKeymap, getKeymap())
|
||||
|
||||
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
|
||||
ipc.on('CONFIG_RENEW', (e, payload) => {
|
||||
globalShortcut.unregisterAll()
|
||||
var { config } = payload
|
||||
|
||||
var errors = []
|
||||
try {
|
||||
registerKey('toggleFinder', toggleFinder)
|
||||
globalShortcut.register(config.hotkey.toggleFinder, toggleFinder)
|
||||
} catch (err) {
|
||||
errors.push('toggleFinder')
|
||||
}
|
||||
try {
|
||||
registerKey('toggleMain', toggleMain)
|
||||
globalShortcut.register(config.hotkey.toggleMain, toggleMain)
|
||||
} catch (err) {
|
||||
errors.push('toggleMain')
|
||||
}
|
||||
|
||||
if (broadcast) {
|
||||
if (!config.silent) {
|
||||
if (errors.length === 0) {
|
||||
mainWindow.webContents.send('APP_SETTING_DONE', {})
|
||||
} 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()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user