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
14 changes: 5 additions & 9 deletions packages/insomnia/src/main.development.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion packages/insomnia/src/main/network/curl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions packages/insomnia/src/main/network/libcurl-promise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion packages/insomnia/src/main/network/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
23 changes: 1 addition & 22 deletions packages/insomnia/src/network/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
};
Expand Down Expand Up @@ -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);
// });
// });
// }