@@ -249,48 +249,68 @@ export const initWindow = (app: App) => {
249
249
currentWindow . on ( "blur" , winOnBlur ) ;
250
250
if ( ! isWindow ( ) ) {
251
251
ipcRenderer . on ( Constants . SIYUAN_OPENURL , ( event , url ) => {
252
- if ( / ^ s i y u a n : \/ \/ p l u g i n s \/ / . test ( url ) ) {
253
- // siyuan://plugins/plugin-samplecustom_tab?title=自定义页签&icon=iconFace&data={"text": "This is the custom plugin tab I opened via protocol."}
254
- const pluginId = url . replace ( "siyuan://plugins/" , "" ) . split ( "?" ) [ 0 ] ;
255
- app . plugins . find ( plugin => {
256
- const match = Object . keys ( plugin . models ) . find ( key => {
257
- if ( key === pluginId ) {
258
- let data = getSearch ( "data" , url ) ;
259
- try {
260
- data = JSON . parse ( data || "{}" ) ;
261
- } catch ( e ) {
262
- console . log ( "Error open plugin tab with protocol:" , e ) ;
252
+ app . plugins . forEach ( plugin => {
253
+ plugin . eventBus . emit ( "open-siyuan-url" , { url } ) ;
254
+ } ) ;
255
+ if ( url . startsWith ( "siyuan://plugins/" ) ) {
256
+ const urlObj = new URL ( url ) ;
257
+ const pluginId = urlObj . pathname . split ( "/" ) [ 3 ] ;
258
+ if ( pluginId ) {
259
+ app . plugins . find ( plugin => {
260
+ // siyuan://plugins/plugin-name/foo?bar=baz
261
+ if ( pluginId . startsWith ( plugin . name ) ) {
262
+ plugin . eventBus . emit ( "open-siyuan-url-plugins" , { url } ) ;
263
+ }
264
+
265
+ // siyuan://plugins/plugin-samplecustom_tab?title=自定义页签&icon=iconFace&data={"text": "This is the custom plugin tab I opened via protocol."}
266
+ const match = Object . keys ( plugin . models ) . find ( key => {
267
+ if ( key === pluginId ) {
268
+ let data = getSearch ( "data" , url ) ;
269
+ try {
270
+ data = JSON . parse ( data || "{}" ) ;
271
+ } catch ( e ) {
272
+ console . log ( "Error open plugin tab with protocol:" , e ) ;
273
+ }
274
+ openFile ( {
275
+ app,
276
+ custom : {
277
+ title : getSearch ( "title" , url ) ,
278
+ icon : getSearch ( "icon" , url ) ,
279
+ data,
280
+ fn : plugin . models [ key ]
281
+ } ,
282
+ } ) ;
283
+ return true ;
263
284
}
264
- openFile ( {
265
- app,
266
- custom : {
267
- title : getSearch ( "title" , url ) ,
268
- icon : getSearch ( "icon" , url ) ,
269
- data,
270
- fn : plugin . models [ key ]
271
- } ,
272
- } ) ;
285
+ } ) ;
286
+ if ( match ) {
273
287
return true ;
274
288
}
275
289
} ) ;
276
- if ( match ) {
277
- return true ;
278
- }
279
- } ) ;
280
- return ;
290
+ return ;
291
+ }
281
292
}
282
293
if ( isSYProtocol ( url ) ) {
283
294
const id = getIdFromSYProtocol ( url ) ;
295
+ const focus = getSearch ( "focus" , url ) === "1" ;
284
296
fetchPost ( "/api/block/checkBlockExist" , { id} , existResponse => {
285
297
if ( existResponse . data ) {
286
298
openFileById ( {
287
299
app,
288
300
id,
289
301
action : [ Constants . CB_GET_FOCUS , Constants . CB_GET_CONTEXT ] ,
290
- zoomIn : getSearch ( " focus" , url ) === "1"
302
+ zoomIn : focus ,
291
303
} ) ;
292
304
ipcRenderer . send ( Constants . SIYUAN_SHOW , getCurrentWindow ( ) . id ) ;
293
305
}
306
+ app . plugins . forEach ( plugin => {
307
+ plugin . eventBus . emit ( "open-siyuan-url-blocks" , {
308
+ url,
309
+ id,
310
+ focus,
311
+ exist : existResponse . data ,
312
+ } ) ;
313
+ } ) ;
294
314
} ) ;
295
315
return ;
296
316
}
0 commit comments