Housekeeping

This commit is contained in:
Manav Rathi 2024-04-30 13:37:17 +05:30
parent d6aeef85d6
commit 6c4adb1127
No known key found for this signature in database
7 changed files with 11 additions and 38 deletions

View file

@ -401,12 +401,6 @@ const main = () => {
setDownloadPath(mainWindow.webContents);
allowExternalLinks(mainWindow.webContents);
// TODO(MR): Remove or resurrect
// The commit that introduced this header override had the message
// "fix cors issue for uploads". Not sure what that means, so disabling
// it for now to see why exactly this is required.
// addAllowOriginHeader(mainWindow);
// Start loading the renderer.
mainWindow.loadURL(rendererURL);

View file

@ -1,21 +0,0 @@
import { BrowserWindow } from "electron";
export function addAllowOriginHeader(mainWindow: BrowserWindow) {
mainWindow.webContents.session.webRequest.onHeadersReceived(
(details, callback) => {
details.responseHeaders = lowerCaseHeaders(details.responseHeaders);
details.responseHeaders["access-control-allow-origin"] = ["*"];
callback({
responseHeaders: details.responseHeaders,
});
},
);
}
function lowerCaseHeaders(responseHeaders: Record<string, string[]>) {
const headers: Record<string, string[]> = {};
for (const key of Object.keys(responseHeaders)) {
headers[key.toLowerCase()] = responseHeaders[key];
}
return headers;
}

View file

@ -1,7 +1,7 @@
import { shell } from "electron/common";
import { app, dialog } from "electron/main";
import path from "node:path";
import { posixPath } from "../utils/path";
import { posixPath } from "../utils/electron";
export const selectDirectory = async () => {
const result = await dialog.showOpenDialog({

View file

@ -5,7 +5,7 @@ import path from "node:path";
import { FolderWatch, type CollectionMapping } from "../../types/ipc";
import log from "../log";
import { watchStore } from "../stores/watch";
import { posixPath } from "../utils/path";
import { posixPath } from "../utils/electron";
import { fsIsDir } from "./fs";
/**

View file

@ -1,12 +1,20 @@
import shellescape from "any-shell-escape";
import { app } from "electron/main";
import { exec } from "node:child_process";
import path from "node:path";
import { promisify } from "node:util";
import log from "../log";
/** `true` if the app is running in development mode. */
export const isDev = !app.isPackaged;
/**
* Convert a file system {@link filePath} that uses the local system specific
* path separators into a path that uses POSIX file separators.
*/
export const posixPath = (filePath: string) =>
filePath.split(path.sep).join(path.posix.sep);
/**
* Run a shell command asynchronously.
*

View file

@ -1,5 +1,5 @@
/**
* @file grab bag of utitity functions.
* @file grab bag of utility functions.
*
* Many of these are verbatim copies of functions from web code since there
* isn't currently a common package that both of them share.

View file

@ -1,8 +0,0 @@
import path from "node:path";
/**
* Convert a file system {@link filePath} that uses the local system specific
* path separators into a path that uses POSIX file separators.
*/
export const posixPath = (filePath: string) =>
filePath.split(path.sep).join(path.posix.sep);