fix: add web project folder picker and isolated HTML file previews
This commit is contained in:
@@ -10,6 +10,7 @@ import { observeWindowsProcess, protectUserDirectory } from '../core/desktop/pro
|
||||
import { DESKTOP_CHANNELS, desktopOrigin } from '../shared/contracts/desktop-bridge.mjs';
|
||||
import { desktopLaunchOptions } from '../core/desktop/launch-options.mjs';
|
||||
import { BrowsingView } from './browsing-view.mjs';
|
||||
import { localPreviewAddress } from '../core/preview/local-file-preview.mjs';
|
||||
|
||||
const options = desktopLaunchOptions(process.argv, { defaultApp: process.defaultApp, mainFile: __filename });
|
||||
const appRoot = path.resolve(options['--app-root'] || (app.isPackaged ? path.resolve(path.dirname(process.execPath), '..') : path.resolve(__dirname, '..')));
|
||||
@@ -45,14 +46,16 @@ else {
|
||||
webPreferences: { preload, sandbox: true, contextIsolation: true, nodeIntegration: false, webSecurity: true, allowRunningInsecureContent: false } });
|
||||
window.webContents.setWindowOpenHandler(() => ({ action: 'deny' }));
|
||||
window.webContents.on('will-navigate', details => { if (!desktopOrigin(details.url, controller.url)) details.preventDefault(); });
|
||||
window.webContents.on('will-frame-navigate', details => { if (!desktopOrigin(details.url, controller.url)) details.preventDefault(); });
|
||||
window.webContents.on('will-frame-navigate', details => { if (!desktopOrigin(details.url, controller.url) && !(details.isMainFrame === false && localPreviewAddress(details.url))) details.preventDefault(); });
|
||||
window.webContents.on('will-attach-webview', event => event.preventDefault());
|
||||
const session = window.webContents.session;
|
||||
session.setPermissionRequestHandler((_contents, _permission, callback) => callback(false));
|
||||
session.setPermissionCheckHandler(() => false);
|
||||
session.webRequest.onBeforeRequest((details, callback) => {
|
||||
const permitted = desktopOrigin(details.url, controller.url) || details.url.startsWith('data:image/') || details.url.startsWith('blob:' + controller.url + '/');
|
||||
callback({ cancel: !permitted });
|
||||
if (permitted) return callback({ cancel: false });
|
||||
if (!localPreviewAddress(details.url) || details.resourceType === 'mainFrame') return callback({ cancel: true });
|
||||
void controller.api('/local-file-preview-access?url=' + encodeURIComponent(details.url)).then(access => callback({ cancel: !access.allowed })).catch(() => callback({ cancel: true }));
|
||||
});
|
||||
bridge = new DesktopBridge(controller, { dialog, shell, getWindow: () => window, onStopped: () => setTimeout(() => app.quit(), 150) });
|
||||
for (const [action, channel] of Object.entries(DESKTOP_CHANNELS)) ipcMain.handle(channel, (event, input) => bridge.execute(event, action, input));
|
||||
|
||||
@@ -4,6 +4,7 @@ contextBridge.exposeInMainWorld('desktopWorkbench', Object.freeze({
|
||||
status: () => ipcRenderer.invoke('awb:desktop-status'),
|
||||
pickProject: () => ipcRenderer.invoke('awb:desktop-pick-project'),
|
||||
projectFolder: projectId => ipcRenderer.invoke('awb:desktop-project-folder', { projectId }),
|
||||
openFilePreview: input => ipcRenderer.invoke('awb:desktop-file-preview', input),
|
||||
reviewTask: input => ipcRenderer.invoke('awb:desktop-review-task', input),
|
||||
revealFile: input => ipcRenderer.invoke('awb:desktop-reveal-file', input),
|
||||
stopHost: () => ipcRenderer.invoke('awb:desktop-stop-host'),
|
||||
|
||||
Reference in New Issue
Block a user