mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 14:49:53 +00:00
parent
444877e1e1
commit
8ecf47c0a7
@ -3,6 +3,7 @@ import electron, { app, ipcMain, session } from 'electron';
|
||||
import { BrowserWindow } from 'electron';
|
||||
import contextMenu from 'electron-context-menu';
|
||||
import installExtension, { REACT_DEVELOPER_TOOLS } from 'electron-devtools-installer';
|
||||
import fs from 'fs/promises';
|
||||
import path from 'path';
|
||||
|
||||
import { userDataFolder } from '../config/config.json';
|
||||
@ -39,15 +40,8 @@ log.info(`Running version ${getAppVersion()}`);
|
||||
|
||||
// Override the Electron userData path
|
||||
// This makes Chromium use this folder for eg localStorage
|
||||
const envDataPath = process.env.INSOMNIA_DATA_PATH;
|
||||
if (envDataPath) {
|
||||
app.setPath('userData', envDataPath);
|
||||
} else {
|
||||
// Explicitly set userData folder from config because it's sketchy to rely on electron-builder to use productName, which could be changed by accident.
|
||||
const defaultPath = app.getPath('userData');
|
||||
const newPath = path.join(defaultPath, '../', isDevelopment() ? 'insomnia-app' : userDataFolder);
|
||||
app.setPath('userData', newPath);
|
||||
}
|
||||
const dataPath = process.env.INSOMNIA_DATA_PATH || path.join(app.getPath('userData'), '../', isDevelopment() ? 'insomnia-app' : userDataFolder);
|
||||
app.setPath('userData', dataPath);
|
||||
|
||||
// So if (window) checks don't throw
|
||||
global.window = global.window || undefined;
|
||||
@ -102,6 +96,8 @@ app.on('ready', async () => {
|
||||
|
||||
// Init the rest
|
||||
await updates.init();
|
||||
// recursive = ignore already exists error
|
||||
await fs.mkdir(path.join(dataPath, 'responses'), { recursive: true });
|
||||
});
|
||||
|
||||
// Set as default protocol
|
||||
|
@ -109,7 +109,6 @@ const openCurlConnection = async (
|
||||
}
|
||||
|
||||
const responsesDir = path.join(process.env['INSOMNIA_DATA_PATH'] || electron.app.getPath('userData'), 'responses');
|
||||
fs.mkdirSync(responsesDir, { recursive: true });
|
||||
|
||||
const responseBodyPath = path.join(responsesDir, uuidV4() + '.response');
|
||||
eventLogFileStreams.set(options.requestId, fs.createWriteStream(responseBodyPath));
|
||||
|
@ -96,8 +96,8 @@ export const cancelCurlRequest = (id: string) => cancelCurlRequestHandlers[id]()
|
||||
export const curlRequest = (options: CurlRequestOptions) => new Promise<CurlRequestOutput>(async resolve => {
|
||||
try {
|
||||
const responsesDir = path.join(getDataDirectory(), 'responses');
|
||||
fs.mkdirSync(responsesDir, { recursive: true });
|
||||
|
||||
// TODO: remove this check, its only used for network.test.ts
|
||||
await fs.promises.mkdir(responsesDir, { recursive: true });
|
||||
const responseBodyPath = path.join(responsesDir, uuidv4() + '.response');
|
||||
|
||||
const { requestId, req, finalUrl, settings, certificates, caCertficatePath, socketPath, authHeader } = options;
|
||||
|
@ -118,7 +118,6 @@ const openWebSocketConnection = async (
|
||||
}
|
||||
|
||||
const responsesDir = path.join(process.env['INSOMNIA_DATA_PATH'] || electron.app.getPath('userData'), 'responses');
|
||||
fs.mkdirSync(responsesDir, { recursive: true });
|
||||
|
||||
const responseBodyPath = path.join(responsesDir, uuidV4() + '.response');
|
||||
eventLogFileStreams.set(options.requestId, fs.createWriteStream(responseBodyPath));
|
||||
|
@ -65,7 +65,7 @@ export const fetchRequestData = async (requestId: string) => {
|
||||
const clientCertificates = await models.clientCertificate.findByParentId(workspaceId);
|
||||
const caCert = await models.caCertificate.findByParentId(workspaceId);
|
||||
const responseId = generateId('res');
|
||||
const responsesDir = pathJoin(process.env['INSOMNIA_DATA_PATH'] || (process.type === 'renderer' ? window : require('electron')).app.getPath('userData'), 'responses');
|
||||
const responsesDir = pathJoin((process.type === 'renderer' ? window : require('electron')).app.getPath('userData'), 'responses');
|
||||
const timelinePath = pathJoin(responsesDir, responseId + '.timeline');
|
||||
return { request, environment, settings, clientCertificates, caCert, activeEnvironmentId, timelinePath, responseId };
|
||||
};
|
||||
@ -337,24 +337,3 @@ async function _applyResponsePluginHooks(
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// export function storeTimeline(timeline: ResponseTimelineEntry[]): Promise<string> {
|
||||
// const timelineStr = JSON.stringify(timeline, null, '\t');
|
||||
// const timelineHash = uuidv4();
|
||||
// const responsesDir = pathJoin(process.env['INSOMNIA_DATA_PATH'] || (process.type === 'renderer' ? window : electron).app.getPath('userData'), 'responses');
|
||||
|
||||
// fs.mkdirSync(responsesDir, { recursive: true });
|
||||
|
||||
// const timelinePath = pathJoin(responsesDir, timelineHash + '.timeline');
|
||||
// if (process.type === 'renderer') {
|
||||
// return window.main.writeFile({ path: timelinePath, content: timelineStr });
|
||||
// }
|
||||
// return new Promise<string>((resolve, reject) => {
|
||||
// fs.writeFile(timelinePath, timelineStr, err => {
|
||||
// if (err != null) {
|
||||
// return reject(err);
|
||||
// }
|
||||
// resolve(timelinePath);
|
||||
// });
|
||||
// });
|
||||
// }
|
||||
|
Loading…
Reference in New Issue
Block a user