mirror of
https://github.com/Kong/insomnia.git
synced 2026-02-07 12:43:44 -05:00
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:
@@ -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.',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
]);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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`,
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user