mirror of
https://github.com/tiddly-gittly/TidGi-Desktop.git
synced 2026-01-24 13:30:59 -08:00
feat: support file relative to wiki folder
This commit is contained in:
parent
6949397524
commit
f16ce580d7
3 changed files with 28 additions and 2 deletions
|
|
@ -203,7 +203,7 @@ ${message.message}
|
|||
}
|
||||
}
|
||||
|
||||
public async handleFileProtocol(request: Electron.ProtocolRequest, callback: (response: string | Electron.ProtocolResponse) => void): Promise<void> {
|
||||
public async handleFileProtocol(request: { url: string }, callback: (response: string) => void): Promise<void> {
|
||||
logger.info('handleFileProtocol() getting url', { url: request.url });
|
||||
const pathname = decodeURI(request.url.replace('open://', '').replace('file://', ''));
|
||||
logger.info('handleFileProtocol() handle file:// or open:// This url will open file in-wiki', { pathname });
|
||||
|
|
@ -240,6 +240,7 @@ ${message.message}
|
|||
}
|
||||
|
||||
public registerFileProtocol(): boolean {
|
||||
// this normally nor called. In wiki file:// image will use `handleFileLink()` in `src\services\view\setupViewSession.ts`.
|
||||
const succeed = protocol.registerFileProtocol('file', this.handleFileProtocol.bind(this));
|
||||
return succeed;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ export interface INativeService {
|
|||
*/
|
||||
executeZxScript$(zxWorkerArguments: IZxFileInput, wikiFolderLocation?: string): Observable<string>;
|
||||
getLocalHostUrlWithActualIP(url: string): Promise<string>;
|
||||
handleFileProtocol(request: Electron.ProtocolRequest, callback: (response: string | Electron.ProtocolResponse) => void): Promise<void>;
|
||||
handleFileProtocol(request: { url: string }, callback: (response: string) => void): Promise<void>;
|
||||
log(level: string, message: string, meta?: Record<string, unknown>): Promise<void>;
|
||||
open(uri: string, isDirectory?: boolean): Promise<void>;
|
||||
openInEditor(filePath: string, editorName?: string | undefined): Promise<boolean>;
|
||||
|
|
|
|||
|
|
@ -34,6 +34,15 @@ export function setupViewSession(workspace: IWorkspace, preferences: IPreference
|
|||
assignAdminAuthToken(workspace.id, details, authService, viewContext);
|
||||
callback({ cancel: false, requestHeaders: details.requestHeaders });
|
||||
});
|
||||
sessionOfView.webRequest.onBeforeRequest((details, callback) => {
|
||||
if (details.url.startsWith('file://') || details.url.startsWith('open://')) {
|
||||
void handleFileLink(details, nativeService, callback);
|
||||
} else {
|
||||
callback({
|
||||
cancel: false,
|
||||
});
|
||||
}
|
||||
});
|
||||
handleFileProtocol(sessionOfView, nativeService);
|
||||
return sessionOfView;
|
||||
}
|
||||
|
|
@ -60,5 +69,21 @@ function assignAdminAuthToken(workspaceID: string, details: Electron.OnBeforeSen
|
|||
}
|
||||
|
||||
function handleFileProtocol(sessionOfView: Electron.Session, nativeService: INativeService) {
|
||||
// this normally nor called. In wiki file:// image will use `handleFileLink()` below.
|
||||
sessionOfView.protocol.registerFileProtocol('file', nativeService.handleFileProtocol.bind(nativeService));
|
||||
}
|
||||
|
||||
async function handleFileLink(details: Electron.OnBeforeRequestListenerDetails, nativeService: INativeService, callback: (response: Electron.CallbackResponse) => void) {
|
||||
await nativeService.handleFileProtocol({ url: details.url }, (redirectURL: string) => {
|
||||
if (redirectURL === details.url) {
|
||||
callback({
|
||||
cancel: false,
|
||||
});
|
||||
} else {
|
||||
callback({
|
||||
cancel: false,
|
||||
redirectURL,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue