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 BaseModel = require('lib/BaseModel.js');
|
|
|
|
const MasterKey = require('lib/models/MasterKey');
|
|
|
|
const { _, setLocale } = require('lib/locale.js');
|
|
|
|
const os = require('os');
|
|
|
|
const fs = require('fs-extra');
|
|
|
|
const Tag = require('lib/models/Tag.js');
|
|
|
|
const { reg } = require('lib/registry.js');
|
|
|
|
const { sprintf } = require('sprintf-js');
|
|
|
|
const { JoplinDatabase } = require('lib/joplin-database.js');
|
|
|
|
const { DatabaseDriverNode } = require('lib/database-driver-node.js');
|
|
|
|
const { ElectronAppWrapper } = require('./ElectronAppWrapper');
|
|
|
|
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-03-09 22:59:12 +02:00
|
|
|
|
|
|
|
const { bridge } = require('electron').remote.require('./bridge');
|
2017-11-11 14:00:37 +02:00
|
|
|
const Menu = bridge().Menu;
|
|
|
|
const MenuItem = bridge().MenuItem;
|
|
|
|
|
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,
|
2017-11-14 20:02:58 +02:00
|
|
|
windowContentSize: bridge().windowContentSize(),
|
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;
|
2018-06-10 13:19:36 +02:00
|
|
|
this.powerSaveBlockerId_ = null;
|
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() {
|
2018-03-09 22:59:12 +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
|
|
|
|
|
|
|
case 'NAV_BACK':
|
|
|
|
case 'NAV_GO':
|
|
|
|
|
|
|
|
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);
|
|
|
|
let newNavHistory = state.navHistory.slice();
|
|
|
|
|
|
|
|
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);
|
2018-03-09 22:59:12 +02:00
|
|
|
newState.navHistory = newNavHistory
|
2017-11-06 20:35:04 +02:00
|
|
|
newState.route = action;
|
|
|
|
break;
|
2017-11-04 15:23:15 +02:00
|
|
|
|
2018-03-09 22:59:12 +02:00
|
|
|
case 'WINDOW_CONTENT_SIZE_SET':
|
|
|
|
|
2017-11-06 20:35:04 +02:00
|
|
|
newState = Object.assign({}, state);
|
|
|
|
newState.windowContentSize = action.size;
|
|
|
|
break;
|
2017-11-04 15:23:15 +02:00
|
|
|
|
2018-03-09 22:59:12 +02:00
|
|
|
case 'WINDOW_COMMAND':
|
|
|
|
|
2017-11-11 19:36:47 +02:00
|
|
|
newState = Object.assign({}, state);
|
2017-11-12 01:13:14 +02:00
|
|
|
let command = Object.assign({}, action);
|
|
|
|
delete command.type;
|
|
|
|
newState.windowCommand = command;
|
2017-11-11 19:36:47 +02:00
|
|
|
break;
|
|
|
|
|
2018-03-09 22:59:12 +02:00
|
|
|
case 'NOTE_VISIBLE_PANES_TOGGLE':
|
|
|
|
|
2017-11-12 19:02:20 +02:00
|
|
|
let panes = state.noteVisiblePanes.slice();
|
|
|
|
if (panes.length === 2) {
|
2018-03-09 22:59:12 +02:00
|
|
|
panes = ['editor'];
|
|
|
|
} else if (panes.indexOf('editor') >= 0) {
|
|
|
|
panes = ['viewer'];
|
|
|
|
} else if (panes.indexOf('viewer') >= 0) {
|
|
|
|
panes = ['editor', 'viewer'];
|
2017-11-12 19:02:20 +02:00
|
|
|
} else {
|
2018-03-09 22:59:12 +02:00
|
|
|
panes = ['editor', 'viewer'];
|
2017-11-12 19:02:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
newState = Object.assign({}, state);
|
|
|
|
newState.noteVisiblePanes = panes;
|
|
|
|
break;
|
|
|
|
|
2018-03-09 22:59:12 +02:00
|
|
|
case 'NOTE_VISIBLE_PANES_SET':
|
2018-04-15 17:50:39 +02:00
|
|
|
|
2017-11-12 19:02:20 +02:00
|
|
|
newState = Object.assign({}, state);
|
|
|
|
newState.noteVisiblePanes = action.panes;
|
|
|
|
break;
|
2018-03-09 22:59:12 +02:00
|
|
|
|
2018-04-15 17:50:39 +02:00
|
|
|
case 'SIDEBAR_VISIBILITY_TOGGLE':
|
|
|
|
|
|
|
|
newState = Object.assign({}, state);
|
|
|
|
newState.sidebarVisibility = !state.sidebarVisibility;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'SIDEBAR_VISIBILITY_SET':
|
|
|
|
newState = Object.assign({}, state);
|
|
|
|
newState.sidebarVisibility = action.visibility;
|
|
|
|
break;
|
|
|
|
|
2017-11-06 20:35:04 +02:00
|
|
|
}
|
2017-11-04 15:23:15 +02:00
|
|
|
} catch (error) {
|
2018-03-09 22:59:12 +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);
|
|
|
|
}
|
|
|
|
|
2017-11-10 20:58:00 +02:00
|
|
|
async generalMiddleware(store, next, action) {
|
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
|
|
|
|
// so it needs to be set too here.
|
|
|
|
bridge().setLocale(Setting.value('locale'));
|
2017-11-12 02:44:26 +02:00
|
|
|
this.refreshMenu();
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2018-03-09 19:49:35 +02:00
|
|
|
if (["NOTE_UPDATE_ONE", "NOTE_DELETE", "FOLDER_UPDATE_ONE", "FOLDER_DELETE"].indexOf(action.type) >= 0) {
|
2018-05-10 20:50:44 +02:00
|
|
|
if (!await reg.syncTarget().syncStarted()) reg.scheduleSync(30 * 1000, { syncSteps: ["update_remote", "delete_remote"] });
|
2017-11-12 19:02:20 +02:00
|
|
|
}
|
2017-11-10 20:58:00 +02:00
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2018-06-10 13:19:36 +02:00
|
|
|
if (action.type === 'SYNC_STARTED') {
|
|
|
|
if (!this.powerSaveBlockerId_) this.powerSaveBlockerId_ = bridge().powerSaveBlockerStart('prevent-app-suspension');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action.type === 'SYNC_COMPLETED') {
|
|
|
|
if (this.powerSaveBlockerId_) {
|
|
|
|
bridge().powerSaveBlockerStop(this.powerSaveBlockerId_);
|
|
|
|
this.powerSaveBlockerId_ = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2017-11-12 02:44:26 +02:00
|
|
|
refreshMenu() {
|
|
|
|
const screen = this.lastMenuScreen_;
|
|
|
|
this.lastMenuScreen_ = null;
|
|
|
|
this.updateMenu(screen);
|
2017-11-10 20:58:00 +02:00
|
|
|
}
|
|
|
|
|
2017-11-11 19:36:47 +02:00
|
|
|
updateMenu(screen) {
|
|
|
|
if (this.lastMenuScreen_ === screen) return;
|
|
|
|
|
2018-02-22 20:58:15 +02:00
|
|
|
const sortNoteItems = [];
|
2018-03-09 22:59:12 +02:00
|
|
|
const sortNoteOptions = Setting.enumOptions('notes.sortOrder.field');
|
2018-02-22 20:58:15 +02:00
|
|
|
for (let field in sortNoteOptions) {
|
|
|
|
if (!sortNoteOptions.hasOwnProperty(field)) continue;
|
|
|
|
sortNoteItems.push({
|
|
|
|
label: sortNoteOptions[field],
|
2018-03-09 22:59:12 +02:00
|
|
|
screens: ['Main'],
|
|
|
|
type: 'checkbox',
|
|
|
|
checked: Setting.value('notes.sortOrder.field') === field,
|
2018-02-22 20:58:15 +02:00
|
|
|
click: () => {
|
2018-03-09 22:59:12 +02:00
|
|
|
Setting.setValue('notes.sortOrder.field', field);
|
2018-02-22 20:58:15 +02:00
|
|
|
this.refreshMenu();
|
2018-03-09 22:59:12 +02:00
|
|
|
}
|
2018-04-15 17:50:39 +02:00
|
|
|
});
|
2018-02-22 20:58:15 +02:00
|
|
|
}
|
|
|
|
|
2018-02-27 22:04:38 +02:00
|
|
|
const importItems = [];
|
|
|
|
const exportItems = [];
|
|
|
|
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') {
|
2018-02-27 22:04:38 +02:00
|
|
|
exportItems.push({
|
2018-03-12 20:01:47 +02:00
|
|
|
label: module.fullLabel(),
|
2018-03-09 22:59:12 +02:00
|
|
|
screens: ['Main'],
|
2018-02-27 22:04:38 +02:00
|
|
|
click: async () => {
|
2018-03-01 22:14:06 +02:00
|
|
|
await InteropServiceHelper.export(this.dispatch.bind(this), module);
|
2018-03-09 22:59:12 +02:00
|
|
|
}
|
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({
|
2018-03-09 22:59:12 +02:00
|
|
|
filters: [{ name: module.description, extensions: [module.fileExtension]}]
|
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),
|
|
|
|
});
|
|
|
|
|
|
|
|
const importOptions = {};
|
|
|
|
importOptions.path = path;
|
|
|
|
importOptions.format = module.format;
|
2018-03-09 22:59:12 +02:00
|
|
|
importOptions.destinationFolderId = !module.isNoteArchive && moduleSource === 'file' ? selectedFolderId : null;
|
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
|
|
|
});
|
2018-03-09 22:59:12 +02:00
|
|
|
}
|
2018-02-27 22:04:38 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-12 20:01:47 +02:00
|
|
|
exportItems.push({
|
|
|
|
label: 'PDF - ' + _('PDF File'),
|
|
|
|
screens: ['Main'],
|
|
|
|
click: async () => {
|
|
|
|
this.dispatch({
|
|
|
|
type: 'WINDOW_COMMAND',
|
|
|
|
name: 'exportPdf',
|
2018-04-15 17:50:39 +02:00
|
|
|
});
|
2018-03-12 20:01:47 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-11-11 14:00:37 +02:00
|
|
|
const template = [
|
|
|
|
{
|
2018-03-09 22:59:12 +02:00
|
|
|
label: _('File'),
|
|
|
|
submenu: [{
|
|
|
|
label: _('New note'),
|
|
|
|
accelerator: 'CommandOrControl+N',
|
|
|
|
screens: ['Main'],
|
|
|
|
click: () => {
|
|
|
|
this.dispatch({
|
|
|
|
type: 'WINDOW_COMMAND',
|
|
|
|
name: 'newNote',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
label: _('New to-do'),
|
|
|
|
accelerator: 'CommandOrControl+T',
|
|
|
|
screens: ['Main'],
|
|
|
|
click: () => {
|
|
|
|
this.dispatch({
|
|
|
|
type: 'WINDOW_COMMAND',
|
|
|
|
name: 'newTodo',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
label: _('New notebook'),
|
|
|
|
accelerator: 'CommandOrControl+B',
|
|
|
|
screens: ['Main'],
|
|
|
|
click: () => {
|
|
|
|
this.dispatch({
|
|
|
|
type: 'WINDOW_COMMAND',
|
|
|
|
name: 'newNotebook',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
type: 'separator',
|
|
|
|
}, {
|
|
|
|
label: _('Import'),
|
|
|
|
submenu: importItems,
|
|
|
|
}, {
|
|
|
|
label: _('Export'),
|
|
|
|
submenu: exportItems,
|
2018-03-12 20:01:47 +02:00
|
|
|
}, {
|
|
|
|
type: 'separator',
|
|
|
|
}, {
|
|
|
|
label: _('Print'),
|
|
|
|
accelerator: 'CommandOrControl+P',
|
|
|
|
screens: ['Main'],
|
|
|
|
click: () => {
|
|
|
|
this.dispatch({
|
|
|
|
type: 'WINDOW_COMMAND',
|
|
|
|
name: 'print',
|
|
|
|
});
|
|
|
|
}
|
2018-03-09 22:59:12 +02:00
|
|
|
}, {
|
|
|
|
type: 'separator',
|
|
|
|
platforms: ['darwin'],
|
|
|
|
}, {
|
|
|
|
label: _('Hide %s', 'Joplin'),
|
|
|
|
platforms: ['darwin'],
|
|
|
|
accelerator: 'CommandOrControl+H',
|
|
|
|
click: () => { bridge().electronApp().hide() }
|
|
|
|
}, {
|
|
|
|
type: 'separator',
|
|
|
|
}, {
|
|
|
|
label: _('Quit'),
|
|
|
|
accelerator: 'CommandOrControl+Q',
|
|
|
|
click: () => { bridge().electronApp().quit() }
|
|
|
|
}]
|
|
|
|
}, {
|
|
|
|
label: _('Edit'),
|
|
|
|
submenu: [{
|
|
|
|
label: _('Copy'),
|
|
|
|
role: 'copy',
|
|
|
|
accelerator: 'CommandOrControl+C',
|
|
|
|
}, {
|
|
|
|
label: _('Cut'),
|
|
|
|
role: 'cut',
|
|
|
|
accelerator: 'CommandOrControl+X',
|
|
|
|
}, {
|
|
|
|
label: _('Paste'),
|
|
|
|
role: 'paste',
|
|
|
|
accelerator: 'CommandOrControl+V',
|
|
|
|
}, {
|
|
|
|
type: 'separator',
|
|
|
|
screens: ['Main'],
|
2018-06-12 00:47:44 +02:00
|
|
|
}, {
|
|
|
|
label: _('Bold'),
|
|
|
|
screens: ['Main'],
|
|
|
|
accelerator: 'CommandOrControl+B',
|
|
|
|
click: () => {
|
|
|
|
this.dispatch({
|
|
|
|
type: 'WINDOW_COMMAND',
|
|
|
|
name: 'textBold',
|
|
|
|
});
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
label: _('Italic'),
|
|
|
|
screens: ['Main'],
|
|
|
|
accelerator: 'CommandOrControl+I',
|
|
|
|
click: () => {
|
|
|
|
this.dispatch({
|
|
|
|
type: 'WINDOW_COMMAND',
|
|
|
|
name: 'textItalic',
|
|
|
|
});
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
type: 'separator',
|
|
|
|
screens: ['Main'],
|
2018-03-09 22:59:12 +02:00
|
|
|
}, {
|
|
|
|
label: _('Search in all the notes'),
|
|
|
|
screens: ['Main'],
|
2018-03-20 01:04:48 +02:00
|
|
|
accelerator: 'CommandOrControl+F',
|
2018-03-09 22:59:12 +02:00
|
|
|
click: () => {
|
|
|
|
this.dispatch({
|
|
|
|
type: 'WINDOW_COMMAND',
|
2018-03-20 01:04:48 +02:00
|
|
|
name: 'focus_search',
|
2018-03-09 22:59:12 +02:00
|
|
|
});
|
|
|
|
},
|
|
|
|
}],
|
|
|
|
}, {
|
|
|
|
label: _('View'),
|
|
|
|
submenu: [{
|
2018-04-16 19:27:36 +02:00
|
|
|
label: _('Toggle sidebar'),
|
|
|
|
screens: ['Main'],
|
|
|
|
accelerator: 'F10',
|
|
|
|
click: () => {
|
|
|
|
this.dispatch({
|
|
|
|
type: 'WINDOW_COMMAND',
|
|
|
|
name: 'toggleSidebar',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, {
|
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',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
type: 'separator',
|
|
|
|
screens: ['Main'],
|
|
|
|
}, {
|
|
|
|
label: Setting.settingMetadata('notes.sortOrder.field').label(),
|
|
|
|
screens: ['Main'],
|
|
|
|
submenu: sortNoteItems,
|
|
|
|
}, {
|
|
|
|
label: Setting.settingMetadata('notes.sortOrder.reverse').label(),
|
|
|
|
type: 'checkbox',
|
|
|
|
checked: Setting.value('notes.sortOrder.reverse'),
|
|
|
|
screens: ['Main'],
|
|
|
|
click: () => {
|
|
|
|
Setting.setValue('notes.sortOrder.reverse', !Setting.value('notes.sortOrder.reverse'));
|
2018-03-09 19:49:35 +02:00
|
|
|
},
|
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'));
|
|
|
|
},
|
2018-03-09 22:59:12 +02:00
|
|
|
}],
|
|
|
|
}, {
|
|
|
|
label: _('Tools'),
|
|
|
|
submenu: [{
|
|
|
|
label: _('Synchronisation status'),
|
|
|
|
click: () => {
|
|
|
|
this.dispatch({
|
|
|
|
type: 'NAV_GO',
|
|
|
|
routeName: 'Status',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
type: 'separator',
|
|
|
|
screens: ['Main'],
|
2018-05-25 14:30:27 +02:00
|
|
|
},{
|
|
|
|
label: _('Web clipper options'),
|
|
|
|
click: () => {
|
|
|
|
this.dispatch({
|
|
|
|
type: 'NAV_GO',
|
|
|
|
routeName: 'ClipperConfig',
|
|
|
|
});
|
|
|
|
}
|
2018-03-09 22:59:12 +02:00
|
|
|
},{
|
|
|
|
label: _('Encryption options'),
|
|
|
|
click: () => {
|
|
|
|
this.dispatch({
|
|
|
|
type: 'NAV_GO',
|
|
|
|
routeName: 'EncryptionConfig',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},{
|
|
|
|
label: _('General Options'),
|
|
|
|
accelerator: 'CommandOrControl+,',
|
|
|
|
click: () => {
|
|
|
|
this.dispatch({
|
|
|
|
type: 'NAV_GO',
|
|
|
|
routeName: 'Config',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}],
|
|
|
|
}, {
|
|
|
|
label: _('Help'),
|
|
|
|
submenu: [{
|
|
|
|
label: _('Website and documentation'),
|
|
|
|
accelerator: 'F1',
|
2018-03-24 22:13:52 +02:00
|
|
|
click () { bridge().openExternal('https://joplin.cozic.net') }
|
2018-03-09 22:59:12 +02:00
|
|
|
}, {
|
|
|
|
label: _('Make a donation'),
|
2018-03-24 22:13:52 +02:00
|
|
|
click () { bridge().openExternal('https://joplin.cozic.net/donate') }
|
2018-03-09 22:59:12 +02:00
|
|
|
}, {
|
|
|
|
label: _('Check for updates...'),
|
|
|
|
click: () => {
|
|
|
|
bridge().checkForUpdates(false, bridge().window(), this.checkForUpdateLoggerPath());
|
|
|
|
}
|
|
|
|
}, {
|
|
|
|
type: 'separator',
|
|
|
|
screens: ['Main'],
|
|
|
|
}, {
|
|
|
|
label: _('About Joplin'),
|
|
|
|
click: () => {
|
|
|
|
const p = packageInfo;
|
|
|
|
let message = [
|
|
|
|
p.description,
|
|
|
|
'',
|
|
|
|
'Copyright © 2016-2018 Laurent Cozic',
|
|
|
|
_('%s %s (%s, %s)', p.name, p.version, Setting.value('env'), process.platform),
|
|
|
|
];
|
|
|
|
bridge().showInfoMessageBox(message.join('\n'), {
|
|
|
|
icon: bridge().electronApp().buildDir() + '/icons/32x32.png',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}]
|
2017-11-11 14:00:37 +02:00
|
|
|
},
|
2017-11-11 19:36:47 +02:00
|
|
|
];
|
|
|
|
|
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
|
|
|
|
let temp = [];
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
let screenTemplate = removeUnwantedItems(template, screen);
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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([
|
2018-03-09 22:59:12 +02:00
|
|
|
{ label: _('Open %s', app.electronApp().getName()), click: () => { app.window().show(); } },
|
|
|
|
{ type: 'separator' },
|
|
|
|
{ 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 = [];
|
2018-03-09 22:59:12 +02:00
|
|
|
if (Setting.value('style.editor.fontFamily')) fontFamilies.push('"' + Setting.value('style.editor.fontFamily') + '"');
|
|
|
|
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
|
|
|
|
2018-03-09 22:59:12 +02:00
|
|
|
const css = '.ace_editor * { font-family: ' + fontFamilies.join(', ') + ' !important; }';
|
|
|
|
const styleTag = document.createElement('style');
|
|
|
|
styleTag.type = 'text/css';
|
2018-03-02 20:16:48 +02:00
|
|
|
styleTag.appendChild(document.createTextNode(css));
|
|
|
|
document.head.appendChild(styleTag);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
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());
|
|
|
|
|
2018-03-09 22:59:12 +02:00
|
|
|
reg.setShowErrorMessageBoxHandler((message) => { bridge().showErrorMessageBox(message) });
|
2017-12-01 19:47:18 +02:00
|
|
|
|
2018-03-09 22:59:12 +02:00
|
|
|
if (Setting.value('openDevTools')) {
|
|
|
|
bridge().window().webContents.openDevTools();
|
2017-11-17 20:02:01 +02:00
|
|
|
}
|
|
|
|
|
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'),
|
|
|
|
});
|
|
|
|
|
2018-06-10 13:19:36 +02:00
|
|
|
if (shim.isLinux()) bridge().setAllowPowerSaveBlockerToggle(true);
|
|
|
|
|
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')) {
|
2018-02-16 01:05:04 +02:00
|
|
|
bridge().checkForUpdates(true, bridge().window(), this.checkForUpdateLoggerPath());
|
2017-11-21 21:37:34 +02:00
|
|
|
}
|
2018-03-09 22:59:12 +02:00
|
|
|
}
|
2018-04-15 17:50:39 +02:00
|
|
|
|
2018-02-16 01:05:04 +02:00
|
|
|
// Initial check on startup
|
2018-03-09 22:59:12 +02:00
|
|
|
setTimeout(() => { runAutoUpdateCheck() }, 5000);
|
2018-02-16 01:05:04 +02:00
|
|
|
// Then every x hours
|
2018-03-09 22:59:12 +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-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();
|
|
|
|
clipperLogger.addTarget('file', { path: Setting.value('profileDir') + '/log-clipper.txt' });
|
|
|
|
clipperLogger.addTarget('console');
|
|
|
|
|
|
|
|
ClipperServer.instance().setLogger(clipperLogger);
|
|
|
|
ClipperServer.instance().setDispatch(this.store().dispatch);
|
|
|
|
|
|
|
|
if (Setting.value('clipperServer.autoStart')) {
|
|
|
|
ClipperServer.instance().start();
|
|
|
|
}
|
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 };
|