mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-30 10:36:35 +02:00
Handle openFolder and openTag too; change the URL format; extract ULR functions to a separate file
This commit is contained in:
parent
61161039c8
commit
f118f5250f
@ -185,8 +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_);
|
||||
} else if (message === 'mainScreenReady' && this.initialUrl_) {
|
||||
void this.openUrl(this.initialUrl_);
|
||||
}
|
||||
});
|
||||
|
||||
@ -332,7 +332,9 @@ export default class ElectronAppWrapper {
|
||||
win.focus();
|
||||
if (process.platform !== 'darwin') {
|
||||
const url = argv.find((arg) => arg.startsWith('joplin://'));
|
||||
if (url) this.openUrl(url);
|
||||
if (url) {
|
||||
void this.openUrl(url);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@ -362,8 +364,8 @@ export default class ElectronAppWrapper {
|
||||
});
|
||||
|
||||
this.electronApp_.on('open-url', (_event: any, url: string) => {
|
||||
this.openUrl(url);
|
||||
});
|
||||
void this.openUrl(url);
|
||||
});
|
||||
}
|
||||
|
||||
async openUrl(url: string) {
|
||||
|
@ -36,6 +36,7 @@ import ShareService from '@joplin/lib/services/share/ShareService';
|
||||
import { reg } from '@joplin/lib/registry';
|
||||
import removeKeylessItems from '../ResizableLayout/utils/removeKeylessItems';
|
||||
import { localSyncInfoFromState } from '@joplin/lib/services/synchronizer/syncInfoUtils';
|
||||
import { parseUrl } from '@joplin/lib/ProtocolUtils';
|
||||
|
||||
const { connect } = require('react-redux');
|
||||
const { PromptDialog } = require('../PromptDialog.min.js');
|
||||
@ -189,11 +190,11 @@ class MainScreenComponent extends React.Component<Props, State> {
|
||||
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);
|
||||
const { command, params } = parseUrl(args.url);
|
||||
void CommandService.instance().execute(command, params.id);
|
||||
}
|
||||
});
|
||||
ipcRenderer.send('asynchronous-message', 'getInitialUrl');
|
||||
});
|
||||
ipcRenderer.send('asynchronous-message', 'mainScreenReady');
|
||||
}
|
||||
|
||||
private updateLayoutPluginViews(layout: LayoutItem, plugins: PluginStates) {
|
||||
|
@ -20,6 +20,7 @@ import Logger from '@joplin/lib/Logger';
|
||||
import { FolderEntity } from '@joplin/lib/services/database/types';
|
||||
import stateToWhenClauseContext from '../../services/commands/stateToWhenClauseContext';
|
||||
import { store } from '@joplin/lib/reducer';
|
||||
import { getFolderUrl, getTagUrl } from '@joplin/lib/ProtocolUtils';
|
||||
const { connect } = require('react-redux');
|
||||
const shared = require('@joplin/lib/components/shared/side-menu-shared.js');
|
||||
const { themeStyle } = require('@joplin/lib/theme');
|
||||
@ -326,10 +327,31 @@ class SidebarComponent extends React.Component<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
if (itemType === BaseModel.TYPE_FOLDER) {
|
||||
menu.append(
|
||||
new MenuItem({
|
||||
label: _('Copy folder URL'),
|
||||
click: async () => {
|
||||
const { clipboard } = require('electron');
|
||||
clipboard.writeText(getFolderUrl(itemId));
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
if (itemType === BaseModel.TYPE_TAG) {
|
||||
menu.append(new MenuItem(
|
||||
menuUtils.commandToStatefulMenuItem('renameTag', itemId)
|
||||
));
|
||||
menu.append(
|
||||
new MenuItem({
|
||||
label: _('Copy tag URL'),
|
||||
click: async () => {
|
||||
const { clipboard } = require('electron');
|
||||
clipboard.writeText(getTagUrl(itemId));
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
const pluginViews = pluginUtils.viewsByType(this.pluginsRef.current, 'menuItem');
|
||||
|
@ -6,6 +6,7 @@ import MenuUtils from '@joplin/lib/services/commands/MenuUtils';
|
||||
import InteropServiceHelper from '../../InteropServiceHelper';
|
||||
import { _ } from '@joplin/lib/locale';
|
||||
import { MenuItemLocation } from '@joplin/lib/services/plugins/api/types';
|
||||
import { getNoteUrl } from '@joplin/lib/ProtocolUtils';
|
||||
|
||||
import BaseModel from '@joplin/lib/BaseModel';
|
||||
const bridge = require('electron').remote.require('./bridge').default;
|
||||
@ -133,6 +134,18 @@ export default class NoteListUtils {
|
||||
})
|
||||
);
|
||||
|
||||
if (noteIds.length == 1) {
|
||||
menu.append(
|
||||
new MenuItem({
|
||||
label: _('Copy note URL'),
|
||||
click: async () => {
|
||||
const { clipboard } = require('electron');
|
||||
clipboard.writeText(getNoteUrl(noteIds[0]));
|
||||
},
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
if ([9, 10].includes(Setting.value('sync.target'))) {
|
||||
menu.append(
|
||||
new MenuItem(
|
||||
|
33
packages/lib/ProtocolUtils.ts
Normal file
33
packages/lib/ProtocolUtils.ts
Normal file
@ -0,0 +1,33 @@
|
||||
export function getNoteUrl(noteId: string) {
|
||||
return `joplin://x-callback-url/openNote?id=${noteId}`;
|
||||
}
|
||||
|
||||
export function getFolderUrl(folderId: string) {
|
||||
return `joplin://x-callback-url/openFolder?id=${folderId}`;
|
||||
}
|
||||
|
||||
export function getTagUrl(tagId: string) {
|
||||
return `joplin://x-callback-url/openTag?id=${tagId}`;
|
||||
}
|
||||
|
||||
export type Command = 'openNote' | 'openFolder' | 'openTag';
|
||||
|
||||
export interface UlrInfo {
|
||||
command: Command;
|
||||
params: any;
|
||||
}
|
||||
|
||||
export function parseUrl(s: string): UlrInfo {
|
||||
if (!s.startsWith('joplin://')) return null;
|
||||
const url = new URL(s);
|
||||
|
||||
const params: any = {};
|
||||
for (const [key, value] of url.searchParams) {
|
||||
params[key] = value;
|
||||
}
|
||||
|
||||
return {
|
||||
command: url.pathname.substring(url.pathname.lastIndexOf('/') + 1) as Command,
|
||||
params,
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user