mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-29 19:35:20 +02:00
refactor(deep-links, quick-ask, window): replace localhost references with dynamic server origin retrieval
This commit is contained in:
parent
a2847664c8
commit
fe797e65d6
4 changed files with 16 additions and 11 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
import { app } from 'electron';
|
import { app } from 'electron';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { getMainWindow } from './window';
|
import { getMainWindow } from './window';
|
||||||
import { getServerPort } from './server';
|
import { getServerOrigin } from './server';
|
||||||
import { trackEvent } from './analytics';
|
import { trackEvent } from './analytics';
|
||||||
|
|
||||||
const PROTOCOL = 'surfsense';
|
const PROTOCOL = 'surfsense';
|
||||||
|
|
@ -23,7 +23,7 @@ function handleDeepLink(url: string) {
|
||||||
});
|
});
|
||||||
if (parsed.hostname === 'auth' && parsed.pathname === '/callback') {
|
if (parsed.hostname === 'auth' && parsed.pathname === '/callback') {
|
||||||
const params = parsed.searchParams.toString();
|
const params = parsed.searchParams.toString();
|
||||||
win.loadURL(`http://localhost:${getServerPort()}/auth/callback?${params}`);
|
win.loadURL(`${getServerOrigin()}/auth/callback?${params}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
win.show();
|
win.show();
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import { BrowserWindow, clipboard, globalShortcut, ipcMain, screen, shell } from
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { IPC_CHANNELS } from '../ipc/channels';
|
import { IPC_CHANNELS } from '../ipc/channels';
|
||||||
import { checkAccessibilityPermission, getFrontmostApp, simulateCopy, simulatePaste } from './platform';
|
import { checkAccessibilityPermission, getFrontmostApp, simulateCopy, simulatePaste } from './platform';
|
||||||
import { getServerPort } from './server';
|
import { getServerOrigin } from './server';
|
||||||
import { getShortcuts } from './shortcuts';
|
import { getShortcuts } from './shortcuts';
|
||||||
import { getActiveSearchSpaceId } from './active-search-space';
|
import { getActiveSearchSpaceId } from './active-search-space';
|
||||||
import { trackEvent } from './analytics';
|
import { trackEvent } from './analytics';
|
||||||
|
|
@ -58,7 +58,7 @@ function createQuickAskWindow(x: number, y: number): BrowserWindow {
|
||||||
|
|
||||||
const spaceId = pendingSearchSpaceId;
|
const spaceId = pendingSearchSpaceId;
|
||||||
const route = spaceId ? `/dashboard/${spaceId}/new-chat` : '/dashboard';
|
const route = spaceId ? `/dashboard/${spaceId}/new-chat` : '/dashboard';
|
||||||
quickAskWindow.loadURL(`http://localhost:${getServerPort()}${route}?quickAssist=true`);
|
quickAskWindow.loadURL(`${getServerOrigin()}${route}?quickAssist=true`);
|
||||||
|
|
||||||
quickAskWindow.once('ready-to-show', () => {
|
quickAskWindow.once('ready-to-show', () => {
|
||||||
quickAskWindow?.show();
|
quickAskWindow?.show();
|
||||||
|
|
@ -69,7 +69,7 @@ function createQuickAskWindow(x: number, y: number): BrowserWindow {
|
||||||
});
|
});
|
||||||
|
|
||||||
quickAskWindow.webContents.setWindowOpenHandler(({ url }) => {
|
quickAskWindow.webContents.setWindowOpenHandler(({ url }) => {
|
||||||
if (url.startsWith('http://localhost')) {
|
if (url.startsWith(getServerOrigin())) {
|
||||||
return { action: 'allow' };
|
return { action: 'allow' };
|
||||||
}
|
}
|
||||||
shell.openExternal(url);
|
shell.openExternal(url);
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import { app, utilityProcess } from 'electron';
|
||||||
import { getPort } from 'get-port-please';
|
import { getPort } from 'get-port-please';
|
||||||
|
|
||||||
const isDev = !app.isPackaged;
|
const isDev = !app.isPackaged;
|
||||||
|
const SERVER_HOST = '127.0.0.1';
|
||||||
let serverPort = 3000;
|
let serverPort = 3000;
|
||||||
let nextServerProcess: ReturnType<typeof utilityProcess.fork> | null = null;
|
let nextServerProcess: ReturnType<typeof utilityProcess.fork> | null = null;
|
||||||
|
|
||||||
|
|
@ -10,6 +11,10 @@ export function getServerPort(): number {
|
||||||
return serverPort;
|
return serverPort;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getServerOrigin(): string {
|
||||||
|
return `http://${SERVER_HOST}:${serverPort}`;
|
||||||
|
}
|
||||||
|
|
||||||
function getStandalonePath(): string {
|
function getStandalonePath(): string {
|
||||||
if (isDev) {
|
if (isDev) {
|
||||||
return path.join(__dirname, '..', '..', 'surfsense_web', '.next', 'standalone', 'surfsense_web');
|
return path.join(__dirname, '..', '..', 'surfsense_web', '.next', 'standalone', 'surfsense_web');
|
||||||
|
|
@ -44,7 +49,7 @@ export async function startNextServer(): Promise<void> {
|
||||||
env: {
|
env: {
|
||||||
...process.env,
|
...process.env,
|
||||||
PORT: String(serverPort),
|
PORT: String(serverPort),
|
||||||
HOSTNAME: '127.0.0.1',
|
HOSTNAME: SERVER_HOST,
|
||||||
NODE_ENV: 'production',
|
NODE_ENV: 'production',
|
||||||
},
|
},
|
||||||
serviceName: 'SurfSense Next Server',
|
serviceName: 'SurfSense Next Server',
|
||||||
|
|
@ -75,7 +80,7 @@ export async function startNextServer(): Promise<void> {
|
||||||
child.once('exit', startupExitHandler);
|
child.once('exit', startupExitHandler);
|
||||||
});
|
});
|
||||||
|
|
||||||
const ready = await Promise.race([waitForServer(`http://localhost:${serverPort}`), exited]);
|
const ready = await Promise.race([waitForServer(getServerOrigin()), exited]);
|
||||||
if (startupExitHandler) {
|
if (startupExitHandler) {
|
||||||
child.removeListener('exit', startupExitHandler);
|
child.removeListener('exit', startupExitHandler);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import { app, BrowserWindow, shell, session } from 'electron';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { trackEvent } from './analytics';
|
import { trackEvent } from './analytics';
|
||||||
import { showErrorDialog } from './errors';
|
import { showErrorDialog } from './errors';
|
||||||
import { getServerPort } from './server';
|
import { getServerOrigin } from './server';
|
||||||
import { setActiveSearchSpaceId } from './active-search-space';
|
import { setActiveSearchSpaceId } from './active-search-space';
|
||||||
|
|
||||||
const isDev = !app.isPackaged;
|
const isDev = !app.isPackaged;
|
||||||
|
|
@ -58,10 +58,10 @@ export function createMainWindow(initialPath = '/dashboard'): BrowserWindow {
|
||||||
mainWindow?.setTitle(WINDOW_TITLE);
|
mainWindow?.setTitle(WINDOW_TITLE);
|
||||||
});
|
});
|
||||||
|
|
||||||
mainWindow.loadURL(`http://localhost:${getServerPort()}${initialPath}`);
|
mainWindow.loadURL(`${getServerOrigin()}${initialPath}`);
|
||||||
|
|
||||||
mainWindow.webContents.setWindowOpenHandler(({ url }) => {
|
mainWindow.webContents.setWindowOpenHandler(({ url }) => {
|
||||||
if (url.startsWith('http://localhost')) {
|
if (url.startsWith(getServerOrigin())) {
|
||||||
return { action: 'allow' };
|
return { action: 'allow' };
|
||||||
}
|
}
|
||||||
shell.openExternal(url);
|
shell.openExternal(url);
|
||||||
|
|
@ -70,7 +70,7 @@ export function createMainWindow(initialPath = '/dashboard'): BrowserWindow {
|
||||||
|
|
||||||
const filter = { urls: [`${HOSTED_FRONTEND_URL}/*`] };
|
const filter = { urls: [`${HOSTED_FRONTEND_URL}/*`] };
|
||||||
session.defaultSession.webRequest.onBeforeRequest(filter, (details, callback) => {
|
session.defaultSession.webRequest.onBeforeRequest(filter, (details, callback) => {
|
||||||
const rewritten = details.url.replace(HOSTED_FRONTEND_URL, `http://localhost:${getServerPort()}`);
|
const rewritten = details.url.replace(HOSTED_FRONTEND_URL, getServerOrigin());
|
||||||
callback({ redirectURL: rewritten });
|
callback({ redirectURL: rewritten });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue