2018-03-09 22:59:12 +02:00
|
|
|
require('app-module-path').addPath(__dirname);
|
|
|
|
|
|
|
|
const { BaseApplication } = require('lib/BaseApplication');
|
|
|
|
const { FoldersScreenUtils } = require('lib/folders-screen-utils.js');
|
|
|
|
const Setting = require('lib/models/Setting.js');
|
|
|
|
const { shim } = require('lib/shim.js');
|
|
|
|
const MasterKey = require('lib/models/MasterKey');
|
2019-07-30 09:35:42 +02:00
|
|
|
const Note = require('lib/models/Note');
|
2020-05-17 17:45:27 +02:00
|
|
|
const Folder = require('lib/models/Folder');
|
2020-01-30 23:05:23 +02:00
|
|
|
const { MarkupToHtml } = require('lib/joplin-renderer');
|
2018-03-09 22:59:12 +02:00
|
|
|
const { _, setLocale } = require('lib/locale.js');
|
2019-07-30 09:35:42 +02:00
|
|
|
const { Logger } = require('lib/logger.js');
|
2018-03-09 22:59:12 +02:00
|
|
|
const fs = require('fs-extra');
|
|
|
|
const Tag = require('lib/models/Tag.js');
|
|
|
|
const { reg } = require('lib/registry.js');
|
|
|
|
const { defaultState } = require('lib/reducer.js');
|
|
|
|
const packageInfo = require('./packageInfo.js');
|
|
|
|
const AlarmService = require('lib/services/AlarmService.js');
|
|
|
|
const AlarmServiceDriverNode = require('lib/services/AlarmServiceDriverNode');
|
|
|
|
const DecryptionWorker = require('lib/services/DecryptionWorker');
|
|
|
|
const InteropService = require('lib/services/InteropService');
|
|
|
|
const InteropServiceHelper = require('./InteropServiceHelper.js');
|
2018-03-15 20:08:46 +02:00
|
|
|
const ResourceService = require('lib/services/ResourceService');
|
2018-05-25 14:30:27 +02:00
|
|
|
const ClipperServer = require('lib/ClipperServer');
|
2018-11-21 21:50:50 +02:00
|
|
|
const ExternalEditWatcher = require('lib/services/ExternalEditWatcher');
|
2020-05-30 14:25:05 +02:00
|
|
|
const ResourceEditWatcher = require('lib/services/ResourceEditWatcher').default;
|
2018-03-09 22:59:12 +02:00
|
|
|
const { bridge } = require('electron').remote.require('./bridge');
|
2020-03-13 01:13:18 +02:00
|
|
|
const { shell, webFrame, clipboard } = require('electron');
|
2017-11-11 14:00:37 +02:00
|
|
|
const Menu = bridge().Menu;
|
2019-04-01 21:43:13 +02:00
|
|
|
const PluginManager = require('lib/services/PluginManager');
|
2019-05-06 22:35:29 +02:00
|
|
|
const RevisionService = require('lib/services/RevisionService');
|
2019-05-12 12:41:07 +02:00
|
|
|
const MigrationService = require('lib/services/MigrationService');
|
2019-07-20 23:13:10 +02:00
|
|
|
const TemplateUtils = require('lib/TemplateUtils');
|
2019-12-13 02:40:58 +02:00
|
|
|
const CssUtils = require('lib/CssUtils');
|
2019-04-01 21:43:13 +02:00
|
|
|
|
|
|
|
const pluginClasses = [
|
|
|
|
require('./plugins/GotoAnything.min'),
|
|
|
|
];
|
2017-11-11 14:00:37 +02:00
|
|
|
|
2017-11-06 20:35:04 +02:00
|
|
|
const appDefaultState = Object.assign({}, defaultState, {
|
|
|
|
route: {
|
2018-03-09 22:59:12 +02:00
|
|
|
type: 'NAV_GO',
|
|
|
|
routeName: 'Main',
|
2017-11-11 19:36:47 +02:00
|
|
|
props: {},
|
2017-11-06 20:35:04 +02:00
|
|
|
},
|
|
|
|
navHistory: [],
|
2017-11-11 19:36:47 +02:00
|
|
|
fileToImport: null,
|
|
|
|
windowCommand: null,
|
2018-03-09 22:59:12 +02:00
|
|
|
noteVisiblePanes: ['editor', 'viewer'],
|
2018-04-15 17:50:39 +02:00
|
|
|
sidebarVisibility: true,
|
2019-10-30 11:40:34 +02:00
|
|
|
noteListVisibility: true,
|
2017-11-14 20:02:58 +02:00
|
|
|
windowContentSize: bridge().windowContentSize(),
|
2018-06-18 20:56:07 +02:00
|
|
|
watchedNoteFiles: [],
|
2019-01-31 00:45:28 +02:00
|
|
|
lastEditorScrollPercents: {},
|
2019-12-17 19:06:55 +02:00
|
|
|
devToolsVisible: false,
|
2017-11-14 01:04:27 +02:00
|
|
|
});
|
2017-11-04 14:23:46 +02:00
|
|
|
|
2017-11-06 20:35:04 +02:00
|
|
|
class Application extends BaseApplication {
|
2018-03-09 22:59:12 +02:00
|
|
|
|
2017-11-11 19:36:47 +02:00
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
this.lastMenuScreen_ = null;
|
2020-05-21 01:47:38 +02:00
|
|
|
|
|
|
|
this.bridge_nativeThemeUpdated = this.bridge_nativeThemeUpdated.bind(this);
|
2017-11-11 19:36:47 +02:00
|
|
|
}
|
|
|
|
|
2017-11-05 02:17:48 +02:00
|
|
|
hasGui() {
|
|
|
|
return true;
|
2017-11-04 14:23:46 +02:00
|
|
|
}
|
|
|
|
|
2018-01-31 21:34:38 +02:00
|
|
|
checkForUpdateLoggerPath() {
|
2019-09-19 23:51:18 +02:00
|
|
|
return `${Setting.value('profileDir')}/log-autoupdater.txt`;
|
2018-01-31 21:34:38 +02:00
|
|
|
}
|
|
|
|
|
2017-11-06 20:35:04 +02:00
|
|
|
reducer(state = appDefaultState, action) {
|
|
|
|
let newState = state;
|
2017-11-04 14:23:46 +02:00
|
|
|
|
2017-11-06 20:35:04 +02:00
|
|
|
try {
|
|
|
|
switch (action.type) {
|
2018-03-09 22:59:12 +02:00
|
|
|
|
2019-07-30 09:35:42 +02:00
|
|
|
case 'NAV_BACK':
|
|
|
|
case 'NAV_GO':
|
2018-03-09 22:59:12 +02:00
|
|
|
|
2019-07-30 09:35:42 +02:00
|
|
|
{
|
2018-03-09 22:59:12 +02:00
|
|
|
const goingBack = action.type === 'NAV_BACK';
|
2017-11-06 20:35:04 +02:00
|
|
|
|
|
|
|
if (goingBack && !state.navHistory.length) break;
|
|
|
|
|
|
|
|
const currentRoute = state.route;
|
|
|
|
|
|
|
|
newState = Object.assign({}, state);
|
2020-03-14 01:46:14 +02:00
|
|
|
const newNavHistory = state.navHistory.slice();
|
2017-11-06 20:35:04 +02:00
|
|
|
|
|
|
|
if (goingBack) {
|
|
|
|
let newAction = null;
|
|
|
|
while (newNavHistory.length) {
|
|
|
|
newAction = newNavHistory.pop();
|
|
|
|
if (newAction.routeName !== state.route.routeName) break;
|
|
|
|
}
|
2017-11-04 15:23:15 +02:00
|
|
|
|
2017-11-06 20:35:04 +02:00
|
|
|
if (!newAction) break;
|
2017-11-04 15:23:15 +02:00
|
|
|
|
2017-11-06 20:35:04 +02:00
|
|
|
action = newAction;
|
|
|
|
}
|
2018-04-15 17:50:39 +02:00
|
|
|
|
2017-11-06 20:35:04 +02:00
|
|
|
if (!goingBack) newNavHistory.push(currentRoute);
|
2019-07-30 09:35:42 +02:00
|
|
|
newState.navHistory = newNavHistory;
|
2017-11-06 20:35:04 +02:00
|
|
|
newState.route = action;
|
2019-07-30 09:35:42 +02:00
|
|
|
}
|
|
|
|
break;
|
2017-11-04 15:23:15 +02:00
|
|
|
|
2019-07-30 09:35:42 +02:00
|
|
|
case 'WINDOW_CONTENT_SIZE_SET':
|
2018-03-09 22:59:12 +02:00
|
|
|
|
2019-07-30 09:35:42 +02:00
|
|
|
newState = Object.assign({}, state);
|
|
|
|
newState.windowContentSize = action.size;
|
|
|
|
break;
|
2017-11-04 15:23:15 +02:00
|
|
|
|
2019-07-30 09:35:42 +02:00
|
|
|
case 'WINDOW_COMMAND':
|
2018-03-09 22:59:12 +02:00
|
|
|
|
2019-07-30 09:35:42 +02:00
|
|
|
{
|
2017-11-11 19:36:47 +02:00
|
|
|
newState = Object.assign({}, state);
|
2020-03-14 01:46:14 +02:00
|
|
|
const command = Object.assign({}, action);
|
2017-11-12 01:13:14 +02:00
|
|
|
delete command.type;
|
2020-03-10 01:24:57 +02:00
|
|
|
newState.windowCommand = command.name ? command : null;
|
2019-07-30 09:35:42 +02:00
|
|
|
}
|
|
|
|
break;
|
2017-11-11 19:36:47 +02:00
|
|
|
|
2019-07-30 09:35:42 +02:00
|
|
|
case 'NOTE_VISIBLE_PANES_TOGGLE':
|
2018-03-09 22:59:12 +02:00
|
|
|
|
2019-07-30 09:35:42 +02:00
|
|
|
{
|
2019-10-31 10:42:17 +02:00
|
|
|
const getNextLayout = (currentLayout) => {
|
|
|
|
currentLayout = panes.length === 2 ? 'both' : currentLayout[0];
|
|
|
|
|
|
|
|
let paneOptions;
|
2019-10-31 10:47:45 +02:00
|
|
|
if (state.settings.layoutButtonSequence === Setting.LAYOUT_EDITOR_VIEWER) {
|
2019-10-31 10:42:17 +02:00
|
|
|
paneOptions = ['editor', 'viewer'];
|
2019-10-31 10:47:45 +02:00
|
|
|
} else if (state.settings.layoutButtonSequence === Setting.LAYOUT_EDITOR_SPLIT) {
|
2019-10-31 10:42:17 +02:00
|
|
|
paneOptions = ['editor', 'both'];
|
2019-10-31 10:47:45 +02:00
|
|
|
} else if (state.settings.layoutButtonSequence === Setting.LAYOUT_VIEWER_SPLIT) {
|
2019-10-31 10:42:17 +02:00
|
|
|
paneOptions = ['viewer', 'both'];
|
|
|
|
} else {
|
|
|
|
paneOptions = ['editor', 'viewer', 'both'];
|
|
|
|
}
|
|
|
|
|
|
|
|
const currentLayoutIndex = paneOptions.indexOf(currentLayout);
|
|
|
|
const nextLayoutIndex = currentLayoutIndex === paneOptions.length - 1 ? 0 : currentLayoutIndex + 1;
|
|
|
|
|
2020-03-14 01:46:14 +02:00
|
|
|
const nextLayout = paneOptions[nextLayoutIndex];
|
2019-10-31 10:42:17 +02:00
|
|
|
return nextLayout === 'both' ? ['editor', 'viewer'] : [nextLayout];
|
|
|
|
};
|
2017-11-12 19:02:20 +02:00
|
|
|
|
|
|
|
newState = Object.assign({}, state);
|
2019-10-31 10:42:17 +02:00
|
|
|
|
2020-03-14 01:46:14 +02:00
|
|
|
const panes = state.noteVisiblePanes.slice();
|
2019-10-31 10:42:17 +02:00
|
|
|
newState.noteVisiblePanes = getNextLayout(panes);
|
2019-07-30 09:35:42 +02:00
|
|
|
}
|
|
|
|
break;
|
2017-11-12 19:02:20 +02:00
|
|
|
|
2019-07-30 09:35:42 +02:00
|
|
|
case 'NOTE_VISIBLE_PANES_SET':
|
2018-04-15 17:50:39 +02:00
|
|
|
|
2019-07-30 09:35:42 +02:00
|
|
|
newState = Object.assign({}, state);
|
|
|
|
newState.noteVisiblePanes = action.panes;
|
|
|
|
break;
|
2018-03-09 22:59:12 +02:00
|
|
|
|
2019-07-30 09:35:42 +02:00
|
|
|
case 'SIDEBAR_VISIBILITY_TOGGLE':
|
2018-04-15 17:50:39 +02:00
|
|
|
|
2019-07-30 09:35:42 +02:00
|
|
|
newState = Object.assign({}, state);
|
|
|
|
newState.sidebarVisibility = !state.sidebarVisibility;
|
|
|
|
break;
|
2018-04-15 17:50:39 +02:00
|
|
|
|
2019-07-30 09:35:42 +02:00
|
|
|
case 'SIDEBAR_VISIBILITY_SET':
|
|
|
|
newState = Object.assign({}, state);
|
|
|
|
newState.sidebarVisibility = action.visibility;
|
|
|
|
break;
|
2018-04-15 17:50:39 +02:00
|
|
|
|
2019-10-30 11:40:34 +02:00
|
|
|
case 'NOTELIST_VISIBILITY_TOGGLE':
|
|
|
|
newState = Object.assign({}, state);
|
|
|
|
newState.noteListVisibility = !state.noteListVisibility;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'NOTELIST_VISIBILITY_SET':
|
|
|
|
newState = Object.assign({}, state);
|
|
|
|
newState.noteListVisibility = action.visibility;
|
|
|
|
break;
|
|
|
|
|
2019-07-30 09:35:42 +02:00
|
|
|
case 'NOTE_FILE_WATCHER_ADD':
|
2018-06-18 20:56:07 +02:00
|
|
|
|
2019-07-30 09:35:42 +02:00
|
|
|
if (newState.watchedNoteFiles.indexOf(action.id) < 0) {
|
|
|
|
newState = Object.assign({}, state);
|
|
|
|
const watchedNoteFiles = newState.watchedNoteFiles.slice();
|
|
|
|
watchedNoteFiles.push(action.id);
|
|
|
|
newState.watchedNoteFiles = watchedNoteFiles;
|
|
|
|
}
|
|
|
|
break;
|
2018-06-18 20:56:07 +02:00
|
|
|
|
2019-07-30 09:35:42 +02:00
|
|
|
case 'NOTE_FILE_WATCHER_REMOVE':
|
2018-06-18 20:56:07 +02:00
|
|
|
|
2019-07-30 09:35:42 +02:00
|
|
|
{
|
2018-06-18 20:56:07 +02:00
|
|
|
newState = Object.assign({}, state);
|
|
|
|
const idx = newState.watchedNoteFiles.indexOf(action.id);
|
|
|
|
if (idx >= 0) {
|
|
|
|
const watchedNoteFiles = newState.watchedNoteFiles.slice();
|
|
|
|
watchedNoteFiles.splice(idx, 1);
|
|
|
|
newState.watchedNoteFiles = watchedNoteFiles;
|
|
|
|
}
|
2019-07-30 09:35:42 +02:00
|
|
|
}
|
|
|
|
break;
|
2018-06-18 20:56:07 +02:00
|
|
|
|
2019-07-30 09:35:42 +02:00
|
|
|
case 'NOTE_FILE_WATCHER_CLEAR':
|
2018-06-18 20:56:07 +02:00
|
|
|
|
2019-07-30 09:35:42 +02:00
|
|
|
if (state.watchedNoteFiles.length) {
|
|
|
|
newState = Object.assign({}, state);
|
|
|
|
newState.watchedNoteFiles = [];
|
|
|
|
}
|
|
|
|
break;
|
2018-06-18 20:56:07 +02:00
|
|
|
|
2019-07-30 09:35:42 +02:00
|
|
|
case 'EDITOR_SCROLL_PERCENT_SET':
|
2019-01-31 00:45:28 +02:00
|
|
|
|
2019-07-30 09:35:42 +02:00
|
|
|
{
|
2019-01-31 00:45:28 +02:00
|
|
|
newState = Object.assign({}, state);
|
|
|
|
const newPercents = Object.assign({}, newState.lastEditorScrollPercents);
|
|
|
|
newPercents[action.noteId] = action.percent;
|
|
|
|
newState.lastEditorScrollPercents = newPercents;
|
2019-07-30 09:35:42 +02:00
|
|
|
}
|
|
|
|
break;
|
2019-01-31 00:45:28 +02:00
|
|
|
|
2019-07-30 09:35:42 +02:00
|
|
|
case 'NOTE_DEVTOOLS_TOGGLE':
|
|
|
|
newState = Object.assign({}, state);
|
2019-12-17 19:06:55 +02:00
|
|
|
newState.devToolsVisible = !newState.devToolsVisible;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'NOTE_DEVTOOLS_SET':
|
|
|
|
newState = Object.assign({}, state);
|
|
|
|
newState.devToolsVisible = action.value;
|
2019-07-30 09:35:42 +02:00
|
|
|
break;
|
2019-06-05 18:41:30 +02:00
|
|
|
|
2017-11-06 20:35:04 +02:00
|
|
|
}
|
2017-11-04 15:23:15 +02:00
|
|
|
} catch (error) {
|
2019-09-19 23:51:18 +02:00
|
|
|
error.message = `In reducer: ${error.message} Action: ${JSON.stringify(action)}`;
|
2017-11-04 15:23:15 +02:00
|
|
|
throw error;
|
|
|
|
}
|
2017-11-06 20:35:04 +02:00
|
|
|
|
|
|
|
return super.reducer(newState, action);
|
|
|
|
}
|
|
|
|
|
2019-12-17 19:06:55 +02:00
|
|
|
toggleDevTools(visible) {
|
|
|
|
if (visible) {
|
|
|
|
bridge().openDevTools();
|
|
|
|
} else {
|
|
|
|
bridge().closeDevTools();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-10 20:58:00 +02:00
|
|
|
async generalMiddleware(store, next, action) {
|
2020-05-07 01:31:18 +02:00
|
|
|
let mustUpdateMenuItemStates = false;
|
|
|
|
|
2018-03-09 22:59:12 +02:00
|
|
|
if (action.type == 'SETTING_UPDATE_ONE' && action.key == 'locale' || action.type == 'SETTING_UPDATE_ALL') {
|
|
|
|
setLocale(Setting.value('locale'));
|
2018-05-20 13:54:42 +02:00
|
|
|
// The bridge runs within the main process, with its own instance of locale.js
|
2018-06-16 17:16:27 +02:00
|
|
|
// so it needs to be set too here.
|
2018-05-20 13:54:42 +02:00
|
|
|
bridge().setLocale(Setting.value('locale'));
|
2019-07-20 23:13:10 +02:00
|
|
|
await this.refreshMenu();
|
2017-11-12 02:44:26 +02:00
|
|
|
}
|
|
|
|
|
2018-03-09 22:59:12 +02:00
|
|
|
if (action.type == 'SETTING_UPDATE_ONE' && action.key == 'showTrayIcon' || action.type == 'SETTING_UPDATE_ALL') {
|
2018-01-31 22:10:32 +02:00
|
|
|
this.updateTray();
|
|
|
|
}
|
|
|
|
|
2018-03-09 22:59:12 +02:00
|
|
|
if (action.type == 'SETTING_UPDATE_ONE' && action.key == 'style.editor.fontFamily' || action.type == 'SETTING_UPDATE_ALL') {
|
2018-03-02 20:16:48 +02:00
|
|
|
this.updateEditorFont();
|
|
|
|
}
|
|
|
|
|
2020-02-12 14:41:32 +02:00
|
|
|
if (action.type == 'SETTING_UPDATE_ONE' && action.key == 'windowContentZoomFactor' || action.type == 'SETTING_UPDATE_ALL') {
|
|
|
|
webFrame.setZoomFactor(Setting.value('windowContentZoomFactor') / 100);
|
|
|
|
}
|
|
|
|
|
2020-05-07 01:31:18 +02:00
|
|
|
if (action.type == 'SETTING_UPDATE_ONE' && ['editor.codeView'].includes(action.key) || action.type == 'SETTING_UPDATE_ALL') {
|
|
|
|
mustUpdateMenuItemStates = true;
|
|
|
|
}
|
|
|
|
|
2018-03-09 22:59:12 +02:00
|
|
|
if (['EVENT_NOTE_ALARM_FIELD_CHANGE', 'NOTE_DELETE'].indexOf(action.type) >= 0) {
|
|
|
|
await AlarmService.updateNoteNotification(action.id, action.type === 'NOTE_DELETE');
|
2017-11-28 00:50:46 +02:00
|
|
|
}
|
|
|
|
|
2017-11-11 19:36:47 +02:00
|
|
|
const result = await super.generalMiddleware(store, next, action);
|
|
|
|
const newState = store.getState();
|
|
|
|
|
2018-03-09 22:59:12 +02:00
|
|
|
if (action.type === 'NAV_GO' || action.type === 'NAV_BACK') {
|
2017-11-11 19:36:47 +02:00
|
|
|
app().updateMenu(newState.route.routeName);
|
|
|
|
}
|
|
|
|
|
2018-03-09 22:59:12 +02:00
|
|
|
if (['NOTE_VISIBLE_PANES_TOGGLE', 'NOTE_VISIBLE_PANES_SET'].indexOf(action.type) >= 0) {
|
|
|
|
Setting.setValue('noteVisiblePanes', newState.noteVisiblePanes);
|
2017-11-12 19:02:20 +02:00
|
|
|
}
|
|
|
|
|
2018-04-15 17:50:39 +02:00
|
|
|
if (['SIDEBAR_VISIBILITY_TOGGLE', 'SIDEBAR_VISIBILITY_SET'].indexOf(action.type) >= 0) {
|
|
|
|
Setting.setValue('sidebarVisibility', newState.sidebarVisibility);
|
|
|
|
}
|
|
|
|
|
2019-10-30 11:40:34 +02:00
|
|
|
if (['NOTELIST_VISIBILITY_TOGGLE', 'NOTELIST_VISIBILITY_SET'].indexOf(action.type) >= 0) {
|
|
|
|
Setting.setValue('noteListVisibility', newState.noteListVisibility);
|
|
|
|
}
|
|
|
|
|
2020-05-07 01:31:18 +02:00
|
|
|
if (action.type.indexOf('NOTE_SELECT') === 0 || action.type.indexOf('FOLDER_SELECT') === 0 || action.type === 'NOTE_VISIBLE_PANES_TOGGLE') {
|
|
|
|
mustUpdateMenuItemStates = true;
|
2019-06-20 01:02:13 +02:00
|
|
|
}
|
|
|
|
|
2019-12-17 19:06:55 +02:00
|
|
|
if (['NOTE_DEVTOOLS_TOGGLE', 'NOTE_DEVTOOLS_SET'].indexOf(action.type) >= 0) {
|
|
|
|
this.toggleDevTools(newState.devToolsVisible);
|
2020-05-07 01:31:18 +02:00
|
|
|
mustUpdateMenuItemStates = true;
|
2019-10-09 19:55:35 +02:00
|
|
|
}
|
|
|
|
|
2020-05-17 17:45:27 +02:00
|
|
|
if (action.type === 'FOLDER_AND_NOTE_SELECT') {
|
|
|
|
await Folder.expandTree(newState.folders, action.folderId);
|
|
|
|
}
|
|
|
|
|
2020-05-21 01:47:38 +02:00
|
|
|
if (this.hasGui() && ((action.type == 'SETTING_UPDATE_ONE' && ['themeAutoDetect', 'theme', 'preferredLightTheme', 'preferredDarkTheme'].includes(action.key)) || action.type == 'SETTING_UPDATE_ALL')) {
|
|
|
|
this.handleThemeAutoDetect();
|
|
|
|
}
|
|
|
|
|
2020-05-07 01:31:18 +02:00
|
|
|
if (mustUpdateMenuItemStates) this.updateMenuItemStates(newState);
|
|
|
|
|
2017-11-11 19:36:47 +02:00
|
|
|
return result;
|
2017-11-12 02:44:26 +02:00
|
|
|
}
|
2017-11-11 19:36:47 +02:00
|
|
|
|
2020-05-21 01:47:38 +02:00
|
|
|
handleThemeAutoDetect() {
|
|
|
|
if (!Setting.value('themeAutoDetect')) return;
|
|
|
|
|
|
|
|
if (bridge().shouldUseDarkColors()) {
|
|
|
|
Setting.setValue('theme', Setting.value('preferredDarkTheme'));
|
|
|
|
} else {
|
|
|
|
Setting.setValue('theme', Setting.value('preferredLightTheme'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-20 23:13:10 +02:00
|
|
|
async refreshMenu() {
|
2017-11-12 02:44:26 +02:00
|
|
|
const screen = this.lastMenuScreen_;
|
|
|
|
this.lastMenuScreen_ = null;
|
2019-07-20 23:13:10 +02:00
|
|
|
await this.updateMenu(screen);
|
2017-11-10 20:58:00 +02:00
|
|
|
}
|
|
|
|
|
2019-01-26 20:04:32 +02:00
|
|
|
focusElement_(target) {
|
|
|
|
this.dispatch({
|
|
|
|
type: 'WINDOW_COMMAND',
|
|
|
|
name: 'focusElement',
|
|
|
|
target: target,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-07-20 23:13:10 +02:00
|
|
|
async updateMenu(screen) {
|
2017-11-11 19:36:47 +02:00
|
|
|
if (this.lastMenuScreen_ === screen) return;
|
|
|
|
|
2019-03-02 19:35:57 +02:00
|
|
|
const sortNoteFolderItems = (type) => {
|
|
|
|
const sortItems = [];
|
2019-09-19 23:51:18 +02:00
|
|
|
const sortOptions = Setting.enumOptions(`${type}.sortOrder.field`);
|
2020-03-14 01:46:14 +02:00
|
|
|
for (const field in sortOptions) {
|
2019-03-02 19:35:57 +02:00
|
|
|
if (!sortOptions.hasOwnProperty(field)) continue;
|
|
|
|
sortItems.push({
|
|
|
|
label: sortOptions[field],
|
|
|
|
screens: ['Main'],
|
|
|
|
type: 'checkbox',
|
2019-09-19 23:51:18 +02:00
|
|
|
checked: Setting.value(`${type}.sortOrder.field`) === field,
|
2019-03-02 19:35:57 +02:00
|
|
|
click: () => {
|
2019-09-19 23:51:18 +02:00
|
|
|
Setting.setValue(`${type}.sortOrder.field`, field);
|
2019-03-02 19:35:57 +02:00
|
|
|
this.refreshMenu();
|
2019-07-30 09:35:42 +02:00
|
|
|
},
|
2019-03-02 19:35:57 +02:00
|
|
|
});
|
|
|
|
}
|
2019-07-30 09:35:42 +02:00
|
|
|
|
2019-03-02 19:35:57 +02:00
|
|
|
sortItems.push({ type: 'separator' });
|
|
|
|
|
|
|
|
sortItems.push({
|
2020-05-27 18:21:46 +02:00
|
|
|
id: `sort:${type}:reverse`,
|
2019-09-19 23:51:18 +02:00
|
|
|
label: Setting.settingMetadata(`${type}.sortOrder.reverse`).label(),
|
2018-03-09 22:59:12 +02:00
|
|
|
type: 'checkbox',
|
2019-09-19 23:51:18 +02:00
|
|
|
checked: Setting.value(`${type}.sortOrder.reverse`),
|
2019-03-02 19:35:57 +02:00
|
|
|
screens: ['Main'],
|
2018-02-22 20:58:15 +02:00
|
|
|
click: () => {
|
2019-09-19 23:51:18 +02:00
|
|
|
Setting.setValue(`${type}.sortOrder.reverse`, !Setting.value(`${type}.sortOrder.reverse`));
|
2019-03-02 19:35:57 +02:00
|
|
|
},
|
2018-04-15 17:50:39 +02:00
|
|
|
});
|
2019-03-02 19:35:57 +02:00
|
|
|
|
|
|
|
return sortItems;
|
2019-07-30 09:35:42 +02:00
|
|
|
};
|
2018-02-22 20:58:15 +02:00
|
|
|
|
2019-03-02 19:35:57 +02:00
|
|
|
const sortNoteItems = sortNoteFolderItems('notes');
|
|
|
|
const sortFolderItems = sortNoteFolderItems('folders');
|
|
|
|
|
2019-01-26 20:04:32 +02:00
|
|
|
const focusItems = [];
|
|
|
|
|
|
|
|
focusItems.push({
|
|
|
|
label: _('Sidebar'),
|
2019-07-30 09:35:42 +02:00
|
|
|
click: () => { this.focusElement_('sideBar'); },
|
2019-01-26 20:04:32 +02:00
|
|
|
accelerator: 'CommandOrControl+Shift+S',
|
|
|
|
});
|
|
|
|
|
|
|
|
focusItems.push({
|
|
|
|
label: _('Note list'),
|
2019-07-30 09:35:42 +02:00
|
|
|
click: () => { this.focusElement_('noteList'); },
|
2019-01-26 20:04:32 +02:00
|
|
|
accelerator: 'CommandOrControl+Shift+L',
|
|
|
|
});
|
|
|
|
|
|
|
|
focusItems.push({
|
|
|
|
label: _('Note title'),
|
2019-07-30 09:35:42 +02:00
|
|
|
click: () => { this.focusElement_('noteTitle'); },
|
2019-01-26 20:04:32 +02:00
|
|
|
accelerator: 'CommandOrControl+Shift+N',
|
|
|
|
});
|
|
|
|
|
|
|
|
focusItems.push({
|
|
|
|
label: _('Note body'),
|
2019-07-30 09:35:42 +02:00
|
|
|
click: () => { this.focusElement_('noteBody'); },
|
2019-01-26 20:04:32 +02:00
|
|
|
accelerator: 'CommandOrControl+Shift+B',
|
|
|
|
});
|
|
|
|
|
2020-02-21 07:33:48 +02:00
|
|
|
let toolsItems = [];
|
2018-02-27 22:04:38 +02:00
|
|
|
const importItems = [];
|
|
|
|
const exportItems = [];
|
2019-04-01 11:04:34 +02:00
|
|
|
const toolsItemsFirst = [];
|
2019-07-30 09:35:42 +02:00
|
|
|
const templateItems = [];
|
2018-02-27 22:04:38 +02:00
|
|
|
const ioService = new InteropService();
|
|
|
|
const ioModules = ioService.modules();
|
|
|
|
for (let i = 0; i < ioModules.length; i++) {
|
|
|
|
const module = ioModules[i];
|
2018-03-09 22:59:12 +02:00
|
|
|
if (module.type === 'exporter') {
|
2019-12-18 12:00:59 +02:00
|
|
|
if (module.canDoMultiExport !== false) {
|
|
|
|
exportItems.push({
|
|
|
|
label: module.fullLabel(),
|
|
|
|
screens: ['Main'],
|
|
|
|
click: async () => {
|
|
|
|
await InteropServiceHelper.export(this.dispatch.bind(this), module);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2018-02-27 22:04:38 +02:00
|
|
|
} else {
|
|
|
|
for (let j = 0; j < module.sources.length; j++) {
|
|
|
|
const moduleSource = module.sources[j];
|
|
|
|
importItems.push({
|
2018-03-12 20:01:47 +02:00
|
|
|
label: module.fullLabel(moduleSource),
|
2018-03-09 22:59:12 +02:00
|
|
|
screens: ['Main'],
|
2018-02-27 22:04:38 +02:00
|
|
|
click: async () => {
|
|
|
|
let path = null;
|
|
|
|
|
|
|
|
const selectedFolderId = this.store().getState().selectedFolderId;
|
|
|
|
|
2018-03-09 22:59:12 +02:00
|
|
|
if (moduleSource === 'file') {
|
2018-02-27 22:04:38 +02:00
|
|
|
path = bridge().showOpenDialog({
|
2020-02-05 00:09:34 +02:00
|
|
|
filters: [{ name: module.description, extensions: module.fileExtensions }],
|
2018-02-27 22:04:38 +02:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
path = bridge().showOpenDialog({
|
2018-03-09 22:59:12 +02:00
|
|
|
properties: ['openDirectory', 'createDirectory'],
|
2018-02-27 22:04:38 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!path || (Array.isArray(path) && !path.length)) return;
|
|
|
|
|
|
|
|
if (Array.isArray(path)) path = path[0];
|
|
|
|
|
|
|
|
this.dispatch({
|
2018-03-09 22:59:12 +02:00
|
|
|
type: 'WINDOW_COMMAND',
|
|
|
|
name: 'showModalMessage',
|
2018-02-27 22:04:38 +02:00
|
|
|
message: _('Importing from "%s" as "%s" format. Please wait...', path, module.format),
|
|
|
|
});
|
|
|
|
|
2019-09-23 23:18:30 +02:00
|
|
|
const importOptions = {
|
|
|
|
path,
|
|
|
|
format: module.format,
|
|
|
|
modulePath: module.path,
|
|
|
|
onError: console.warn,
|
|
|
|
destinationFolderId:
|
|
|
|
!module.isNoteArchive && moduleSource === 'file'
|
|
|
|
? selectedFolderId
|
|
|
|
: null,
|
2019-07-30 09:35:42 +02:00
|
|
|
};
|
2018-02-27 22:04:38 +02:00
|
|
|
|
|
|
|
const service = new InteropService();
|
|
|
|
try {
|
|
|
|
const result = await service.import(importOptions);
|
2018-03-09 22:59:12 +02:00
|
|
|
console.info('Import result: ', result);
|
2018-02-27 22:04:38 +02:00
|
|
|
} catch (error) {
|
|
|
|
bridge().showErrorMessageBox(error.message);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.dispatch({
|
2018-03-09 22:59:12 +02:00
|
|
|
type: 'WINDOW_COMMAND',
|
|
|
|
name: 'hideModalMessage',
|
2018-02-27 22:04:38 +02:00
|
|
|
});
|
2019-07-30 09:35:42 +02:00
|
|
|
},
|
2018-02-27 22:04:38 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-12 20:01:47 +02:00
|
|
|
exportItems.push({
|
2019-09-19 23:51:18 +02:00
|
|
|
label: `PDF - ${_('PDF File')}`,
|
2018-03-12 20:01:47 +02:00
|
|
|
screens: ['Main'],
|
|
|
|
click: async () => {
|
2020-02-11 16:14:04 +02:00
|
|
|
const selectedNoteIds = this.store().getState().selectedNoteIds;
|
2018-03-12 20:01:47 +02:00
|
|
|
this.dispatch({
|
|
|
|
type: 'WINDOW_COMMAND',
|
|
|
|
name: 'exportPdf',
|
2020-02-11 16:14:04 +02:00
|
|
|
noteIds: selectedNoteIds,
|
2018-04-15 17:50:39 +02:00
|
|
|
});
|
2019-07-30 09:35:42 +02:00
|
|
|
},
|
2018-03-12 20:01:47 +02:00
|
|
|
});
|
|
|
|
|
2019-10-09 21:35:13 +02:00
|
|
|
// We need a dummy entry, otherwise the ternary operator to show a
|
|
|
|
// menu item only on a specific OS does not work.
|
2019-04-01 11:04:34 +02:00
|
|
|
const noItem = {
|
|
|
|
type: 'separator',
|
2019-07-30 09:35:42 +02:00
|
|
|
visible: false,
|
|
|
|
};
|
2019-04-01 11:04:34 +02:00
|
|
|
|
|
|
|
const syncStatusItem = {
|
2019-10-02 20:07:51 +02:00
|
|
|
label: _('Synchronisation Status'),
|
2019-04-01 11:04:34 +02:00
|
|
|
click: () => {
|
|
|
|
this.dispatch({
|
|
|
|
type: 'NAV_GO',
|
|
|
|
routeName: 'Status',
|
|
|
|
});
|
2019-07-30 09:35:42 +02:00
|
|
|
},
|
|
|
|
};
|
2019-04-01 11:04:34 +02:00
|
|
|
|
|
|
|
const newNoteItem = {
|
|
|
|
label: _('New note'),
|
|
|
|
accelerator: 'CommandOrControl+N',
|
|
|
|
screens: ['Main'],
|
|
|
|
click: () => {
|
|
|
|
this.dispatch({
|
|
|
|
type: 'WINDOW_COMMAND',
|
|
|
|
name: 'newNote',
|
|
|
|
});
|
2019-07-30 09:35:42 +02:00
|
|
|
},
|
|
|
|
};
|
2019-04-01 11:04:34 +02:00
|
|
|
|
|
|
|
const newTodoItem = {
|
|
|
|
label: _('New to-do'),
|
|
|
|
accelerator: 'CommandOrControl+T',
|
|
|
|
screens: ['Main'],
|
|
|
|
click: () => {
|
|
|
|
this.dispatch({
|
|
|
|
type: 'WINDOW_COMMAND',
|
|
|
|
name: 'newTodo',
|
|
|
|
});
|
2019-07-30 09:35:42 +02:00
|
|
|
},
|
|
|
|
};
|
2019-04-01 11:04:34 +02:00
|
|
|
|
|
|
|
const newNotebookItem = {
|
|
|
|
label: _('New notebook'),
|
|
|
|
screens: ['Main'],
|
|
|
|
click: () => {
|
|
|
|
this.dispatch({
|
|
|
|
type: 'WINDOW_COMMAND',
|
|
|
|
name: 'newNotebook',
|
|
|
|
});
|
2019-07-30 09:35:42 +02:00
|
|
|
},
|
|
|
|
};
|
2019-04-01 11:04:34 +02:00
|
|
|
|
2019-10-17 22:41:13 +02:00
|
|
|
const newSubNotebookItem = {
|
|
|
|
label: _('New sub-notebook'),
|
|
|
|
screens: ['Main'],
|
|
|
|
click: () => {
|
|
|
|
this.dispatch({
|
|
|
|
type: 'WINDOW_COMMAND',
|
|
|
|
name: 'newSubNotebook',
|
|
|
|
activeFolderId: Setting.value('activeFolderId'),
|
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2019-04-01 11:04:34 +02:00
|
|
|
const printItem = {
|
|
|
|
label: _('Print'),
|
2019-04-20 13:02:43 +02:00
|
|
|
accelerator: 'CommandOrControl+P',
|
2019-04-01 11:04:34 +02:00
|
|
|
screens: ['Main'],
|
|
|
|
click: () => {
|
|
|
|
this.dispatch({
|
|
|
|
type: 'WINDOW_COMMAND',
|
|
|
|
name: 'print',
|
2020-05-02 17:41:07 +02:00
|
|
|
noteIds: this.store().getState().selectedNoteIds,
|
2019-04-01 11:04:34 +02:00
|
|
|
});
|
2019-07-30 09:35:42 +02:00
|
|
|
},
|
|
|
|
};
|
2019-04-01 11:04:34 +02:00
|
|
|
|
|
|
|
toolsItemsFirst.push(syncStatusItem, {
|
|
|
|
type: 'separator',
|
|
|
|
screens: ['Main'],
|
|
|
|
});
|
|
|
|
|
2019-07-20 23:13:10 +02:00
|
|
|
const templateDirExists = await shim.fsDriver().exists(Setting.value('templateDir'));
|
|
|
|
|
|
|
|
templateItems.push({
|
|
|
|
label: _('Create note from template'),
|
|
|
|
visible: templateDirExists,
|
|
|
|
click: () => {
|
|
|
|
this.dispatch({
|
|
|
|
type: 'WINDOW_COMMAND',
|
|
|
|
name: 'selectTemplate',
|
|
|
|
noteType: 'note',
|
|
|
|
});
|
2019-07-30 09:35:42 +02:00
|
|
|
},
|
2019-07-20 23:13:10 +02:00
|
|
|
}, {
|
|
|
|
label: _('Create to-do from template'),
|
|
|
|
visible: templateDirExists,
|
|
|
|
click: () => {
|
|
|
|
this.dispatch({
|
|
|
|
type: 'WINDOW_COMMAND',
|
|
|
|
name: 'selectTemplate',
|
|
|
|
noteType: 'todo',
|
|
|
|
});
|
2019-07-30 09:35:42 +02:00
|
|
|
},
|
2019-07-20 23:13:10 +02:00
|
|
|
}, {
|
|
|
|
label: _('Insert template'),
|
|
|
|
visible: templateDirExists,
|
|
|
|
accelerator: 'CommandOrControl+Alt+I',
|
|
|
|
click: () => {
|
|
|
|
this.dispatch({
|
|
|
|
type: 'WINDOW_COMMAND',
|
|
|
|
name: 'selectTemplate',
|
|
|
|
});
|
2019-07-30 09:35:42 +02:00
|
|
|
},
|
2019-07-20 23:13:10 +02:00
|
|
|
}, {
|
|
|
|
label: _('Open template directory'),
|
|
|
|
click: () => {
|
|
|
|
const templateDir = Setting.value('templateDir');
|
|
|
|
if (!templateDirExists) shim.fsDriver().mkdir(templateDir);
|
|
|
|
shell.openItem(templateDir);
|
2019-07-30 09:35:42 +02:00
|
|
|
},
|
2019-07-20 23:13:10 +02:00
|
|
|
}, {
|
|
|
|
label: _('Refresh templates'),
|
|
|
|
click: async () => {
|
|
|
|
const templates = await TemplateUtils.loadTemplates(Setting.value('templateDir'));
|
|
|
|
|
|
|
|
this.store().dispatch({
|
|
|
|
type: 'TEMPLATE_UPDATE_ALL',
|
2019-07-30 09:35:42 +02:00
|
|
|
templates: templates,
|
2019-07-20 23:13:10 +02:00
|
|
|
});
|
2019-07-30 09:35:42 +02:00
|
|
|
},
|
2019-07-20 23:13:10 +02:00
|
|
|
});
|
|
|
|
|
2020-02-21 07:33:48 +02:00
|
|
|
// we need this workaround, because on macOS the menu is different
|
|
|
|
const toolsItemsWindowsLinux = toolsItemsFirst.concat([{
|
2019-09-11 01:53:01 +02:00
|
|
|
label: _('Options'),
|
|
|
|
visible: !shim.isMac(),
|
|
|
|
accelerator: 'CommandOrControl+,',
|
|
|
|
click: () => {
|
|
|
|
this.dispatch({
|
|
|
|
type: 'NAV_GO',
|
|
|
|
routeName: 'Config',
|
|
|
|
});
|
|
|
|
},
|
2020-02-21 07:33:48 +02:00
|
|
|
}]);
|
|
|
|
|
|
|
|
// the following menu items will be available for all OS under Tools
|
|
|
|
const toolsItemsAll = [{
|
2020-04-08 12:12:25 +02:00
|
|
|
label: _('Note attachments...'),
|
2020-02-21 07:33:48 +02:00
|
|
|
click: () => {
|
|
|
|
this.dispatch({
|
|
|
|
type: 'NAV_GO',
|
|
|
|
routeName: 'Resources',
|
|
|
|
});
|
|
|
|
},
|
|
|
|
}];
|
|
|
|
|
|
|
|
if (!shim.isMac()) {
|
|
|
|
toolsItems = toolsItems.concat(toolsItemsWindowsLinux);
|
|
|
|
}
|
|
|
|
toolsItems = toolsItems.concat(toolsItemsAll);
|
2019-04-01 11:04:34 +02:00
|
|
|
|
|
|
|
function _checkForUpdates(ctx) {
|
|
|
|
bridge().checkForUpdates(false, bridge().window(), ctx.checkForUpdateLoggerPath(), { includePreReleases: Setting.value('autoUpdate.includePreReleases') });
|
|
|
|
}
|
|
|
|
|
|
|
|
function _showAbout() {
|
|
|
|
const p = packageInfo;
|
2019-06-27 16:04:02 +02:00
|
|
|
let gitInfo = '';
|
2019-07-30 09:35:42 +02:00
|
|
|
if ('git' in p) {
|
2019-06-27 16:04:02 +02:00
|
|
|
gitInfo = _('Revision: %s (%s)', p.git.hash, p.git.branch);
|
|
|
|
}
|
2020-02-10 17:54:53 +02:00
|
|
|
const copyrightText = 'Copyright © 2016-YYYY Laurent Cozic';
|
2020-03-14 01:46:14 +02:00
|
|
|
const message = [
|
2019-04-01 11:04:34 +02:00
|
|
|
p.description,
|
|
|
|
'',
|
2020-02-10 17:54:53 +02:00
|
|
|
copyrightText.replace('YYYY', new Date().getFullYear()),
|
2019-04-01 11:04:34 +02:00
|
|
|
_('%s %s (%s, %s)', p.name, p.version, Setting.value('env'), process.platform),
|
2019-10-10 23:23:11 +02:00
|
|
|
'',
|
|
|
|
_('Client ID: %s', Setting.value('clientId')),
|
|
|
|
_('Sync Version: %s', Setting.value('syncVersion')),
|
2020-02-03 23:40:48 +02:00
|
|
|
_('Profile Version: %s', reg.db().version()),
|
2020-06-03 18:07:50 +02:00
|
|
|
_('Keychain Supported: %s', Setting.value('keychain.supported') >= 1 ? _('Yes') : _('No')),
|
2019-04-01 11:04:34 +02:00
|
|
|
];
|
2019-07-30 09:35:42 +02:00
|
|
|
if (gitInfo) {
|
2019-09-19 23:51:18 +02:00
|
|
|
message.push(`\n${gitInfo}`);
|
2019-06-27 16:04:02 +02:00
|
|
|
console.info(gitInfo);
|
|
|
|
}
|
2020-03-13 01:13:18 +02:00
|
|
|
const text = message.join('\n');
|
|
|
|
|
|
|
|
const copyToClipboard = bridge().showMessageBox(text, {
|
2019-12-05 11:44:16 +02:00
|
|
|
icon: `${bridge().electronApp().buildDir()}/icons/128x128.png`,
|
2020-03-13 01:13:18 +02:00
|
|
|
buttons: [_('Copy'), _('OK')],
|
|
|
|
cancelId: 1,
|
|
|
|
defaultId: 1,
|
2019-04-01 11:04:34 +02:00
|
|
|
});
|
2020-03-13 01:13:18 +02:00
|
|
|
if (copyToClipboard === 0) {
|
|
|
|
clipboard.writeText(message.splice(3).join('\n'));
|
|
|
|
}
|
2019-04-01 11:04:34 +02:00
|
|
|
}
|
|
|
|
|
2019-04-01 21:51:47 +02:00
|
|
|
const rootMenuFile = {
|
2019-10-09 21:35:13 +02:00
|
|
|
// Using a dummy entry for macOS here, because first menu
|
|
|
|
// becomes 'Joplin' and we need a nenu called 'File' later.
|
2019-04-01 21:51:47 +02:00
|
|
|
label: shim.isMac() ? '&JoplinMainMenu' : _('&File'),
|
2019-10-09 21:35:13 +02:00
|
|
|
// `&` before one of the char in the label name mean, that
|
|
|
|
// <Alt + F> will open this menu. It's needed becase electron
|
|
|
|
// opens the first menu on Alt press if no hotkey assigned.
|
|
|
|
// Issue: https://github.com/laurent22/joplin/issues/934
|
2019-04-01 21:51:47 +02:00
|
|
|
submenu: [{
|
|
|
|
label: _('About Joplin'),
|
|
|
|
visible: shim.isMac() ? true : false,
|
2019-07-30 09:35:42 +02:00
|
|
|
click: () => _showAbout(),
|
2019-04-01 21:51:47 +02:00
|
|
|
}, {
|
|
|
|
type: 'separator',
|
2019-07-30 09:35:42 +02:00
|
|
|
visible: shim.isMac() ? true : false,
|
2019-04-01 21:51:47 +02:00
|
|
|
}, {
|
|
|
|
label: _('Preferences...'),
|
|
|
|
visible: shim.isMac() ? true : false,
|
2019-09-11 01:53:01 +02:00
|
|
|
accelerator: 'CommandOrControl+,',
|
|
|
|
click: () => {
|
|
|
|
this.dispatch({
|
|
|
|
type: 'NAV_GO',
|
|
|
|
routeName: 'Config',
|
|
|
|
});
|
|
|
|
},
|
2019-04-01 21:51:47 +02:00
|
|
|
}, {
|
|
|
|
label: _('Check for updates...'),
|
|
|
|
visible: shim.isMac() ? true : false,
|
2019-07-30 09:35:42 +02:00
|
|
|
click: () => _checkForUpdates(this),
|
2019-04-01 21:51:47 +02:00
|
|
|
}, {
|
|
|
|
type: 'separator',
|
2019-07-30 09:35:42 +02:00
|
|
|
visible: shim.isMac() ? true : false,
|
2019-04-01 21:51:47 +02:00
|
|
|
},
|
|
|
|
shim.isMac() ? noItem : newNoteItem,
|
|
|
|
shim.isMac() ? noItem : newTodoItem,
|
2019-10-17 22:41:13 +02:00
|
|
|
shim.isMac() ? noItem : newNotebookItem,
|
|
|
|
shim.isMac() ? noItem : newSubNotebookItem, {
|
2019-04-01 21:51:47 +02:00
|
|
|
type: 'separator',
|
2019-07-30 09:35:42 +02:00
|
|
|
visible: shim.isMac() ? false : true,
|
2019-07-20 23:13:10 +02:00
|
|
|
}, {
|
|
|
|
label: _('Templates'),
|
|
|
|
visible: shim.isMac() ? false : true,
|
|
|
|
submenu: templateItems,
|
|
|
|
}, {
|
|
|
|
type: 'separator',
|
2019-07-30 09:35:42 +02:00
|
|
|
visible: shim.isMac() ? false : true,
|
2019-04-01 21:51:47 +02:00
|
|
|
}, {
|
|
|
|
label: _('Import'),
|
|
|
|
visible: shim.isMac() ? false : true,
|
|
|
|
submenu: importItems,
|
|
|
|
}, {
|
|
|
|
label: _('Export'),
|
|
|
|
visible: shim.isMac() ? false : true,
|
|
|
|
submenu: exportItems,
|
|
|
|
}, {
|
|
|
|
type: 'separator',
|
|
|
|
}, {
|
|
|
|
label: _('Synchronise'),
|
|
|
|
accelerator: 'CommandOrControl+S',
|
|
|
|
screens: ['Main'],
|
|
|
|
click: async () => {
|
|
|
|
this.dispatch({
|
|
|
|
type: 'WINDOW_COMMAND',
|
|
|
|
name: 'synchronize',
|
|
|
|
});
|
2019-07-30 09:35:42 +02:00
|
|
|
},
|
2019-04-01 21:51:47 +02:00
|
|
|
}, shim.isMac() ? syncStatusItem : noItem, {
|
|
|
|
type: 'separator',
|
|
|
|
}, shim.isMac() ? noItem : printItem, {
|
|
|
|
type: 'separator',
|
|
|
|
platforms: ['darwin'],
|
|
|
|
}, {
|
|
|
|
label: _('Hide %s', 'Joplin'),
|
|
|
|
platforms: ['darwin'],
|
|
|
|
accelerator: 'CommandOrControl+H',
|
2019-07-30 09:35:42 +02:00
|
|
|
click: () => { bridge().electronApp().hide(); },
|
2019-04-01 21:51:47 +02:00
|
|
|
}, {
|
|
|
|
type: 'separator',
|
|
|
|
}, {
|
|
|
|
label: _('Quit'),
|
|
|
|
accelerator: 'CommandOrControl+Q',
|
2019-07-30 09:35:42 +02:00
|
|
|
click: () => { bridge().electronApp().quit(); },
|
|
|
|
}],
|
2019-04-01 21:51:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const rootMenuFileMacOs = {
|
|
|
|
label: _('&File'),
|
|
|
|
visible: shim.isMac() ? true : false,
|
|
|
|
submenu: [
|
|
|
|
newNoteItem,
|
|
|
|
newTodoItem,
|
2019-10-17 22:41:13 +02:00
|
|
|
newNotebookItem,
|
|
|
|
newSubNotebookItem, {
|
2019-04-30 22:38:20 +02:00
|
|
|
label: _('Close Window'),
|
|
|
|
platforms: ['darwin'],
|
|
|
|
accelerator: 'Command+W',
|
|
|
|
selector: 'performClose:',
|
2019-07-20 23:13:10 +02:00
|
|
|
}, {
|
|
|
|
type: 'separator',
|
|
|
|
}, {
|
|
|
|
label: _('Templates'),
|
|
|
|
submenu: templateItems,
|
2019-04-30 22:38:20 +02:00
|
|
|
}, {
|
|
|
|
type: 'separator',
|
2018-03-09 22:59:12 +02:00
|
|
|
}, {
|
|
|
|
label: _('Import'),
|
|
|
|
submenu: importItems,
|
|
|
|
}, {
|
|
|
|
label: _('Export'),
|
|
|
|
submenu: exportItems,
|
2018-03-12 20:01:47 +02:00
|
|
|
}, {
|
|
|
|
type: 'separator',
|
2019-04-01 21:51:47 +02:00
|
|
|
},
|
2019-07-30 09:35:42 +02:00
|
|
|
printItem,
|
|
|
|
],
|
2019-04-01 21:51:47 +02:00
|
|
|
};
|
|
|
|
|
2019-10-31 10:47:45 +02:00
|
|
|
const layoutButtonSequenceOptions = Object.entries(Setting.enumOptions('layoutButtonSequence')).map(([layoutKey, layout]) => ({
|
2019-10-31 10:42:17 +02:00
|
|
|
label: layout,
|
|
|
|
screens: ['Main'],
|
|
|
|
type: 'checkbox',
|
2019-10-31 10:47:45 +02:00
|
|
|
checked: Setting.value('layoutButtonSequence') == layoutKey,
|
2019-10-31 10:42:17 +02:00
|
|
|
click: () => {
|
2019-10-31 10:47:45 +02:00
|
|
|
Setting.setValue('layoutButtonSequence', layoutKey);
|
2019-10-31 10:42:17 +02:00
|
|
|
this.refreshMenu();
|
|
|
|
},
|
|
|
|
}));
|
|
|
|
|
2019-04-01 21:51:47 +02:00
|
|
|
const rootMenus = {
|
2019-04-01 21:43:13 +02:00
|
|
|
edit: {
|
2019-06-20 01:02:13 +02:00
|
|
|
id: 'edit',
|
2019-02-24 13:07:07 +02:00
|
|
|
label: _('&Edit'),
|
2018-03-09 22:59:12 +02:00
|
|
|
submenu: [{
|
2019-06-20 01:02:13 +02:00
|
|
|
id: 'edit:copy',
|
2018-03-09 22:59:12 +02:00
|
|
|
label: _('Copy'),
|
|
|
|
role: 'copy',
|
|
|
|
accelerator: 'CommandOrControl+C',
|
|
|
|
}, {
|
2019-06-20 01:02:13 +02:00
|
|
|
id: 'edit:cut',
|
2018-03-09 22:59:12 +02:00
|
|
|
label: _('Cut'),
|
|
|
|
role: 'cut',
|
|
|
|
accelerator: 'CommandOrControl+X',
|
|
|
|
}, {
|
2019-06-20 01:02:13 +02:00
|
|
|
id: 'edit:paste',
|
2018-03-09 22:59:12 +02:00
|
|
|
label: _('Paste'),
|
|
|
|
role: 'paste',
|
|
|
|
accelerator: 'CommandOrControl+V',
|
2018-10-02 09:40:33 +02:00
|
|
|
}, {
|
2019-06-20 01:02:13 +02:00
|
|
|
id: 'edit:selectAll',
|
2018-10-02 09:40:33 +02:00
|
|
|
label: _('Select all'),
|
|
|
|
role: 'selectall',
|
|
|
|
accelerator: 'CommandOrControl+A',
|
2018-03-09 22:59:12 +02:00
|
|
|
}, {
|
|
|
|
type: 'separator',
|
|
|
|
screens: ['Main'],
|
2018-06-12 00:47:44 +02:00
|
|
|
}, {
|
2019-06-20 01:02:13 +02:00
|
|
|
id: 'edit:bold',
|
2018-06-12 00:47:44 +02:00
|
|
|
label: _('Bold'),
|
|
|
|
screens: ['Main'],
|
|
|
|
accelerator: 'CommandOrControl+B',
|
|
|
|
click: () => {
|
|
|
|
this.dispatch({
|
|
|
|
type: 'WINDOW_COMMAND',
|
|
|
|
name: 'textBold',
|
|
|
|
});
|
|
|
|
},
|
|
|
|
}, {
|
2019-06-20 01:02:13 +02:00
|
|
|
id: 'edit:italic',
|
2018-06-12 00:47:44 +02:00
|
|
|
label: _('Italic'),
|
|
|
|
screens: ['Main'],
|
|
|
|
accelerator: 'CommandOrControl+I',
|
|
|
|
click: () => {
|
|
|
|
this.dispatch({
|
|
|
|
type: 'WINDOW_COMMAND',
|
|
|
|
name: 'textItalic',
|
|
|
|
});
|
|
|
|
},
|
2019-02-09 21:13:23 +02:00
|
|
|
}, {
|
2019-06-20 01:02:13 +02:00
|
|
|
id: 'edit:link',
|
2019-02-09 21:13:23 +02:00
|
|
|
label: _('Link'),
|
|
|
|
screens: ['Main'],
|
|
|
|
accelerator: 'CommandOrControl+K',
|
|
|
|
click: () => {
|
|
|
|
this.dispatch({
|
|
|
|
type: 'WINDOW_COMMAND',
|
|
|
|
name: 'textLink',
|
|
|
|
});
|
|
|
|
},
|
2019-06-10 09:05:20 +02:00
|
|
|
}, {
|
2019-06-20 01:02:13 +02:00
|
|
|
id: 'edit:code',
|
2019-06-10 09:05:20 +02:00
|
|
|
label: _('Code'),
|
|
|
|
screens: ['Main'],
|
|
|
|
accelerator: 'CommandOrControl+`',
|
|
|
|
click: () => {
|
|
|
|
this.dispatch({
|
|
|
|
type: 'WINDOW_COMMAND',
|
|
|
|
name: 'textCode',
|
|
|
|
});
|
|
|
|
},
|
2019-01-31 00:45:49 +02:00
|
|
|
}, {
|
|
|
|
type: 'separator',
|
|
|
|
screens: ['Main'],
|
2018-06-16 17:16:27 +02:00
|
|
|
}, {
|
2019-06-20 01:02:13 +02:00
|
|
|
id: 'edit:insertDateTime',
|
2018-06-16 17:16:27 +02:00
|
|
|
label: _('Insert Date Time'),
|
|
|
|
screens: ['Main'],
|
|
|
|
accelerator: 'CommandOrControl+Shift+T',
|
|
|
|
click: () => {
|
|
|
|
this.dispatch({
|
|
|
|
type: 'WINDOW_COMMAND',
|
|
|
|
name: 'insertDateTime',
|
|
|
|
});
|
|
|
|
},
|
2018-06-12 00:47:44 +02:00
|
|
|
}, {
|
|
|
|
type: 'separator',
|
|
|
|
screens: ['Main'],
|
2018-03-09 22:59:12 +02:00
|
|
|
}, {
|
2019-06-20 01:02:13 +02:00
|
|
|
id: 'edit:focusSearch',
|
2018-03-09 22:59:12 +02:00
|
|
|
label: _('Search in all the notes'),
|
|
|
|
screens: ['Main'],
|
2019-02-09 21:13:23 +02:00
|
|
|
accelerator: shim.isMac() ? 'Shift+Command+F' : 'F6',
|
2018-03-09 22:59:12 +02:00
|
|
|
click: () => {
|
|
|
|
this.dispatch({
|
|
|
|
type: 'WINDOW_COMMAND',
|
2019-06-20 01:02:13 +02:00
|
|
|
name: 'focusSearch',
|
2018-03-09 22:59:12 +02:00
|
|
|
});
|
|
|
|
},
|
2018-12-09 02:18:10 +02:00
|
|
|
}, {
|
2019-06-20 01:02:13 +02:00
|
|
|
id: 'edit:showLocalSearch',
|
2018-12-09 02:18:10 +02:00
|
|
|
label: _('Search in current note'),
|
|
|
|
screens: ['Main'],
|
|
|
|
accelerator: 'CommandOrControl+F',
|
|
|
|
click: () => {
|
|
|
|
this.dispatch({
|
|
|
|
type: 'WINDOW_COMMAND',
|
|
|
|
name: 'showLocalSearch',
|
|
|
|
});
|
|
|
|
},
|
2018-03-09 22:59:12 +02:00
|
|
|
}],
|
2019-04-01 21:43:13 +02:00
|
|
|
},
|
|
|
|
view: {
|
2019-02-24 13:07:07 +02:00
|
|
|
label: _('&View'),
|
2018-03-09 22:59:12 +02:00
|
|
|
submenu: [{
|
2018-04-16 19:27:36 +02:00
|
|
|
label: _('Toggle sidebar'),
|
|
|
|
screens: ['Main'],
|
2019-02-09 21:13:23 +02:00
|
|
|
accelerator: shim.isMac() ? 'Option+Command+S' : 'F10',
|
2018-04-16 19:27:36 +02:00
|
|
|
click: () => {
|
|
|
|
this.dispatch({
|
|
|
|
type: 'WINDOW_COMMAND',
|
|
|
|
name: 'toggleSidebar',
|
|
|
|
});
|
2019-07-30 09:35:42 +02:00
|
|
|
},
|
2019-10-31 10:42:17 +02:00
|
|
|
}, {
|
|
|
|
type: 'separator',
|
|
|
|
screens: ['Main'],
|
|
|
|
}, {
|
2019-10-31 10:47:45 +02:00
|
|
|
label: _('Layout button sequence'),
|
2019-10-31 10:42:17 +02:00
|
|
|
screens: ['Main'],
|
2019-10-31 10:47:45 +02:00
|
|
|
submenu: layoutButtonSequenceOptions,
|
2019-10-30 11:40:34 +02:00
|
|
|
}, {
|
|
|
|
label: _('Toggle note list'),
|
|
|
|
screens: ['Main'],
|
|
|
|
click: () => {
|
|
|
|
this.dispatch({
|
|
|
|
type: 'WINDOW_COMMAND',
|
|
|
|
name: 'toggleNoteList',
|
|
|
|
});
|
|
|
|
},
|
2018-04-16 19:27:36 +02:00
|
|
|
}, {
|
2018-03-09 22:59:12 +02:00
|
|
|
label: _('Toggle editor layout'),
|
|
|
|
screens: ['Main'],
|
|
|
|
accelerator: 'CommandOrControl+L',
|
|
|
|
click: () => {
|
|
|
|
this.dispatch({
|
|
|
|
type: 'WINDOW_COMMAND',
|
|
|
|
name: 'toggleVisiblePanes',
|
|
|
|
});
|
2019-07-30 09:35:42 +02:00
|
|
|
},
|
2018-03-09 22:59:12 +02:00
|
|
|
}, {
|
|
|
|
type: 'separator',
|
|
|
|
screens: ['Main'],
|
|
|
|
}, {
|
|
|
|
label: Setting.settingMetadata('notes.sortOrder.field').label(),
|
|
|
|
screens: ['Main'],
|
|
|
|
submenu: sortNoteItems,
|
|
|
|
}, {
|
2019-03-02 19:35:57 +02:00
|
|
|
label: Setting.settingMetadata('folders.sortOrder.field').label(),
|
2018-03-09 22:59:12 +02:00
|
|
|
screens: ['Main'],
|
2019-03-02 19:35:57 +02:00
|
|
|
submenu: sortFolderItems,
|
2019-11-11 08:14:56 +02:00
|
|
|
}, {
|
|
|
|
label: Setting.settingMetadata('showNoteCounts').label(),
|
|
|
|
type: 'checkbox',
|
|
|
|
checked: Setting.value('showNoteCounts'),
|
|
|
|
screens: ['Main'],
|
|
|
|
click: () => {
|
|
|
|
Setting.setValue('showNoteCounts', !Setting.value('showNoteCounts'));
|
|
|
|
},
|
2018-03-09 22:59:12 +02:00
|
|
|
}, {
|
|
|
|
label: Setting.settingMetadata('uncompletedTodosOnTop').label(),
|
|
|
|
type: 'checkbox',
|
|
|
|
checked: Setting.value('uncompletedTodosOnTop'),
|
|
|
|
screens: ['Main'],
|
|
|
|
click: () => {
|
|
|
|
Setting.setValue('uncompletedTodosOnTop', !Setting.value('uncompletedTodosOnTop'));
|
2018-03-09 19:49:35 +02:00
|
|
|
},
|
2018-05-09 22:00:05 +02:00
|
|
|
}, {
|
|
|
|
label: Setting.settingMetadata('showCompletedTodos').label(),
|
|
|
|
type: 'checkbox',
|
|
|
|
checked: Setting.value('showCompletedTodos'),
|
|
|
|
screens: ['Main'],
|
|
|
|
click: () => {
|
|
|
|
Setting.setValue('showCompletedTodos', !Setting.value('showCompletedTodos'));
|
|
|
|
},
|
2019-01-26 20:04:32 +02:00
|
|
|
}, {
|
|
|
|
type: 'separator',
|
|
|
|
screens: ['Main'],
|
|
|
|
}, {
|
|
|
|
label: _('Focus'),
|
|
|
|
screens: ['Main'],
|
|
|
|
submenu: focusItems,
|
2020-02-12 14:41:32 +02:00
|
|
|
}, {
|
|
|
|
type: 'separator',
|
|
|
|
screens: ['Main'],
|
|
|
|
}, {
|
|
|
|
label: _('Actual Size'),
|
|
|
|
click: () => {
|
|
|
|
Setting.setValue('windowContentZoomFactor', 100);
|
|
|
|
},
|
|
|
|
accelerator: 'CommandOrControl+0',
|
|
|
|
}, {
|
2020-04-30 11:08:19 +02:00
|
|
|
// There are 2 shortcuts for the action 'zoom in', mainly to increase the user experience.
|
|
|
|
// Most applications handle this the same way. These applications indicate Ctrl +, but actually mean Ctrl =.
|
|
|
|
// In fact they allow both: + and =. On the English keyboard layout - and = are used without the shift key.
|
|
|
|
// So to use Ctrl + would mean to use the shift key, but this is not the case in any of the apps that show Ctrl +.
|
|
|
|
// Additionally it allows the use of the plus key on the numpad.
|
2020-02-12 14:41:32 +02:00
|
|
|
label: _('Zoom In'),
|
|
|
|
click: () => {
|
|
|
|
Setting.incValue('windowContentZoomFactor', 10);
|
|
|
|
},
|
2020-04-30 11:08:19 +02:00
|
|
|
accelerator: 'CommandOrControl+Plus',
|
|
|
|
}, {
|
|
|
|
label: _('Zoom In'),
|
|
|
|
visible: false,
|
|
|
|
click: () => {
|
|
|
|
Setting.incValue('windowContentZoomFactor', 10);
|
|
|
|
},
|
2020-02-12 14:41:32 +02:00
|
|
|
accelerator: 'CommandOrControl+=',
|
|
|
|
}, {
|
|
|
|
label: _('Zoom Out'),
|
|
|
|
click: () => {
|
|
|
|
Setting.incValue('windowContentZoomFactor', -10);
|
|
|
|
},
|
|
|
|
accelerator: 'CommandOrControl+-',
|
2018-03-09 22:59:12 +02:00
|
|
|
}],
|
2019-04-01 21:43:13 +02:00
|
|
|
},
|
2020-05-02 17:41:07 +02:00
|
|
|
note: {
|
|
|
|
label: _('&Note'),
|
|
|
|
submenu: [{
|
|
|
|
id: 'edit:commandStartExternalEditing',
|
|
|
|
label: _('Edit in external editor'),
|
|
|
|
screens: ['Main'],
|
|
|
|
accelerator: 'CommandOrControl+E',
|
|
|
|
click: () => {
|
|
|
|
this.dispatch({
|
|
|
|
type: 'WINDOW_COMMAND',
|
|
|
|
name: 'commandStartExternalEditing',
|
|
|
|
});
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
id: 'edit:setTags',
|
|
|
|
label: _('Tags'),
|
|
|
|
screens: ['Main'],
|
|
|
|
accelerator: 'CommandOrControl+Alt+T',
|
|
|
|
click: () => {
|
|
|
|
const selectedNoteIds = this.store().getState().selectedNoteIds;
|
|
|
|
this.dispatch({
|
|
|
|
type: 'WINDOW_COMMAND',
|
|
|
|
name: 'setTags',
|
|
|
|
noteIds: selectedNoteIds,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
type: 'separator',
|
|
|
|
screens: ['Main'],
|
|
|
|
}, {
|
2020-05-07 01:31:18 +02:00
|
|
|
id: 'note:statistics',
|
2020-05-02 17:41:07 +02:00
|
|
|
label: _('Statistics...'),
|
|
|
|
click: () => {
|
|
|
|
this.dispatch({
|
|
|
|
type: 'WINDOW_COMMAND',
|
|
|
|
name: 'commandContentProperties',
|
|
|
|
});
|
|
|
|
},
|
|
|
|
}],
|
|
|
|
},
|
2019-04-01 21:43:13 +02:00
|
|
|
tools: {
|
2019-02-24 13:07:07 +02:00
|
|
|
label: _('&Tools'),
|
2020-02-21 07:33:48 +02:00
|
|
|
submenu: toolsItems,
|
2019-04-01 21:43:13 +02:00
|
|
|
},
|
|
|
|
help: {
|
2019-02-24 13:07:07 +02:00
|
|
|
label: _('&Help'),
|
2020-05-09 11:47:13 +02:00
|
|
|
role: 'help', // Makes it add the "Search" field on macOS
|
2018-03-09 22:59:12 +02:00
|
|
|
submenu: [{
|
|
|
|
label: _('Website and documentation'),
|
|
|
|
accelerator: 'F1',
|
2019-09-30 00:11:36 +02:00
|
|
|
click() { bridge().openExternal('https://joplinapp.org'); },
|
2019-09-09 19:16:00 +02:00
|
|
|
}, {
|
|
|
|
label: _('Joplin Forum'),
|
2019-09-30 00:11:36 +02:00
|
|
|
click() { bridge().openExternal('https://discourse.joplinapp.org'); },
|
2018-03-09 22:59:12 +02:00
|
|
|
}, {
|
|
|
|
label: _('Make a donation'),
|
2019-09-30 00:11:36 +02:00
|
|
|
click() { bridge().openExternal('https://joplinapp.org/donate/'); },
|
2018-03-09 22:59:12 +02:00
|
|
|
}, {
|
|
|
|
label: _('Check for updates...'),
|
2019-04-01 11:04:34 +02:00
|
|
|
visible: shim.isMac() ? false : true,
|
2019-07-30 09:35:42 +02:00
|
|
|
click: () => _checkForUpdates(this),
|
2019-06-05 18:41:30 +02:00
|
|
|
}, {
|
|
|
|
type: 'separator',
|
|
|
|
screens: ['Main'],
|
|
|
|
}, {
|
2019-10-09 19:55:35 +02:00
|
|
|
id: 'help:toggleDevTools',
|
|
|
|
type: 'checkbox',
|
2019-06-05 18:41:30 +02:00
|
|
|
label: _('Toggle development tools'),
|
|
|
|
visible: true,
|
|
|
|
click: () => {
|
|
|
|
this.dispatch({
|
|
|
|
type: 'NOTE_DEVTOOLS_TOGGLE',
|
|
|
|
});
|
|
|
|
},
|
2018-03-09 22:59:12 +02:00
|
|
|
}, {
|
|
|
|
type: 'separator',
|
2019-04-01 11:04:34 +02:00
|
|
|
visible: shim.isMac() ? false : true,
|
2018-03-09 22:59:12 +02:00
|
|
|
screens: ['Main'],
|
|
|
|
}, {
|
|
|
|
label: _('About Joplin'),
|
2019-04-01 11:04:34 +02:00
|
|
|
visible: shim.isMac() ? false : true,
|
2019-07-30 09:35:42 +02:00
|
|
|
click: () => _showAbout(),
|
|
|
|
}],
|
|
|
|
},
|
2019-04-01 21:43:13 +02:00
|
|
|
};
|
|
|
|
|
2019-04-01 21:51:47 +02:00
|
|
|
if (shim.isMac()) {
|
|
|
|
rootMenus.macOsApp = rootMenuFile;
|
|
|
|
rootMenus.file = rootMenuFileMacOs;
|
|
|
|
} else {
|
|
|
|
rootMenus.file = rootMenuFile;
|
|
|
|
}
|
|
|
|
|
2019-05-27 20:48:09 +02:00
|
|
|
// It seems the "visible" property of separators is ignored by Electron, making
|
|
|
|
// it display separators that we want hidden. So this function iterates through
|
|
|
|
// them and remove them completely.
|
2020-05-21 10:14:33 +02:00
|
|
|
const cleanUpSeparators = items => {
|
2019-05-27 20:48:09 +02:00
|
|
|
const output = [];
|
|
|
|
for (const item of items) {
|
|
|
|
if ('visible' in item && item.type === 'separator' && !item.visible) continue;
|
|
|
|
output.push(item);
|
|
|
|
}
|
|
|
|
return output;
|
2019-07-30 09:35:42 +02:00
|
|
|
};
|
2019-05-27 20:48:09 +02:00
|
|
|
|
|
|
|
for (const key in rootMenus) {
|
|
|
|
if (!rootMenus.hasOwnProperty(key)) continue;
|
|
|
|
if (!rootMenus[key].submenu) continue;
|
|
|
|
rootMenus[key].submenu = cleanUpSeparators(rootMenus[key].submenu);
|
|
|
|
}
|
|
|
|
|
2019-04-01 21:43:13 +02:00
|
|
|
const pluginMenuItems = PluginManager.instance().menuItems();
|
|
|
|
for (const item of pluginMenuItems) {
|
2020-03-14 01:46:14 +02:00
|
|
|
const itemParent = rootMenus[item.parent] ? rootMenus[item.parent] : 'tools';
|
2019-04-01 21:43:13 +02:00
|
|
|
itemParent.submenu.push(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
const template = [
|
|
|
|
rootMenus.file,
|
|
|
|
rootMenus.edit,
|
|
|
|
rootMenus.view,
|
2020-05-02 17:41:07 +02:00
|
|
|
rootMenus.note,
|
2019-04-01 21:43:13 +02:00
|
|
|
rootMenus.tools,
|
|
|
|
rootMenus.help,
|
2017-11-11 19:36:47 +02:00
|
|
|
];
|
|
|
|
|
2019-04-01 21:51:47 +02:00
|
|
|
if (shim.isMac()) template.splice(0, 0, rootMenus.macOsApp);
|
|
|
|
|
2017-12-01 21:15:46 +02:00
|
|
|
function isEmptyMenu(template) {
|
|
|
|
for (let i = 0; i < template.length; i++) {
|
|
|
|
const t = template[i];
|
2018-03-09 22:59:12 +02:00
|
|
|
if (t.type !== 'separator') return false;
|
2017-12-01 21:15:46 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-11-11 19:36:47 +02:00
|
|
|
function removeUnwantedItems(template, screen) {
|
2018-02-16 20:08:02 +02:00
|
|
|
const platform = shim.platformName();
|
|
|
|
|
2017-11-11 19:36:47 +02:00
|
|
|
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;
|
2018-02-16 20:08:02 +02:00
|
|
|
if (t.platforms && t.platforms.indexOf(platform) < 0) continue;
|
2017-11-11 19:36:47 +02:00
|
|
|
if (t.submenu) t.submenu = removeUnwantedItems(t.submenu, screen);
|
2018-03-09 22:59:12 +02:00
|
|
|
if (('submenu' in t) && isEmptyMenu(t.submenu)) continue;
|
2017-11-11 19:36:47 +02:00
|
|
|
output.push(t);
|
|
|
|
}
|
2018-05-20 14:01:07 +02:00
|
|
|
|
|
|
|
// Remove empty separator for now empty sections
|
2020-03-14 01:46:14 +02:00
|
|
|
const temp = [];
|
2018-05-20 14:01:07 +02:00
|
|
|
let previous = null;
|
|
|
|
for (let i = 0; i < output.length; i++) {
|
|
|
|
const t = Object.assign({}, output[i]);
|
|
|
|
if (t.type === 'separator') {
|
|
|
|
if (!previous) continue;
|
|
|
|
if (previous.type === 'separator') continue;
|
|
|
|
}
|
|
|
|
temp.push(t);
|
|
|
|
previous = t;
|
|
|
|
}
|
|
|
|
output = temp;
|
|
|
|
|
2017-11-11 19:36:47 +02:00
|
|
|
return output;
|
|
|
|
}
|
|
|
|
|
2020-03-14 01:46:14 +02:00
|
|
|
const screenTemplate = removeUnwantedItems(template, screen);
|
2017-11-11 19:36:47 +02:00
|
|
|
|
|
|
|
const menu = Menu.buildFromTemplate(screenTemplate);
|
|
|
|
Menu.setApplicationMenu(menu);
|
2017-11-11 14:00:37 +02:00
|
|
|
|
2017-11-11 19:36:47 +02:00
|
|
|
this.lastMenuScreen_ = screen;
|
2017-11-11 14:00:37 +02:00
|
|
|
}
|
|
|
|
|
2020-03-21 15:18:37 +02:00
|
|
|
async updateMenuItemStates(state = null) {
|
2019-06-20 01:02:13 +02:00
|
|
|
if (!this.lastMenuScreen_) return;
|
2019-12-17 19:06:55 +02:00
|
|
|
if (!this.store() && !state) return;
|
|
|
|
|
|
|
|
if (!state) state = this.store().getState();
|
2019-06-20 01:02:13 +02:00
|
|
|
|
2019-12-17 19:06:55 +02:00
|
|
|
const selectedNoteIds = state.selectedNoteIds;
|
2019-07-17 23:49:12 +02:00
|
|
|
const note = selectedNoteIds.length === 1 ? await Note.load(selectedNoteIds[0]) : null;
|
2020-05-07 01:31:18 +02:00
|
|
|
const aceEditorViewerOnly = state.settings['editor.codeView'] && state.noteVisiblePanes.length === 1 && state.noteVisiblePanes[0] === 'viewer';
|
|
|
|
|
|
|
|
// Only enabled when there's only one active note, and that note
|
|
|
|
// is a Markdown note (markup_language = MARKDOWN), and the
|
|
|
|
// editor is in edit mode (not viewer-only mode).
|
|
|
|
const singleMarkdownNoteMenuItems = [
|
|
|
|
'edit:bold',
|
|
|
|
'edit:italic',
|
|
|
|
'edit:link',
|
|
|
|
'edit:code',
|
|
|
|
'edit:insertDateTime',
|
|
|
|
];
|
|
|
|
|
|
|
|
// Only enabled when there's only one active note.
|
|
|
|
const singleNoteMenuItems = [
|
|
|
|
'edit:copy',
|
|
|
|
'edit:paste',
|
|
|
|
'edit:cut',
|
|
|
|
'edit:selectAll',
|
|
|
|
'edit:showLocalSearch',
|
|
|
|
'edit:commandStartExternalEditing',
|
|
|
|
'note:statistics',
|
|
|
|
];
|
|
|
|
|
|
|
|
for (const itemId of singleMarkdownNoteMenuItems) {
|
|
|
|
const menuItem = Menu.getApplicationMenu().getMenuItemById(itemId);
|
|
|
|
if (!menuItem) continue;
|
|
|
|
menuItem.enabled = !aceEditorViewerOnly && !!note && note.markup_language === MarkupToHtml.MARKUP_LANGUAGE_MARKDOWN;
|
|
|
|
}
|
2019-06-20 01:02:13 +02:00
|
|
|
|
2020-05-07 01:31:18 +02:00
|
|
|
for (const itemId of singleNoteMenuItems) {
|
|
|
|
const menuItem = Menu.getApplicationMenu().getMenuItemById(itemId);
|
2019-06-20 01:02:13 +02:00
|
|
|
if (!menuItem) continue;
|
2020-05-07 01:31:18 +02:00
|
|
|
menuItem.enabled = selectedNoteIds.length === 1;
|
2019-06-20 01:02:13 +02:00
|
|
|
}
|
2019-12-17 19:06:55 +02:00
|
|
|
|
2020-05-27 18:21:46 +02:00
|
|
|
const sortNoteReverseItem = Menu.getApplicationMenu().getMenuItemById('sort:notes:reverse');
|
|
|
|
sortNoteReverseItem.enabled = state.settings['notes.sortOrder.field'] !== 'order';
|
|
|
|
|
2019-12-17 19:06:55 +02:00
|
|
|
const menuItem = Menu.getApplicationMenu().getMenuItemById('help:toggleDevTools');
|
|
|
|
menuItem.checked = state.devToolsVisible;
|
2019-06-20 01:02:13 +02:00
|
|
|
}
|
|
|
|
|
2020-05-21 01:47:38 +02:00
|
|
|
bridge_nativeThemeUpdated() {
|
|
|
|
this.handleThemeAutoDetect();
|
|
|
|
}
|
|
|
|
|
2018-01-31 22:10:32 +02:00
|
|
|
updateTray() {
|
|
|
|
const app = bridge().electronApp();
|
|
|
|
|
2018-03-09 22:59:12 +02:00
|
|
|
if (app.trayShown() === Setting.value('showTrayIcon')) return;
|
2018-01-31 22:10:32 +02:00
|
|
|
|
2018-03-09 22:59:12 +02:00
|
|
|
if (!Setting.value('showTrayIcon')) {
|
2018-01-31 22:10:32 +02:00
|
|
|
app.destroyTray();
|
|
|
|
} else {
|
|
|
|
const contextMenu = Menu.buildFromTemplate([
|
2020-01-26 19:32:00 +02:00
|
|
|
{ label: _('Open %s', app.electronApp().name), click: () => { app.window().show(); } },
|
2018-03-09 22:59:12 +02:00
|
|
|
{ type: 'separator' },
|
2019-07-30 09:35:42 +02:00
|
|
|
{ label: _('Exit'), click: () => { app.quit(); } },
|
|
|
|
]);
|
2018-01-31 22:10:32 +02:00
|
|
|
app.createTray(contextMenu);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-02 20:16:48 +02:00
|
|
|
updateEditorFont() {
|
|
|
|
const fontFamilies = [];
|
2019-09-19 23:51:18 +02:00
|
|
|
if (Setting.value('style.editor.fontFamily')) fontFamilies.push(`"${Setting.value('style.editor.fontFamily')}"`);
|
2018-03-09 22:59:12 +02:00
|
|
|
fontFamilies.push('monospace');
|
2018-03-02 20:16:48 +02:00
|
|
|
|
|
|
|
// The '*' and '!important' parts are necessary to make sure Russian text is displayed properly
|
|
|
|
// https://github.com/laurent22/joplin/issues/155
|
2018-03-02 20:24:02 +02:00
|
|
|
|
2020-06-06 17:00:20 +02:00
|
|
|
const css = `.CodeMirror * { font-family: ${fontFamilies.join(', ')} !important; }`;
|
|
|
|
const ace_css = `.ace_editor * { font-family: ${fontFamilies.join(', ')} !important; }`;
|
2018-03-09 22:59:12 +02:00
|
|
|
const styleTag = document.createElement('style');
|
|
|
|
styleTag.type = 'text/css';
|
2018-03-02 20:16:48 +02:00
|
|
|
styleTag.appendChild(document.createTextNode(css));
|
2020-06-06 17:00:20 +02:00
|
|
|
styleTag.appendChild(document.createTextNode(ace_css));
|
2018-03-02 20:16:48 +02:00
|
|
|
document.head.appendChild(styleTag);
|
|
|
|
}
|
|
|
|
|
2018-11-08 00:52:31 +02:00
|
|
|
async loadCustomCss(filePath) {
|
|
|
|
let cssString = '';
|
|
|
|
if (await fs.pathExists(filePath)) {
|
|
|
|
try {
|
|
|
|
cssString = await fs.readFile(filePath, 'utf-8');
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
let msg = error.message ? error.message : '';
|
2019-09-19 23:51:18 +02:00
|
|
|
msg = `Could not load custom css from ${filePath}\n${msg}`;
|
2018-11-08 00:52:31 +02:00
|
|
|
error.message = msg;
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return cssString;
|
|
|
|
}
|
|
|
|
|
2020-01-20 04:19:57 +02:00
|
|
|
// async createManyNotes() {
|
|
|
|
// return;
|
|
|
|
// const folderIds = [];
|
|
|
|
|
|
|
|
// const randomFolderId = (folderIds) => {
|
|
|
|
// if (!folderIds.length) return '';
|
|
|
|
// const idx = Math.floor(Math.random() * folderIds.length);
|
|
|
|
// if (idx > folderIds.length - 1) throw new Error('Invalid index ' + idx + ' / ' + folderIds.length);
|
|
|
|
// return folderIds[idx];
|
|
|
|
// }
|
|
|
|
|
|
|
|
// let rootFolderCount = 0;
|
|
|
|
// let folderCount = 100;
|
|
|
|
|
|
|
|
// for (let i = 0; i < folderCount; i++) {
|
|
|
|
// let parentId = '';
|
|
|
|
|
|
|
|
// if (Math.random() >= 0.9 || rootFolderCount >= folderCount / 10) {
|
|
|
|
// parentId = randomFolderId(folderIds);
|
|
|
|
// } else {
|
|
|
|
// rootFolderCount++;
|
|
|
|
// }
|
|
|
|
|
|
|
|
// const folder = await Folder.save({ title: 'folder' + i, parent_id: parentId });
|
|
|
|
// folderIds.push(folder.id);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// for (let i = 0; i < 10000; i++) {
|
|
|
|
// const parentId = randomFolderId(folderIds);
|
|
|
|
// Note.save({ title: 'note' + i, parent_id: parentId });
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
2017-11-06 20:35:04 +02:00
|
|
|
async start(argv) {
|
2018-04-23 21:50:29 +02:00
|
|
|
const electronIsDev = require('electron-is-dev');
|
|
|
|
|
|
|
|
// If running inside a package, the command line, instead of being "node.exe <path> <flags>" is "joplin.exe <flags>" so
|
|
|
|
// insert an extra argument so that they can be processed in a consistent way everywhere.
|
|
|
|
if (!electronIsDev) argv.splice(1, 0, '.');
|
|
|
|
|
2017-11-06 20:35:04 +02:00
|
|
|
argv = await super.start(argv);
|
|
|
|
|
2019-12-14 12:55:42 +02:00
|
|
|
// Loads app-wide styles. (Markdown preview-specific styles loaded in app.js)
|
|
|
|
const dir = Setting.value('profileDir');
|
|
|
|
const filename = Setting.custom_css_files.JOPLIN_APP;
|
|
|
|
await CssUtils.injectCustomStyles(`${dir}/${filename}`);
|
|
|
|
|
2017-11-28 21:53:29 +02:00
|
|
|
AlarmService.setDriver(new AlarmServiceDriverNode({ appName: packageInfo.build.appId }));
|
2017-11-28 00:50:46 +02:00
|
|
|
AlarmService.setLogger(reg.logger());
|
|
|
|
|
2019-07-30 09:35:42 +02:00
|
|
|
reg.setShowErrorMessageBoxHandler((message) => { bridge().showErrorMessageBox(message); });
|
2017-12-01 19:47:18 +02:00
|
|
|
|
2019-12-17 19:06:55 +02:00
|
|
|
if (Setting.value('flagOpenDevTools')) {
|
|
|
|
bridge().openDevTools();
|
2017-11-17 20:02:01 +02:00
|
|
|
}
|
|
|
|
|
2019-04-01 21:43:13 +02:00
|
|
|
PluginManager.instance().dispatch_ = this.dispatch.bind(this);
|
|
|
|
PluginManager.instance().setLogger(reg.logger());
|
|
|
|
PluginManager.instance().register(pluginClasses);
|
|
|
|
|
2018-03-09 22:59:12 +02:00
|
|
|
this.updateMenu('Main');
|
2017-11-11 14:00:37 +02:00
|
|
|
|
2017-11-06 20:35:04 +02:00
|
|
|
this.initRedux();
|
|
|
|
|
|
|
|
// Since the settings need to be loaded before the store is created, it will never
|
2017-11-08 23:22:24 +02:00
|
|
|
// receive the SETTING_UPDATE_ALL even, which mean state.settings will not be
|
2017-11-06 20:35:04 +02:00
|
|
|
// initialised. So we manually call dispatchUpdateAll() to force an update.
|
|
|
|
Setting.dispatchUpdateAll();
|
|
|
|
|
|
|
|
await FoldersScreenUtils.refreshFolders();
|
|
|
|
|
|
|
|
const tags = await Tag.allWithNotes();
|
|
|
|
|
|
|
|
this.dispatch({
|
2018-03-09 22:59:12 +02:00
|
|
|
type: 'TAG_UPDATE_ALL',
|
2017-12-14 19:58:10 +02:00
|
|
|
items: tags,
|
|
|
|
});
|
|
|
|
|
|
|
|
const masterKeys = await MasterKey.all();
|
|
|
|
|
|
|
|
this.dispatch({
|
2018-03-09 22:59:12 +02:00
|
|
|
type: 'MASTERKEY_UPDATE_ALL',
|
2017-12-14 19:58:10 +02:00
|
|
|
items: masterKeys,
|
2017-11-06 20:35:04 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
this.store().dispatch({
|
2018-03-09 22:59:12 +02:00
|
|
|
type: 'FOLDER_SELECT',
|
|
|
|
id: Setting.value('activeFolderId'),
|
2017-11-06 20:35:04 +02:00
|
|
|
});
|
2017-11-14 12:18:18 +02:00
|
|
|
|
2018-05-09 11:49:31 +02:00
|
|
|
this.store().dispatch({
|
|
|
|
type: 'FOLDER_SET_COLLAPSED_ALL',
|
|
|
|
ids: Setting.value('collapsedFolderIds'),
|
|
|
|
});
|
|
|
|
|
2019-12-13 02:40:58 +02:00
|
|
|
// Loads custom Markdown preview styles
|
|
|
|
const cssString = await CssUtils.loadCustomCss(`${Setting.value('profileDir')}/userstyle.css`);
|
2018-11-08 00:52:31 +02:00
|
|
|
this.store().dispatch({
|
|
|
|
type: 'LOAD_CUSTOM_CSS',
|
2019-07-30 09:35:42 +02:00
|
|
|
css: cssString,
|
2018-11-08 00:52:31 +02:00
|
|
|
});
|
|
|
|
|
2019-07-20 23:13:10 +02:00
|
|
|
const templates = await TemplateUtils.loadTemplates(Setting.value('templateDir'));
|
|
|
|
|
|
|
|
this.store().dispatch({
|
|
|
|
type: 'TEMPLATE_UPDATE_ALL',
|
2019-07-30 09:35:42 +02:00
|
|
|
templates: templates,
|
2019-07-20 23:13:10 +02:00
|
|
|
});
|
|
|
|
|
2019-12-17 19:06:55 +02:00
|
|
|
this.store().dispatch({
|
|
|
|
type: 'NOTE_DEVTOOLS_SET',
|
|
|
|
value: Setting.value('flagOpenDevTools'),
|
|
|
|
});
|
|
|
|
|
2017-11-14 20:02:58 +02:00
|
|
|
// Note: Auto-update currently doesn't work in Linux: it downloads the update
|
|
|
|
// but then doesn't install it on exit.
|
|
|
|
if (shim.isWindows() || shim.isMac()) {
|
2018-01-31 21:34:38 +02:00
|
|
|
const runAutoUpdateCheck = () => {
|
2018-03-09 22:59:12 +02:00
|
|
|
if (Setting.value('autoUpdateEnabled')) {
|
2019-01-12 01:40:05 +02:00
|
|
|
bridge().checkForUpdates(true, bridge().window(), this.checkForUpdateLoggerPath(), { includePreReleases: Setting.value('autoUpdate.includePreReleases') });
|
2017-11-21 21:37:34 +02:00
|
|
|
}
|
2019-07-30 09:35:42 +02:00
|
|
|
};
|
2018-04-15 17:50:39 +02:00
|
|
|
|
2018-02-16 01:05:04 +02:00
|
|
|
// Initial check on startup
|
2019-07-30 09:35:42 +02:00
|
|
|
setTimeout(() => { runAutoUpdateCheck(); }, 5000);
|
2018-02-16 01:05:04 +02:00
|
|
|
// Then every x hours
|
2019-07-30 09:35:42 +02:00
|
|
|
setInterval(() => { runAutoUpdateCheck(); }, 12 * 60 * 60 * 1000);
|
2017-11-14 12:53:18 +02:00
|
|
|
}
|
2017-11-21 21:47:29 +02:00
|
|
|
|
2018-01-31 22:10:32 +02:00
|
|
|
this.updateTray();
|
|
|
|
|
2017-11-28 02:22:38 +02:00
|
|
|
setTimeout(() => {
|
|
|
|
AlarmService.garbageCollect();
|
|
|
|
}, 1000 * 60 * 60);
|
|
|
|
|
2018-09-06 19:56:23 +02:00
|
|
|
if (Setting.value('startMinimized') && Setting.value('showTrayIcon')) {
|
2019-11-05 19:03:24 +02:00
|
|
|
// Keep it hidden
|
|
|
|
} else {
|
|
|
|
bridge().window().show();
|
2018-09-06 19:56:23 +02:00
|
|
|
}
|
|
|
|
|
2018-03-16 16:32:47 +02:00
|
|
|
ResourceService.runInBackground();
|
2018-03-15 20:08:46 +02:00
|
|
|
|
2018-03-09 22:59:12 +02:00
|
|
|
if (Setting.value('env') === 'dev') {
|
2017-11-28 02:22:38 +02:00
|
|
|
AlarmService.updateAllNotifications();
|
2017-11-30 20:36:26 +02:00
|
|
|
} else {
|
|
|
|
reg.scheduleSync().then(() => {
|
|
|
|
// Wait for the first sync before updating the notifications, since synchronisation
|
|
|
|
// might change the notifications.
|
|
|
|
AlarmService.updateAllNotifications();
|
2017-12-21 21:06:08 +02:00
|
|
|
|
|
|
|
DecryptionWorker.instance().scheduleStart();
|
2017-11-30 20:36:26 +02:00
|
|
|
});
|
|
|
|
}
|
2018-05-25 14:30:27 +02:00
|
|
|
|
|
|
|
const clipperLogger = new Logger();
|
2019-09-19 23:51:18 +02:00
|
|
|
clipperLogger.addTarget('file', { path: `${Setting.value('profileDir')}/log-clipper.txt` });
|
2018-05-25 14:30:27 +02:00
|
|
|
clipperLogger.addTarget('console');
|
|
|
|
|
|
|
|
ClipperServer.instance().setLogger(clipperLogger);
|
|
|
|
ClipperServer.instance().setDispatch(this.store().dispatch);
|
|
|
|
|
|
|
|
if (Setting.value('clipperServer.autoStart')) {
|
|
|
|
ClipperServer.instance().start();
|
|
|
|
}
|
2018-11-21 21:50:50 +02:00
|
|
|
|
|
|
|
ExternalEditWatcher.instance().setLogger(reg.logger());
|
|
|
|
ExternalEditWatcher.instance().dispatch = this.store().dispatch;
|
2019-05-06 22:35:29 +02:00
|
|
|
|
2020-05-30 14:25:05 +02:00
|
|
|
ResourceEditWatcher.instance().initialize(reg.logger(), this.store().dispatch);
|
|
|
|
|
2019-05-06 22:35:29 +02:00
|
|
|
RevisionService.instance().runInBackground();
|
|
|
|
|
2019-06-20 01:02:13 +02:00
|
|
|
this.updateMenuItemStates();
|
|
|
|
|
2019-05-06 22:35:29 +02:00
|
|
|
// Make it available to the console window - useful to call revisionService.collectRevisions()
|
|
|
|
window.revisionService = RevisionService.instance();
|
2019-05-12 12:41:07 +02:00
|
|
|
window.migrationService = MigrationService.instance();
|
2019-06-08 00:11:08 +02:00
|
|
|
window.decryptionWorker = DecryptionWorker.instance();
|
2020-05-21 01:47:38 +02:00
|
|
|
|
|
|
|
bridge().addEventListener('nativeThemeUpdated', this.bridge_nativeThemeUpdated);
|
2017-11-04 14:23:46 +02:00
|
|
|
}
|
2018-03-09 22:59:12 +02:00
|
|
|
|
2017-11-04 14:23:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
let application_ = null;
|
|
|
|
|
|
|
|
function app() {
|
2017-11-05 02:17:48 +02:00
|
|
|
if (!application_) application_ = new Application();
|
2017-11-04 14:23:46 +02:00
|
|
|
return application_;
|
|
|
|
}
|
|
|
|
|
2018-04-16 19:27:36 +02:00
|
|
|
module.exports = { app };
|