Skip to content

Commit

Permalink
Windows (muan#14): Migrated to Windows friendly keyboard shortcuts, c…
Browse files Browse the repository at this point in the history
…orrected systray transparency (on Win it can be dark) and added ability to center window on when loading.
  • Loading branch information
patricknelson committed Feb 18, 2017
1 parent a85ac1f commit 3bb7fd1
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 16 deletions.
Binary file modified app/Icon-Template.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified app/Icon-Template@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 33 additions & 10 deletions app/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@ var ipc = require('electron').ipcRenderer

var defaultPreference = {
'open-window-shortcut': 'ctrl+shift+space',
'emoji-size': '20',
'open-at-login': false
'emoji-size': '40',
'window-position': 'topRight',
'open-at-login': false,
}

var preferenceNames = {
'open-window-shortcut': 'Mojibar shortcut',
'emoji-size': 'Emoji font size',
'open-at-login': 'Start Mojibar at login'
'emoji-size': 'Emoji size',
'window-position': 'Window Position',
'open-at-login': 'Start Mojibar at login',
}

var applyPreferences = function (preference, initialization) {
window.localStorage.setItem('preference', JSON.stringify(preference))

ipc.send('update-preference', preference, initialization)
var style = document.createElement('style')
style.innerText = '.emoji { font-size: ' + preference['emoji-size'] + 'px; width: ' + (Number(preference['emoji-size']) + 20) + 'px; height: ' + (Number(preference['emoji-size']) + 20) + 'px; }'
style.innerText = '.emoji { width: ' + preference['emoji-size'] + 'px; height: ' + preference['emoji-size'] + 'px; }'
document.body.appendChild(style)
}

Expand Down Expand Up @@ -71,16 +73,37 @@ var togglePreferencePanel = function () {
panel.id = 'js-preference-panel'
var html = '<form>'
Object.keys(preferenceNames).forEach(function (key) {
var prefTitle = preferenceNames[key]
var prefVal = preference[key]
html += '<div class="pref-item"><label for="' + key + '">'
if (typeof preference[key] === 'boolean') {
if (typeof defaultPreference[key] === 'boolean') {
html += '<label>'
html += '<input type="checkbox" id="' + key + '"' + (preference[key] ? 'checked' : '') + '>'
html += preferenceNames[key]
html += '<input type="checkbox" id="' + key + '"' + (prefVal ? 'checked' : '') + '>'
html += prefTitle
html += '</label>'
} else if (key == 'window-position') {
let positionOptions = {
'topLeft': 'Top Left',
'topRight': 'Top Right',
'bottomLeft': 'Bottom Left',
'bottomRight': 'Bottom Right',
'topCenter': 'Top Center',
'bottomCenter': 'Bottom Center',
'center': 'Center'
};
html += '<label for="' + key + '">'
html += prefTitle
html += '</label>'
html += '<select id="' + key + '">'
for(let opt in positionOptions) {
let title = positionOptions[opt];
html += '<option value="' + opt + '"' + (prefVal == opt ? ' selected' : '') + '>' + title + '</option>'
}
html += '</select>'
} else {
html += preferenceNames[key]
html += prefTitle
html += '</label>'
html += '<input type="text" id="' + key + '" value="' + preference[key] + '" placeholder="' + defaultPreference[key] + '">'
html += '<input type="text" id="' + key + '" value="' + prefVal + '" placeholder="' + defaultPreference[key] + '">'
}
html += '</div>'
})
Expand Down
2 changes: 1 addition & 1 deletion app/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ button {
margin-bottom: 8px;
}

.preference-panel input {
.preference-panel input, .preference-panel select {
padding: 10px 13px;
font-size: 13px;
border-radius: 3px;
Expand Down
15 changes: 10 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ ipcMain.on('update-preference', function (evt, pref, initialization) {
openAsHidden: true
})
}

mb.setOption('windowPosition', pref['window-position'])
})

var isWin = /^win/.test(process.platform)
var superHotKey = isWin ? 'Control+Shift' : 'Command'

var template = [
{
label: 'Mojibar',
Expand Down Expand Up @@ -74,17 +79,17 @@ var template = [
},
{
label: 'Preference',
accelerator: 'Command+,',
accelerator: superHotKey + '+,',
click: function () { mb.window.webContents.send('open-preference') }
},
{
label: 'Quit App',
accelerator: 'Command+Q',
selector: 'terminate:'
},
accelerator: superHotKey + '+Q',
click: function () { app.quit() }
},
{
label: 'Toggle DevTools',
accelerator: 'Alt+Command+I',
accelerator: (isWin ? 'Control+Shift' : 'Alt+Command') + '+I',
click: function () { mb.window.toggleDevTools() }
}
]
Expand Down

0 comments on commit 3bb7fd1

Please sign in to comment.