Chore: Adding eslint rule to avoid using window and document in main process related code (#9579)

* add eslint rule for main
* update extension
This commit is contained in:
Kent Wang
2026-01-21 11:41:07 +08:00
committed by GitHub
parent 252a4b8b63
commit eff9d9e7e2
4 changed files with 24 additions and 7 deletions

View File

@@ -222,4 +222,22 @@ export default defineConfig([
'**/.react-router/*',
],
},
// Main process ESLint rules
{
files: ['packages/insomnia/src/main/**/*.{ts,tsx,js,mjs}'],
rules: {
'no-restricted-globals': [
'error',
// block usage of browser globals in main process code
{
name: 'window',
message: '"window" is not available in main process.',
},
{
name: 'document',
message: '"document" is not available in main process.',
},
],
},
},
]);

View File

@@ -16,8 +16,7 @@ export const isPathAllowed = (filePath: string, userAllowList: string[]) => {
};
const securePath = (filePath: string) => path.resolve(decodeURIComponent(filePath));
const getSecuredFolderAllowList = (userAllowList: string[]) => {
const userDataPath = process.type === 'renderer' ? window.app.getPath('userData') : electron.app.getPath('userData');
const userdataDirectory = process.env.INSOMNIA_DATA_PATH || userDataPath;
const userdataDirectory = process.env.INSOMNIA_DATA_PATH || electron.app.getPath('userData');
// we use tmpdir for buildMultipart
// we put the db in userData
// the user can also specifiy other folders

View File

@@ -610,7 +610,10 @@ export function createWindow(): ElectronBrowserWindow {
},
{
label: `R${MNEMONIC_SYM}estart`,
click: window?.main.restart,
click: () => {
app.relaunch();
app.exit();
},
},
{
label: `Set window for ${MNEMONIC_SYM}FHD Screenshot`,

View File

@@ -8,7 +8,6 @@ import { jarFromCookies } from '~/common/cookies';
import { getBodyBuffer } from '~/models/helpers/response-operations';
import { database as db } from '../common/database';
import { secureReadFile } from '../main/secure-read-file';
import * as models from '../models/index';
import type { Request } from '../models/request';
import type { RequestGroup } from '../models/request-group';
@@ -122,9 +121,7 @@ export default class BaseExtension {
userInfo: os.userInfo(),
};
},
readFile: async (path: string) => {
return secureReadFile(path);
},
readFile: async (path: string) => window.main.secureReadFile({ path }),
decode: async (buffer: Buffer, encoding = 'utf8') => iconv.decode(buffer, encoding),
encode: async (input: string, encoding: BinaryToTextEncoding) =>
crypto.createHash('md5').update(input).digest(encoding),