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
2 changes: 1 addition & 1 deletion 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.20260209.3",
"version": "0.20260209.4",
"scripts": {
"archive:web": "bun src/renderer/scripts/archive.web.js",
"build": "electron-vite build",
Expand Down
12 changes: 6 additions & 6 deletions src/main/MainMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let disabledMenu: electron.Menu | null = null;
let recentFilePaths: string[] = [];
let hasFiles = false;

export function enableDisableMainMenu(enable: boolean): void {
export const enableDisableMainMenu = (enable: boolean): void => {
// Build our menu, if needed.

if (enable && enabledMenu) {
Expand Down Expand Up @@ -290,9 +290,9 @@ export function enableDisableMainMenu(enable: boolean): void {

electron.Menu.setApplicationMenu(enable ? enabledMenu : disabledMenu);
}
}
};

export function enableDisableFileCloseAndCloseAllMenuItems(enable: boolean): void {
export const enableDisableFileCloseAndCloseAllMenuItems = (enable: boolean): void => {
if (enabledMenu) {
hasFiles = enable;

Expand All @@ -304,11 +304,11 @@ export function enableDisableFileCloseAndCloseAllMenuItems(enable: boolean): voi
fileCloseAllMenu.enabled = hasFiles;
}
}
}
};

export function updateReopenMenu(filePaths: string[]): void {
export const updateReopenMenu = (filePaths: string[]): void => {
enabledMenu = null;
recentFilePaths = filePaths;

enableDisableMainMenu(true);
}
};
52 changes: 26 additions & 26 deletions src/main/MainWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import type { SplashScreenWindow } from './SplashScreenWindow.ts';
autoUpdater.autoDownload = false;
autoUpdater.logger = null;

export function checkForUpdates(atStartup: boolean): void {
export const checkForUpdates = (atStartup: boolean): void => {
// Check for updates, if requested and if OpenCOR is packaged.

if (isPackaged() && electronConf.get('settings.general.checkForUpdatesAtStartup')) {
Expand All @@ -37,13 +37,13 @@ export function checkForUpdates(atStartup: boolean): void {
MainWindow.instance?.webContents.send('update-check-error', formatError(error));
});
}
}
};

autoUpdater.on('download-progress', (info: ProgressInfo) => {
MainWindow.instance?.webContents.send('update-download-progress', info.percent);
});

export function downloadAndInstallUpdate(): void {
export const downloadAndInstallUpdate = (): void => {
autoUpdater
.downloadUpdate()
.then(() => {
Expand All @@ -52,23 +52,23 @@ export function downloadAndInstallUpdate(): void {
.catch((error: unknown) => {
MainWindow.instance?.webContents.send('update-download-error', formatError(error));
});
}
};

export function installUpdateAndRestart(): void {
export const installUpdateAndRestart = (): void => {
autoUpdater.quitAndInstall(true, true);
}
};

export function loadSettings(): ISettings {
export const loadSettings = (): ISettings => {
return electronConf.get('settings');
}
};

export function saveSettings(settings: ISettings): void {
export const saveSettings = (settings: ISettings): void => {
electronConf.set('settings', settings);
}
};

let _resetAll = false;

export function resetAll(): void {
export const resetAll = (): void => {
_resetAll = true;

/* TODO: enable once our GitHub integration is fully ready.
Expand All @@ -77,17 +77,17 @@ export function resetAll(): void {

electron.app.relaunch();
electron.app.quit();
}
};

let recentFilePaths: string[] = [];

export function clearRecentFiles(): void {
export const clearRecentFiles = (): void => {
recentFilePaths = [];

updateReopenMenu(recentFilePaths);
}
};

export function fileClosed(filePath: string): void {
export const fileClosed = (filePath: string): void => {
// Make sure that the file is not a COMBINE archive that was opened using a data URL.

if (isDataUrlOmexFileName(filePath)) {
Expand All @@ -98,15 +98,15 @@ export function fileClosed(filePath: string): void {
recentFilePaths = recentFilePaths.slice(0, 10);

updateReopenMenu(recentFilePaths);
}
};

export function fileIssue(filePath: string): void {
export const fileIssue = (filePath: string): void => {
recentFilePaths = recentFilePaths.filter((recentFilePath) => recentFilePath !== filePath);

updateReopenMenu(recentFilePaths);
}
};

export function fileOpened(filePath: string): void {
export const fileOpened = (filePath: string): void => {
recentFilePaths = recentFilePaths.filter((recentFilePath) => recentFilePath !== filePath);

updateReopenMenu(recentFilePaths);
Expand All @@ -116,23 +116,23 @@ export function fileOpened(filePath: string): void {
// are no more files to reopen.

MainWindow.instance?.reopenFilePathsAndSelectFilePath();
}
};

let openedFilePaths: string[] = [];

export function filesOpened(filePaths: string[]): void {
export const filesOpened = (filePaths: string[]): void => {
openedFilePaths = filePaths;

if (!filePaths.length) {
selectedFilePath = null;
}
}
};

let selectedFilePath: string | null = null;

export function fileSelected(filePath: string): void {
export const fileSelected = (filePath: string): void => {
selectedFilePath = filePath;
}
};

export class MainWindow extends ApplicationWindow {
// Properties.
Expand Down Expand Up @@ -299,7 +299,7 @@ export class MainWindow extends ApplicationWindow {
// so that the OAuth flow can proceed.

this.webContents.setWindowOpenHandler((details) => {
function isFirebaseOauthPopup(url: string): boolean {
const isFirebaseOauthPopup = (url: string): boolean => {
try {
const parsedUrl = new URL(url);

Expand All @@ -311,7 +311,7 @@ export class MainWindow extends ApplicationWindow {
} catch {
return false;
}
}
};

if (isFirebaseOauthPopup(details.url)) {
return {
Expand Down
2 changes: 1 addition & 1 deletion 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.20260209.3",
"version": "0.20260209.4",
"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
4 changes: 2 additions & 2 deletions src/renderer/scripts/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ const version = `${majorVersion}.${minorVersion}.${patchVersion}`;

// Update our package.json files.

function updatePackageJsonFile(filePath) {
const updatePackageJsonFile = (filePath) => {
const contents = JSON.parse(fs.readFileSync(filePath));

contents.version = version;

fs.writeFileSync(filePath, `${JSON.stringify(contents, null, 2)}\n`);
}
};

// Perform the updates.

Expand Down
68 changes: 34 additions & 34 deletions src/renderer/src/common/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,69 +17,69 @@ export interface ISettings {

const uaParser = new UAParser();

export function isWindows(): boolean {
export const isWindows = (): boolean => {
return uaParser.getOS().name === 'Windows';
}
};

export function isLinux(): boolean {
export const isLinux = (): boolean => {
return uaParser.getOS().name === 'Linux';
}
};

export function isMacOs(): boolean {
export const isMacOs = (): boolean => {
return uaParser.getOS().name === 'macOS';
}
};

export function isDesktop(): boolean {
export const isDesktop = (): boolean => {
return uaParser.getOS().name === 'Windows' || uaParser.getOS().name === 'Linux' || uaParser.getOS().name === 'macOS';
}
};

// A method to determine whether the Ctrl or Cmd key is pressed, depending on the operating system.

export function isCtrlOrCmd(event: KeyboardEvent): boolean {
export const isCtrlOrCmd = (event: KeyboardEvent): boolean => {
return isMacOs() ? event.metaKey : event.ctrlKey;
}
};

// A method to enable/disable the main menu.

export function enableDisableMainMenu(enable: boolean): void {
export const enableDisableMainMenu = (enable: boolean): void => {
electronApi?.enableDisableMainMenu(enable);
}
};

// A method to determine whether a given file name indicates a data URL OMEX file.

export const OMEX_PREFIX = 'OMEX #';

export function isDataUrlOmexFileName(fileName: string): boolean {
export const isDataUrlOmexFileName = (fileName: string): boolean => {
return fileName.startsWith(OMEX_PREFIX);
}
};

// A method to determine whether a given URL is an HTTP or HTTPS URL.

export function isHttpUrl(url: string): boolean {
export const isHttpUrl = (url: string): boolean => {
try {
const { protocol } = new URL(url);

return protocol === 'http:' || protocol === 'https:';
} catch {
return false;
}
}
};

// A method to get the CORS proxy URL for a given URL.

export function corsProxyUrl(url: string): string {
export const corsProxyUrl = (url: string): string => {
return `https://cors-proxy.opencor.workers.dev/?url=${url}`;
}
};

// A method to return the SHA-256 hash of some data.

export function sha256(data: string | Uint8Array): string {
export const sha256 = (data: string | Uint8Array): string => {
return SHA256(data).toString();
}
};

// A method to format a given number of milliseconds into a string.

export function formatTime(time: number): string {
export const formatTime = (time: number): string => {
const ms = Math.floor(time % 1000);
const s = Math.floor((time / 1000) % 60);
const m = Math.floor((time / (1000 * 60)) % 60);
Expand Down Expand Up @@ -108,21 +108,21 @@ export function formatTime(time: number): string {
}

return res;
}
};

// A method to format an error into a string.

export function formatError(error: unknown): string {
export const formatError = (error: unknown): string => {
if (error instanceof Error) {
return error.message;
}

return String(error);
}
};

// A method to format a message, i.e. make sure that it starts with a capital letter and ends with a period, or not.

export function formatMessage(message: string, selfContained: boolean = true): string {
export const formatMessage = (message: string, selfContained: boolean = true): string => {
message = selfContained
? message.charAt(0).toUpperCase() + message.slice(1)
: message.charAt(0).toLowerCase() + message.slice(1);
Expand All @@ -136,17 +136,17 @@ export function formatMessage(message: string, selfContained: boolean = true): s
: selfContained
? `${message}.`
: message;
}
};

// A method to determine whether a number is divisible by another one.

export function isDivisible(a: number, b: number): boolean {
export const isDivisible = (a: number, b: number): boolean => {
return Number.isInteger(a / b);
}
};

// A method to trigger a browser download for a given file.

export function downloadFile(filename: string, content: string | Blob, type: string): void {
export const downloadFile = (filename: string, content: string | Blob, type: string): void => {
const link = document.createElement('a');
const blob = content instanceof Blob ? content : new Blob([content], { type });
const url = URL.createObjectURL(blob);
Expand All @@ -161,11 +161,11 @@ export function downloadFile(filename: string, content: string | Blob, type: str
document.body.removeChild(link);

URL.revokeObjectURL(url);
}
};

// A method to get the file name from a given file path.

export function fileName(filePath: string): string {
export const fileName = (filePath: string): string => {
const res = filePath.split(/(\\|\/)/g).pop() || '';

try {
Expand All @@ -175,10 +175,10 @@ export function fileName(filePath: string): string {

return res;
}
}
};

// A method to sleep for a given number of milliseconds.

export function sleep(ms: number): Promise<void> {
export const sleep = (ms: number): Promise<void> => {
return new Promise((resolve) => setTimeout(resolve, ms));
}
};
Loading
Loading