mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-09 17:33:55 +00:00
1849b4d39f
* chore: migrate eslint to oxlint * chore: migrate prettier to oxfmt * chore: migrate typescript * chore: toThrow should have a expected value * chore: cast test value as Day * chore: small title fix * chore: mocks should be hoisted * chore: incorrect async useage * chore: test should be inside description * chore: test sohuld include an expeced * chore: oxfmt --------- Co-authored-by: alex-Arc <omnivox@LAPTOP-RC5SNBVV.localdomain>
57 lines
1.5 KiB
TypeScript
57 lines
1.5 KiB
TypeScript
import type { MouseEvent } from 'react';
|
|
|
|
import { baseURI, serverURL } from '../../externals';
|
|
|
|
type ElectronWindow = Window & {
|
|
process?: { type?: string };
|
|
ipcRenderer?: {
|
|
send: (channel: string, args?: string | object) => void;
|
|
};
|
|
};
|
|
|
|
/**
|
|
* Open an external URLs: specifically for a electron / browser case
|
|
* If electron: ask main process to call a new browser window
|
|
* If browser: open in new tab
|
|
*/
|
|
export function openLink(url: string) {
|
|
const electronWindow = window as ElectronWindow;
|
|
if (electronWindow.process?.type === 'renderer' && electronWindow.ipcRenderer) {
|
|
electronWindow.ipcRenderer.send('send-to-link', url);
|
|
} else {
|
|
window.open(url);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Handles opening external links
|
|
* serverUrl and baseURI are used for testing
|
|
*/
|
|
export function handleLinks(
|
|
location: string,
|
|
event?: MouseEvent,
|
|
externalServerUrl: string = serverURL,
|
|
externalBaseURI: string = baseURI,
|
|
) {
|
|
// we handle the link manually
|
|
event?.preventDefault();
|
|
|
|
const destination = new URL(externalServerUrl);
|
|
destination.pathname = externalBaseURI ? `${externalBaseURI}/${location}` : location;
|
|
openLink(destination.toString());
|
|
}
|
|
|
|
export function linkToOtherHost(
|
|
host: string,
|
|
path?: string,
|
|
externalServerUrl: string = serverURL,
|
|
externalBaseURI: string = baseURI,
|
|
) {
|
|
const destination = new URL(externalServerUrl);
|
|
destination.hostname = host;
|
|
if (path) {
|
|
destination.pathname = externalBaseURI ? `${externalBaseURI}/${path}` : path;
|
|
}
|
|
return destination.toString();
|
|
}
|