mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Various clean up and tweaks for Electron app
This commit is contained in:
parent
b10b5566f7
commit
056c0dbab7
@ -312,9 +312,7 @@ class Application extends BaseApplication {
|
||||
}
|
||||
}
|
||||
} else { // Otherwise open the GUI
|
||||
this.store_ = createStore(reducer, applyMiddleware(this.generalMiddleware()));
|
||||
BaseModel.dispatch = this.store().dispatch;
|
||||
FoldersScreenUtils.dispatch = this.store().dispatch;
|
||||
this.initRedux();
|
||||
|
||||
const AppGui = require('./app-gui.js');
|
||||
this.gui_ = new AppGui(this, this.store());
|
||||
|
@ -14,7 +14,7 @@ const { Tag } = require('lib/models/tag.js');
|
||||
const { NoteTag } = require('lib/models/note-tag.js');
|
||||
const { Setting } = require('lib/models/setting.js');
|
||||
const { Logger } = require('lib/logger.js');
|
||||
const { FsDriverNode } = require('./fs-driver-node.js');
|
||||
const { FsDriverNode } = require('lib/fs-driver-node.js');
|
||||
const { shimInit } = require('lib/shim-init-node.js');
|
||||
const { _ } = require('lib/locale.js');
|
||||
|
||||
|
@ -5,14 +5,23 @@ const path = require('path')
|
||||
|
||||
class ElectronAppWrapper {
|
||||
|
||||
constructor(electronApp) {
|
||||
constructor(electronApp, app, store) {
|
||||
this.app_ = app;
|
||||
this.electronApp_ = electronApp;
|
||||
this.loadState_ = 'start';
|
||||
this.store_ = store;
|
||||
this.win_ = null;
|
||||
}
|
||||
|
||||
this.electronApp_.on('ready', () => {
|
||||
this.loadState_ = 'ready';
|
||||
});
|
||||
electronApp() {
|
||||
return this.electronApp_;
|
||||
}
|
||||
|
||||
setLogger(v) {
|
||||
this.logger_ = v;
|
||||
}
|
||||
|
||||
logger() {
|
||||
return this.logger_;
|
||||
}
|
||||
|
||||
createWindow() {
|
||||
@ -39,11 +48,11 @@ class ElectronAppWrapper {
|
||||
}
|
||||
|
||||
async waitForElectronAppReady() {
|
||||
if (this.loadState_ === 'ready') return Promise.resolve();
|
||||
if (this.electronApp().isReady()) return Promise.resolve();
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const iid = setInterval(() => {
|
||||
if (this.loadState_ === 'ready') {
|
||||
if (this.electronApp().isReady()) {
|
||||
clearInterval(iid);
|
||||
resolve();
|
||||
}
|
||||
@ -51,6 +60,10 @@ class ElectronAppWrapper {
|
||||
});
|
||||
}
|
||||
|
||||
async exit() {
|
||||
this.electronApp_.quit();
|
||||
}
|
||||
|
||||
async start() {
|
||||
// Since we are doing other async things before creating the window, we might miss
|
||||
// the "ready" event. So we use the function below to make sure that the app is ready.
|
||||
|
@ -1,10 +1,12 @@
|
||||
const { BaseApplication } = require('lib/BaseApplication');
|
||||
const { FoldersScreenUtils } = require('lib/folders-screen-utils.js');
|
||||
const { Setting } = require('lib/models/setting.js');
|
||||
const { BaseModel } = require('lib/base-model.js');
|
||||
const { _ } = require('lib/locale.js');
|
||||
const os = require('os');
|
||||
const fs = require('fs-extra');
|
||||
const { Logger } = require('lib/logger.js');
|
||||
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');
|
||||
@ -16,7 +18,7 @@ class Application extends BaseApplication {
|
||||
constructor(electronApp) {
|
||||
super();
|
||||
|
||||
this.gui_ = new ElectronAppWrapper(electronApp);
|
||||
this.electronApp_ = electronApp;
|
||||
}
|
||||
|
||||
gui() {
|
||||
@ -26,7 +28,36 @@ class Application extends BaseApplication {
|
||||
async start(argv) {
|
||||
argv = await super.start(argv);
|
||||
|
||||
await this.gui().start();
|
||||
this.initRedux();
|
||||
|
||||
this.gui_ = new ElectronAppWrapper(this.electronApp_, this, this.store());
|
||||
|
||||
try {
|
||||
this.gui_.setLogger(this.logger());
|
||||
await this.gui().start();
|
||||
|
||||
// Since the settings need to be loaded before the store is created, it will never
|
||||
// receive the SETTINGS_UPDATE_ALL even, which mean state.settings will not be
|
||||
// initialised. So we manually call dispatchUpdateAll() to force an update.
|
||||
Setting.dispatchUpdateAll();
|
||||
|
||||
await FoldersScreenUtils.refreshFolders();
|
||||
|
||||
const tags = await Tag.allWithNotes();
|
||||
|
||||
this.dispatch({
|
||||
type: 'TAGS_UPDATE_ALL',
|
||||
tags: tags,
|
||||
});
|
||||
|
||||
this.store().dispatch({
|
||||
type: 'FOLDERS_SELECT',
|
||||
id: Setting.value('activeFolderId'),
|
||||
});
|
||||
} catch (error) {
|
||||
await this.gui_.exit();
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,13 +2,40 @@
|
||||
require('app-module-path').addPath(__dirname);
|
||||
|
||||
const electronApp = require('electron').app;
|
||||
const { initApp } = require('./app');
|
||||
const { initApp } = require('./app.js');
|
||||
const { Folder } = require('lib/models/folder.js');
|
||||
const { Resource } = require('lib/models/resource.js');
|
||||
const { BaseItem } = require('lib/models/base-item.js');
|
||||
const { Note } = require('lib/models/note.js');
|
||||
const { Tag } = require('lib/models/tag.js');
|
||||
const { NoteTag } = require('lib/models/note-tag.js');
|
||||
const { Setting } = require('lib/models/setting.js');
|
||||
const { Logger } = require('lib/logger.js');
|
||||
const { FsDriverNode } = require('lib/fs-driver-node.js');
|
||||
const { shimInit } = require('lib/shim-init-node.js');
|
||||
|
||||
process.on('unhandledRejection', (reason, p) => {
|
||||
console.error('Unhandled promise rejection', p, 'reason:', reason);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
const fsDriver = new FsDriverNode();
|
||||
Logger.fsDriver_ = fsDriver;
|
||||
Resource.fsDriver_ = fsDriver;
|
||||
|
||||
// That's not good, but it's to avoid circular dependency issues
|
||||
// in the BaseItem class.
|
||||
BaseItem.loadClass('Note', Note);
|
||||
BaseItem.loadClass('Folder', Folder);
|
||||
BaseItem.loadClass('Resource', Resource);
|
||||
BaseItem.loadClass('Tag', Tag);
|
||||
BaseItem.loadClass('NoteTag', NoteTag);
|
||||
|
||||
Setting.setConstant('appId', 'net.cozic.joplin-desktop');
|
||||
Setting.setConstant('appType', 'desktop');
|
||||
|
||||
shimInit();
|
||||
|
||||
const app = initApp(electronApp);
|
||||
|
||||
app.start(process.argv).catch((error) => {
|
||||
|
58
ElectronClient/app/package-lock.json
generated
58
ElectronClient/app/package-lock.json
generated
@ -663,6 +663,11 @@
|
||||
"integrity": "sha1-SLaZwn4zS/ifEIkr5DL25MfTSn8=",
|
||||
"dev": true
|
||||
},
|
||||
"deep-is": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.2.tgz",
|
||||
"integrity": "sha1-nO1l6gvAsJ9CptecGxkD+dkTzBg="
|
||||
},
|
||||
"delayed-stream": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
|
||||
@ -1006,6 +1011,14 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"encoding": {
|
||||
"version": "0.1.12",
|
||||
"resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.12.tgz",
|
||||
"integrity": "sha1-U4tm8+5izRq1HsMjgp0flIDHS+s=",
|
||||
"requires": {
|
||||
"iconv-lite": "0.4.19"
|
||||
}
|
||||
},
|
||||
"end-of-stream": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.0.tgz",
|
||||
@ -1401,8 +1414,7 @@
|
||||
"iconv-lite": {
|
||||
"version": "0.4.19",
|
||||
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.19.tgz",
|
||||
"integrity": "sha512-oTZqweIP51xaGPI4uPa56/Pri/480R+mo7SeU+YETByQNhDG55ycFyNLIgta9vXhILrxXDmF7ZGhqZIcuN0gJQ==",
|
||||
"dev": true
|
||||
"integrity": "sha512-oTZqweIP51xaGPI4uPa56/Pri/480R+mo7SeU+YETByQNhDG55ycFyNLIgta9vXhILrxXDmF7ZGhqZIcuN0gJQ=="
|
||||
},
|
||||
"import-lazy": {
|
||||
"version": "2.1.0",
|
||||
@ -1547,8 +1559,7 @@
|
||||
"is-stream": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz",
|
||||
"integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=",
|
||||
"dev": true
|
||||
"integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ="
|
||||
},
|
||||
"is-typedarray": {
|
||||
"version": "1.0.0",
|
||||
@ -1562,6 +1573,14 @@
|
||||
"integrity": "sha1-Sw2hRCEE0bM2NA6AeX6GXPOffXI=",
|
||||
"dev": true
|
||||
},
|
||||
"is2": {
|
||||
"version": "0.0.9",
|
||||
"resolved": "https://registry.npmjs.org/is2/-/is2-0.0.9.tgz",
|
||||
"integrity": "sha1-EZVW0dFlGkG6EFr4AyZ8gLKZ9ik=",
|
||||
"requires": {
|
||||
"deep-is": "0.1.2"
|
||||
}
|
||||
},
|
||||
"isarray": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
|
||||
@ -1943,6 +1962,15 @@
|
||||
"lodash.toarray": "4.4.0"
|
||||
}
|
||||
},
|
||||
"node-fetch": {
|
||||
"version": "1.7.3",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz",
|
||||
"integrity": "sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==",
|
||||
"requires": {
|
||||
"encoding": "0.1.12",
|
||||
"is-stream": "1.1.0"
|
||||
}
|
||||
},
|
||||
"node-gyp": {
|
||||
"version": "3.6.2",
|
||||
"resolved": "https://registry.npmjs.org/node-gyp/-/node-gyp-3.6.2.tgz",
|
||||
@ -2381,6 +2409,11 @@
|
||||
"integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4=",
|
||||
"dev": true
|
||||
},
|
||||
"q": {
|
||||
"version": "0.9.7",
|
||||
"resolved": "https://registry.npmjs.org/q/-/q-0.9.7.tgz",
|
||||
"integrity": "sha1-TeLmyzspCIyeTLwDv51C+5bOL3U="
|
||||
},
|
||||
"qs": {
|
||||
"version": "6.5.1",
|
||||
"resolved": "https://registry.npmjs.org/qs/-/qs-6.5.1.tgz",
|
||||
@ -3626,6 +3659,23 @@
|
||||
"xtend": "4.0.1"
|
||||
}
|
||||
},
|
||||
"tcp-port-used": {
|
||||
"version": "0.1.2",
|
||||
"resolved": "https://registry.npmjs.org/tcp-port-used/-/tcp-port-used-0.1.2.tgz",
|
||||
"integrity": "sha1-lFDodoyDtBb9TRpqlEnuzL9JbCk=",
|
||||
"requires": {
|
||||
"debug": "0.7.4",
|
||||
"is2": "0.0.9",
|
||||
"q": "0.9.7"
|
||||
},
|
||||
"dependencies": {
|
||||
"debug": {
|
||||
"version": "0.7.4",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-0.7.4.tgz",
|
||||
"integrity": "sha1-BuHqgILCyxTjmAbiLi9vdX+Srzk="
|
||||
}
|
||||
}
|
||||
},
|
||||
"temp-file": {
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmjs.org/temp-file/-/temp-file-2.0.3.tgz",
|
||||
|
@ -27,10 +27,12 @@
|
||||
"fs-extra": "^4.0.2",
|
||||
"lodash": "^4.17.4",
|
||||
"moment": "^2.19.1",
|
||||
"node-fetch": "^1.7.3",
|
||||
"promise": "^8.0.1",
|
||||
"query-string": "^5.0.1",
|
||||
"redux": "^3.7.2",
|
||||
"sprintf-js": "^1.1.1",
|
||||
"sqlite3": "^3.1.13"
|
||||
"sqlite3": "^3.1.13",
|
||||
"tcp-port-used": "^0.1.2"
|
||||
}
|
||||
}
|
||||
|
@ -3,4 +3,4 @@ ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
cd "$ROOT_DIR"
|
||||
./build.sh
|
||||
cd "$ROOT_DIR/app"
|
||||
node_modules/.bin/electron .
|
||||
node_modules/.bin/electron . --env dev --log-level debug "$@"
|
@ -227,8 +227,15 @@ class BaseApplication {
|
||||
if (this.store()) return this.store().dispatch(action);
|
||||
}
|
||||
|
||||
initRedux() {
|
||||
this.store_ = createStore(reducer, applyMiddleware(this.generalMiddleware()));
|
||||
BaseModel.dispatch = this.store().dispatch;
|
||||
FoldersScreenUtils.dispatch = this.store().dispatch;
|
||||
}
|
||||
|
||||
async start(argv) {
|
||||
let startFlags = await this.handleStartFlags_(argv);
|
||||
|
||||
argv = startFlags.argv;
|
||||
let initArgs = startFlags.matched;
|
||||
if (argv.length) this.showPromptString_ = false;
|
||||
@ -239,7 +246,9 @@ class BaseApplication {
|
||||
initArgs.env = 'dev';
|
||||
}
|
||||
|
||||
Setting.setConstant('appName', initArgs.env == 'dev' ? 'joplindev' : 'joplin');
|
||||
let appName = initArgs.env == 'dev' ? 'joplindev' : 'joplin';
|
||||
if (Setting.value('appId').indexOf('-desktop') >= 0) appName += '-desktop';
|
||||
Setting.setConstant('appName', appName);
|
||||
|
||||
const profileDir = initArgs.profileDir ? initArgs.profileDir : os.homedir() + '/.config/' + Setting.value('appName');
|
||||
const resourceDir = profileDir + '/resources';
|
||||
@ -250,13 +259,12 @@ class BaseApplication {
|
||||
Setting.setConstant('resourceDir', resourceDir);
|
||||
Setting.setConstant('tempDir', tempDir);
|
||||
|
||||
console.info(Setting.value('env'), Setting.value('profileDir'), Setting.value('resourceDir'), Setting.value('tempDir'));
|
||||
|
||||
await fs.mkdirp(profileDir, 0o755);
|
||||
await fs.mkdirp(resourceDir, 0o755);
|
||||
await fs.mkdirp(tempDir, 0o755);
|
||||
|
||||
this.logger_.addTarget('file', { path: profileDir + '/log.txt' });
|
||||
//this.logger_.addTarget('console');
|
||||
this.logger_.setLevel(initArgs.logLevel);
|
||||
|
||||
reg.setLogger(this.logger_);
|
||||
@ -269,8 +277,8 @@ class BaseApplication {
|
||||
this.dbLogger_.setLevel(Logger.LEVEL_WARN);
|
||||
}
|
||||
|
||||
const packageJson = require('./package.json');
|
||||
this.logger_.info(sprintf('Starting %s %s (%s)...', packageJson.name, packageJson.version, Setting.value('env')));
|
||||
// const packageJson = require('./package.json');
|
||||
// this.logger_.info(sprintf('Starting %s %s (%s)...', packageJson.name, packageJson.version, Setting.value('env')));
|
||||
this.logger_.info('Profile directory: ' + profileDir);
|
||||
|
||||
this.database_ = new JoplinDatabase(new DatabaseDriverNode());
|
||||
|
@ -111,8 +111,6 @@ class Logger {
|
||||
} else if (target.type == 'file') {
|
||||
let serializedObject = this.objectsToString(...object);
|
||||
Logger.fsDriver().appendFileSync(target.path, line + serializedObject + "\n");
|
||||
} else if (target.type == 'vorpal') {
|
||||
//target.vorpal.log(...object);
|
||||
} else if (target.type == 'database') {
|
||||
let msg = this.objectsToString(...object);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user