Skip to content

Commit

Permalink
Electron: Added several keyboard shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
laurent22 committed Feb 16, 2018
1 parent 7244e12 commit 4218b65
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ElectronClient/app/ElectronAppWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class ElectronAppWrapper {
}))

// Uncomment this to view errors if the application does not start
if (this.env_ === 'dev') this.win_.webContents.openDevTools();
// if (this.env_ === 'dev') this.win_.webContents.openDevTools();

this.win_.on('close', (event) => {
// If it's on macOS, the app is completely closed only if the user chooses to close the app (willQuitApp_ will be true)
Expand Down
26 changes: 26 additions & 0 deletions ElectronClient/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ class Application extends BaseApplication {
}
}, {
label: _('New notebook'),
accelerator: 'CommandOrControl+B',
screens: ['Main'],
click: () => {
this.dispatch({
Expand Down Expand Up @@ -228,6 +229,14 @@ class Application extends BaseApplication {
},
});
}
}, {
type: 'separator',
platforms: ['darwin'],
}, {
label: _('Hide %s', 'Joplin'),
platforms: ['darwin'],
accelerator: 'CommandOrControl+H',
click: () => { bridge().window().hide() }
}, {
type: 'separator',
}, {
Expand Down Expand Up @@ -266,6 +275,19 @@ class Application extends BaseApplication {
});
},
}],
}, {
label: _('View'),
submenu: [{
label: _('Toggle editor layout'),
screens: ['Main'],
accelerator: 'CommandOrControl+L',
click: () => {
this.dispatch({
type: 'WINDOW_COMMAND',
name: 'toggleVisiblePanes',
});
}
}],
}, {
label: _('Tools'),
submenu: [{
Expand All @@ -289,6 +311,7 @@ class Application extends BaseApplication {
}
},{
label: _('General Options'),
accelerator: 'CommandOrControl+,',
click: () => {
this.dispatch({
type: 'NAV_GO',
Expand Down Expand Up @@ -334,10 +357,13 @@ class Application extends BaseApplication {
}

function removeUnwantedItems(template, screen) {
const platform = shim.platformName();

let output = [];
for (let i = 0; i < template.length; i++) {
const t = Object.assign({}, template[i]);
if (t.screens && t.screens.indexOf(screen) < 0) continue;
if (t.platforms && t.platforms.indexOf(platform) < 0) continue;
if (t.submenu) t.submenu = removeUnwantedItems(t.submenu, screen);
if (('submenu' in t) && isEmptyMenu(t.submenu)) continue;
output.push(t);
Expand Down
37 changes: 35 additions & 2 deletions ElectronClient/app/checkForUpdates.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,47 @@ autoUpdater.on('error', (error) => {
onCheckEnded();
})

function findDownloadFilename_(info) {
// { version: '1.0.64',
// files:
// [ { url: 'Joplin-1.0.64-mac.zip',
// sha512: 'OlemXqhq/fSifx7EutvMzfoCI/1kGNl10i8nkvACEDfVXwP8hankDBXEC0+GxSArsZuxOh3U1+C+4j72SfIUew==' },
// { url: 'Joplin-1.0.64.dmg',
// sha512: 'jAewQQoJ3nCaOj8hWDgf0sc3LBbAWQtiKqfTflK8Hc3Dh7fAy9jRHfFAZKFUZ9ll95Bun0DVsLq8wLSUrdsMXw==',
// size: 77104485 } ],
// path: 'Joplin-1.0.64-mac.zip',
// sha512: 'OlemXqhq/fSifx7EutvMzfoCI/1kGNl10i8nkvACEDfVXwP8hankDBXEC0+GxSArsZuxOh3U1+C+4j72SfIUew==',
// releaseDate: '2018-02-16T00:13:01.634Z',
// releaseName: 'v1.0.64',
// releaseNotes: '<p>Still more fixes and im...' }

if (!info) return null;

if (!info.files) {
// info.path seems to contain a default, though not a good one,
// so the loop below if preferable to find the right file.
return info.path;
}

for (let i = 0; i < info.files.length; i++) {
const f = info.files[i].url; // Annoyingly this is called "url" but it's obviously not a url, so hopefully it won't change later on and become one.
if (f.indexOf('.exe') >= 0) return f;
if (f.indexOf('.dmg') >= 0) return f;
}

return info.path;
}

autoUpdater.on('update-available', (info) => {
if (!info.version || !info.path) {
const filename = findDownloadFilename_(info);

if (!info.version || !filename) {
if (checkInBackground_) return onCheckEnded();
showErrorMessageBox(('Could not get version info: ' + JSON.stringify(info)));
return onCheckEnded();
}

const downloadUrl = 'https://github.com/laurent22/joplin/releases/download/v' + info.version + '/' + info.path;
const downloadUrl = 'https://github.com/laurent22/joplin/releases/download/v' + info.version + '/' + filename;

let releaseNotes = info.releaseNotes + '';
if (releaseNotes) releaseNotes = '\n\n' + _('Release notes:\n\n%s', htmlToText_(releaseNotes));
Expand Down
6 changes: 3 additions & 3 deletions ElectronClient/app/gui/MainScreen.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ class MainScreenComponent extends React.Component {
}
},
});
} else if (command.name === 'toggleVisiblePanes') {
this.toggleVisiblePanes();
} else if (command.name === 'editAlarm') {
const note = await Note.load(command.noteId);

Expand Down Expand Up @@ -309,9 +311,7 @@ class MainScreenComponent extends React.Component {
title: _('Layout'),
iconName: 'fa-columns',
enabled: !!notes.length,
onClick: () => {
this.toggleVisiblePanes();
},
onClick: () => { this.doCommand({ name: 'toggleVisiblePanes' }) },
});

if (!this.promptOnClose_) {
Expand Down
8 changes: 8 additions & 0 deletions ReactNativeClient/lib/shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ shim.isMac = () => {
return process && process.platform === 'darwin';
}

shim.platformName = function() {
if (shim.isReactNative()) return 'mobile';
if (shim.isMac()) return 'darwin';
if (shim.isWindows()) return 'win32';
if (shim.isLinux()) return 'linux';
throw new Error('Cannot determine platform');
}

// https://github.com/cheton/is-electron
shim.isElectron = () => {
// Renderer process
Expand Down
4 changes: 3 additions & 1 deletion joplin.sublime-project
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"ElectronClient/app/css/font-awesome.min.css",
"docs/*.html",
"docs/*.svg",
"ReactNativeClient/lib/mime-utils.js",
],
"folder_exclude_patterns":
[
Expand Down Expand Up @@ -52,7 +53,8 @@
"tests/logs",
"ReactNativeClient/ios/build",
"ElectronClient/app/dist",
"_releases"
"_releases",
"ReactNativeClient/lib/csstojs",
],
"path": "."
},
Expand Down

0 comments on commit 4218b65

Please sign in to comment.