1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-30 10:36:35 +02:00

Open the note from URL even if Joplin isn't running

This commit is contained in:
Roman 2021-08-13 23:21:14 +01:00
parent 00504898f2
commit 61161039c8
4 changed files with 21 additions and 15 deletions

View File

@ -30,12 +30,14 @@ export default class ElectronAppWrapper {
private buildDir_: string = null;
private rendererProcessQuitReply_: RendererProcessQuitReply = null;
private pluginWindows_: PluginWindows = {};
private initialUrl_: string = null;
constructor(electronApp: any, env: string, profilePath: string, isDebugMode: boolean) {
constructor(electronApp: any, env: string, profilePath: string, isDebugMode: boolean, initialUrl: string) {
this.electronApp_ = electronApp;
this.env_ = env;
this.isDebugMode_ = isDebugMode;
this.profilePath_ = profilePath;
this.initialUrl_ = initialUrl;
}
electronApp() {
@ -183,6 +185,8 @@ export default class ElectronAppWrapper {
// save the response and try quit again.
this.rendererProcessQuitReply_ = args;
this.electronApp_.quit();
} else if (message === 'getInitialUrl' && this.initialUrl_) {
this.openUrl(this.initialUrl_);
}
});
@ -328,7 +332,7 @@ export default class ElectronAppWrapper {
win.focus();
if (process.platform !== 'darwin') {
const url = argv.find((arg) => arg.startsWith('joplin://'));
if (url) this.onUrl(url);
if (url) this.openUrl(url);
}
});
@ -358,11 +362,11 @@ export default class ElectronAppWrapper {
});
this.electronApp_.on('open-url', (_event: any, url: string) => {
this.onUrl(url);
});
this.openUrl(url);
});
}
async onUrl(url: string) {
async openUrl(url: string) {
this.win_.webContents.send('asynchronous-message', 'openUrl', {
url: url,
});

View File

@ -41,7 +41,6 @@ import RevisionService from '@joplin/lib/services/RevisionService';
import MigrationService from '@joplin/lib/services/MigrationService';
import { loadCustomCss, injectCustomStyles } from '@joplin/lib/CssUtils';
// import populateDatabase from '@joplin/lib/services/debug/populateDatabase';
const ipcRenderer = require('electron').ipcRenderer;
const commands = [
require('./gui/MainScreen/commands/editAlarm'),
@ -162,14 +161,6 @@ class Application extends BaseApplication {
super();
this.bridge_nativeThemeUpdated = this.bridge_nativeThemeUpdated.bind(this);
ipcRenderer.on('asynchronous-message', (_event: any, message: string, args: any) => {
if (message === 'openUrl') {
const noteId = (args.url as string).substring('joplin://'.length);
CommandService.instance().execute('openNote', noteId);
}
});
}
hasGui() {

View File

@ -185,6 +185,15 @@ class MainScreenComponent extends React.Component<Props, State> {
this.layoutModeListenerKeyDown = this.layoutModeListenerKeyDown.bind(this);
window.addEventListener('resize', this.window_resize);
ipcRenderer.on('asynchronous-message', (_event: any, message: string, args: any) => {
if (message === 'openUrl') {
console.log(`openUrl ${args.url}`);
const noteId = (args.url as string).substring('joplin://'.length);
CommandService.instance().execute('openNote', noteId);
}
});
ipcRenderer.send('asynchronous-message', 'getInitialUrl');
}
private updateLayoutPluginViews(layout: LayoutItem, plugins: PluginStates) {

View File

@ -44,7 +44,9 @@ if (env === 'dev' && process.platform === 'win32') {
electronApp.setAsDefaultProtocolClient('joplin');
}
const wrapper = new ElectronAppWrapper(electronApp, env, profilePath, isDebugMode);
const initialUrl = process.argv.find((arg) => arg.startsWith('joplin://'));
const wrapper = new ElectronAppWrapper(electronApp, env, profilePath, isDebugMode, initialUrl);
initBridge(wrapper);