Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
168 changes: 79 additions & 89 deletions bun.lock

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"url": "git+https://github.com/opencor/webapp.git"
},
"type": "module",
"version": "0.20260223.0",
"version": "0.20260224.0",
"scripts": {
"archive:web": "bun src/renderer/scripts/archive.web.js",
"build": "electron-vite build",
Expand Down Expand Up @@ -62,11 +62,11 @@
"xxhash-wasm": "^1.1.0"
},
"devDependencies": {
"@biomejs/biome": "^2.4.3",
"@biomejs/biome": "^2.4.4",
"@electron-toolkit/tsconfig": "^2.0.0",
"@electron-toolkit/utils": "^4.0.0",
"@tailwindcss/postcss": "^4.2.0",
"@tailwindcss/vite": "^4.2.0",
"@tailwindcss/postcss": "^4.2.1",
"@tailwindcss/vite": "^4.2.1",
"@types/node": "^25.3.0",
"@types/plotly.js": "^3.0.10",
"@vitejs/plugin-vue": "^6.0.4",
Expand All @@ -81,10 +81,10 @@
"electron-vite": "^5.0.0",
"esbuild": "^0.27.3",
"node-addon-api": "^8.5.0",
"rollup-plugin-visualizer": "^6.0.8",
"rollup-plugin-visualizer": "^7.0.0",
"stylelint": "^17.3.0",
"stylelint-config-standard": "^40.0.0",
"tailwindcss": "^4.2.0",
"tailwindcss": "^4.2.1",
"tailwindcss-primeui": "^0.6.1",
"tar": "^7.5.9",
"typescript": "^5.9.3",
Expand Down
24 changes: 20 additions & 4 deletions src/preload/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import type { ISplashScreenInfo } from '../renderer/src/common/electronApi.ts';

const exec = promisify(_exec);

const _operatingSystem = await (async (): Promise<string> => {
let _operatingSystem: string | null = null;
const defaultOperatingSystem = `${process.platform} (${process.arch === 'x64' ? 'Intel' : 'ARM'})`;

const retrieveOperatingSystem = async (): Promise<string> => {
const safeExec = async (cmd: string): Promise<string | null> => {
try {
const { stdout } = await exec(cmd);
Expand Down Expand Up @@ -69,8 +72,19 @@ const _operatingSystem = await (async (): Promise<string> => {

operatingSystem = operatingSystem || 'macOS';
}
return `${operatingSystem || process.platform} (${process.arch === 'x64' ? 'Intel' : 'ARM'})`;
})();

return operatingSystem ? `${operatingSystem} (${process.arch === 'x64' ? 'Intel' : 'ARM'})` : defaultOperatingSystem;
};

// Retrieve the version of the operating system.

retrieveOperatingSystem()
.then((operatingSystem) => {
_operatingSystem = operatingSystem;
})
.catch(() => {
_operatingSystem = defaultOperatingSystem;
});

// Some bridging between our main process and renderer process.
// Note: this must be in sync with src/electronApi.ts.
Expand All @@ -79,7 +93,9 @@ electron.contextBridge.exposeInMainWorld('electronApi', {
// Some general methods.

operatingSystem: () => {
return _operatingSystem;
// Return a cached version of the operating system if we have it, otherwise return a default value.

return _operatingSystem || defaultOperatingSystem;
},

// Splash screen window.
Expand Down
120 changes: 60 additions & 60 deletions src/renderer/bun.lock

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions src/renderer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
},
"./style.css": "./dist/opencor.css"
},
"version": "0.20260223.0",
"version": "0.20260224.0",
"scripts": {
"build": "vite build && bun scripts/generate.version.js",
"build:lib": "vite build --config vite.lib.config.ts && cp index.d.ts dist/index.d.ts",
Expand Down Expand Up @@ -72,9 +72,9 @@
"xxhash-wasm": "^1.1.0"
},
"devDependencies": {
"@biomejs/biome": "^2.4.3",
"@tailwindcss/postcss": "^4.2.0",
"@tailwindcss/vite": "^4.2.0",
"@biomejs/biome": "^2.4.4",
"@tailwindcss/postcss": "^4.2.1",
"@tailwindcss/vite": "^4.2.1",
"@types/node": "^25.3.0",
"@types/plotly.js": "^3.0.10",
"@vitejs/plugin-vue": "^6.0.4",
Expand All @@ -83,7 +83,7 @@
"esbuild": "^0.27.3",
"stylelint": "^17.3.0",
"stylelint-config-standard": "^40.0.0",
"tailwindcss": "^4.2.0",
"tailwindcss": "^4.2.1",
"tailwindcss-primeui": "^0.6.1",
"typescript": "^5.9.3",
"unplugin-vue-components": "^31.0.0",
Expand Down
111 changes: 2 additions & 109 deletions src/renderer/src/common/common.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import xxhash from 'xxhash-wasm';

import * as dependencies from './dependencies.ts';
import { electronApi } from './electronApi.ts';

// Some interfaces.
Expand Down Expand Up @@ -104,14 +103,8 @@ export const corsProxyUrl = (url: string): string => {

// A method to compute the XXH64 value of some data.

let _xxhash: Awaited<ReturnType<typeof xxhash>>;

export const initialiseXxhash = async (): Promise<void> => {
_xxhash = await xxhash();
};

export const xxh64 = (data: Uint8Array): string => {
return _xxhash.h64Raw(data).toString(16).padStart(16, '0');
return dependencies._xxhash.h64Raw(data).toString(16).padStart(16, '0');
};

// A method to format a number of milliseconds into a string.
Expand Down Expand Up @@ -219,103 +212,3 @@ export const fileName = (filePath: string): string => {
export const sleep = (ms: number): Promise<void> => {
return new Promise((resolve) => setTimeout(resolve, ms));
};

// A method to create a lazy initialiser for a module, which imports the module and optionally its CSS.

// biome-ignore lint/suspicious/noExplicitAny: dynamic import requires any type
type Module = any;

const injectedCss = new Set<string>();

const createLazyInitialiser = (url: string, assign: (module: Module) => void, name: string, cssUrl?: string) => {
return async (): Promise<void> => {
try {
const module = await import(/* @vite-ignore */ url);

assign((module as Module).default ?? module);

// Fetch any CSS for the module and inject it into the page if we haven't already done so.

if (cssUrl && !injectedCss.has(cssUrl)) {
const response = await fetch(/* @vite-ignore */ cssUrl, { mode: 'cors' });

if (!response.ok) {
throw new Error(`Failed to load ${name ?? 'stylesheet'}: ${response.statusText}`);
}

const style = document.createElement('style');

style.textContent = await response.text();

document.head.appendChild(style);

injectedCss.add(cssUrl);
}
} catch (error: unknown) {
console.error(`Failed to import ${name ?? url}:`, formatError(error));

throw error;
}
};
};

// Initialise jsonschema lazily.

export let jsonSchema: Module = null;

export const initialiseJsonSchema = createLazyInitialiser(
'https://cdn.jsdelivr.net/npm/jsonschema@1.5.0/+esm',
(module: Module) => {
jsonSchema = module;
},
'jsonschema'
);

// Initialise JSZip lazily.

export let jsZip: Module = null;

export const initialiseJsZip = createLazyInitialiser(
'https://cdn.jsdelivr.net/npm/jszip@3.10.1/+esm',
(module: Module) => {
jsZip = module;
},
'JSZip'
);

// Initialise Math.js lazily.

export let mathJs: Module = null;

export const initialiseMathJs = createLazyInitialiser(
'https://cdn.jsdelivr.net/npm/mathjs@15.1.1/+esm',
(module: Module) => {
mathJs = module;
},
'Math.js'
);

// Initialise Plotly.js lazily.

export let plotlyJs: Module = null;

export const initialisePlotlyJs = createLazyInitialiser(
'https://cdn.jsdelivr.net/npm/plotly.js-gl2d-dist-min@3.3.1/+esm',
(module: Module) => {
plotlyJs = module;
},
'Plotly.js'
);

// Initialise VueTippy lazily (also injects its CSS once).

export let vueTippy: Module = null;

export const initialiseVueTippy = createLazyInitialiser(
'https://cdn.jsdelivr.net/npm/vue-tippy@6.7.1/+esm',
(module: Module) => {
vueTippy = module;
},
'VueTippy',
'https://cdn.jsdelivr.net/npm/tippy.js@6.3.7/dist/tippy.css'
);
37 changes: 37 additions & 0 deletions src/renderer/src/common/dependencies.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import xxhash from 'xxhash-wasm';

// biome-ignore lint/suspicious/noExplicitAny: dynamic import requires any type
export type Module = any;

export let _jsonSchema: Module = null;
export let _jsZip: Module = null;
export let _mathJs: Module = null;
export let _plotlyJs: Module = null;
export let _vueTippy: Module = null;
export let _xxhash: Module = null;

export const setJsonSchema = (module: Module): void => {
_jsonSchema = module;
};

export const setJsZip = (module: Module): void => {
_jsZip = module;
};

export const setMathJs = (module: Module): void => {
_mathJs = module;
};

export const setPlotlyJs = (module: Module): void => {
_plotlyJs = module;
};

export const setVueTippy = (module: Module): void => {
_vueTippy = module;
};

export const initialiseXxhash: Promise<Module> = xxhash().then((module: Module) => {
_xxhash = module;

return module;
});
Loading