mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-09 06:55:03 +00:00
Merge branch 'main' into feature/proxy-global-and-collection
# Conflicts: # packages/bruno-app/src/components/Preferences/General/index.js # packages/bruno-app/src/components/Preferences/index.js # packages/bruno-app/src/providers/App/useIpcEvents.js # packages/bruno-app/src/providers/Preferences/index.js # packages/bruno-electron/src/index.js # packages/bruno-electron/src/ipc/collection.js # packages/bruno-electron/src/store/preferences.js
This commit is contained in:
@@ -8,10 +8,9 @@ const menuTemplate = require('./app/menu-template');
|
||||
const LastOpenedCollections = require('./store/last-opened-collections');
|
||||
const registerNetworkIpc = require('./ipc/network');
|
||||
const registerCollectionsIpc = require('./ipc/collection');
|
||||
const registerApplicationIpc = require('./ipc/application');
|
||||
const registerPreferencesIpc = require('./ipc/preferences');
|
||||
const Watcher = require('./app/watcher');
|
||||
const { loadWindowState, saveWindowState } = require('./utils/window');
|
||||
const preferences = require('./store/preferences');
|
||||
|
||||
const lastOpenedCollections = new LastOpenedCollections();
|
||||
|
||||
@@ -41,8 +40,8 @@ app.on('ready', async () => {
|
||||
y,
|
||||
width,
|
||||
height,
|
||||
minWidth:1000,
|
||||
minHeight:640,
|
||||
minWidth: 1000,
|
||||
minHeight: 640,
|
||||
webPreferences: {
|
||||
nodeIntegration: true,
|
||||
contextIsolation: true,
|
||||
@@ -78,7 +77,7 @@ app.on('ready', async () => {
|
||||
// register all ipc handlers
|
||||
registerNetworkIpc(mainWindow);
|
||||
registerCollectionsIpc(mainWindow, watcher, lastOpenedCollections);
|
||||
registerApplicationIpc(mainWindow, preferences);
|
||||
registerPreferencesIpc(mainWindow, watcher, lastOpenedCollections);
|
||||
});
|
||||
|
||||
// Quit the app once all windows are closed
|
||||
|
||||
@@ -15,9 +15,10 @@ const {
|
||||
sanitizeDirectoryName
|
||||
} = require('../utils/filesystem');
|
||||
const { stringifyJson } = require('../utils/common');
|
||||
const { openCollectionDialog, openCollection } = require('../app/collections');
|
||||
const { openCollectionDialog } = require('../app/collections');
|
||||
const { generateUidBasedOnHash } = require('../utils/common');
|
||||
const { moveRequestUid, deleteRequestUid } = require('../cache/requestUids');
|
||||
const { setPreferences } = require('../store/preferences');
|
||||
const EnvironmentSecretsStore = require('../store/env-secrets');
|
||||
|
||||
const environmentSecretsStore = new EnvironmentSecretsStore();
|
||||
@@ -462,21 +463,6 @@ const registerRendererEventHandlers = (mainWindow, watcher, lastOpenedCollection
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.handle('renderer:ready-collection', async (event) => {
|
||||
// reload last opened collections
|
||||
const lastOpened = lastOpenedCollections.getAll();
|
||||
|
||||
if (lastOpened && lastOpened.length) {
|
||||
for (let collectionPath of lastOpened) {
|
||||
if (isDirectory(collectionPath)) {
|
||||
openCollection(mainWindow, watcher, collectionPath, {
|
||||
dontSendDisplayErrors: true
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.handle('renderer:update-bruno-config', async (event, brunoConfig, collectionPath, collectionUid) => {
|
||||
try {
|
||||
const brunoConfigPath = path.join(collectionPath, 'bruno.json');
|
||||
|
||||
35
packages/bruno-electron/src/ipc/preferences.js
Normal file
35
packages/bruno-electron/src/ipc/preferences.js
Normal file
@@ -0,0 +1,35 @@
|
||||
const { ipcMain } = require('electron');
|
||||
const { getPreferences, savePreferences } = require('../store/preferences');
|
||||
const { isDirectory } = require('../utils/filesystem');
|
||||
const { openCollection } = require('../app/collections');
|
||||
|
||||
const registerPreferencesIpc = (mainWindow, watcher, lastOpenedCollections) => {
|
||||
ipcMain.handle('renderer:ready', async (event) => {
|
||||
// load preferences
|
||||
const preferences = getPreferences();
|
||||
mainWindow.webContents.send('main:load-preferences', preferences);
|
||||
|
||||
// reload last opened collections
|
||||
const lastOpened = lastOpenedCollections.getAll();
|
||||
|
||||
if (lastOpened && lastOpened.length) {
|
||||
for (let collectionPath of lastOpened) {
|
||||
if (isDirectory(collectionPath)) {
|
||||
openCollection(mainWindow, watcher, collectionPath, {
|
||||
dontSendDisplayErrors: true
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.handle('renderer:save-preferences', async (event, preferences) => {
|
||||
try {
|
||||
await savePreferences(preferences);
|
||||
} catch (error) {
|
||||
return Promise.reject(error);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = registerPreferencesIpc;
|
||||
@@ -1,3 +1,4 @@
|
||||
const Yup = require('yup');
|
||||
const Store = require('electron-store');
|
||||
const { get } = require('lodash');
|
||||
|
||||
@@ -20,9 +21,12 @@ const { get } = require('lodash');
|
||||
|
||||
const defaultPreferences = {
|
||||
request: {
|
||||
tlsVerification: true,
|
||||
sslVerification: true,
|
||||
caCert: ''
|
||||
},
|
||||
font: {
|
||||
codeFont: 'default'
|
||||
},
|
||||
proxy: {
|
||||
enabled: false,
|
||||
protocol: 'http',
|
||||
@@ -37,6 +41,15 @@ const defaultPreferences = {
|
||||
}
|
||||
};
|
||||
|
||||
const preferencesSchema = Yup.object().shape({
|
||||
request: Yup.object().shape({
|
||||
sslVerification: Yup.boolean()
|
||||
}),
|
||||
font: Yup.object().shape({
|
||||
codeFont: Yup.string().nullable()
|
||||
})
|
||||
});
|
||||
|
||||
class PreferencesStore {
|
||||
constructor() {
|
||||
this.store = new Store({
|
||||
@@ -45,25 +58,36 @@ class PreferencesStore {
|
||||
});
|
||||
}
|
||||
|
||||
get(key) {
|
||||
return this.store.get(key);
|
||||
getPreferences() {
|
||||
return {
|
||||
defaultPreferences,
|
||||
...this.store.get('preferences')
|
||||
};
|
||||
}
|
||||
|
||||
set(key, value) {
|
||||
this.store.set(key, value);
|
||||
}
|
||||
|
||||
getPath() {
|
||||
return this.store.path;
|
||||
savePreferences(newPreferences) {
|
||||
return this.store.set('preferences', newPreferences);
|
||||
}
|
||||
}
|
||||
|
||||
const preferencesStore = new PreferencesStore();
|
||||
|
||||
const getPreferences = () => {
|
||||
return {
|
||||
...defaultPreferences,
|
||||
...(preferencesStore.get('preferences') || {})
|
||||
};
|
||||
return preferencesStore.getPreferences();
|
||||
};
|
||||
|
||||
const savePreferences = async (newPreferences) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
preferencesSchema
|
||||
.validate(newPreferences, { abortEarly: true })
|
||||
.then((validatedPreferences) => {
|
||||
preferencesStore.savePreferences(validatedPreferences);
|
||||
resolve();
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const preferences = {
|
||||
@@ -85,28 +109,11 @@ const preferences = {
|
||||
|
||||
getProxyConfig: () => {
|
||||
return get(getPreferences(), 'proxy', {});
|
||||
},
|
||||
|
||||
setPreferences: (validatedPreferences) => {
|
||||
const updatedPreferences = {
|
||||
...getPreferences(),
|
||||
...validatedPreferences
|
||||
};
|
||||
preferencesStore.set('preferences', updatedPreferences);
|
||||
},
|
||||
|
||||
migrateSslVerification: (sslVerification) => {
|
||||
let preferences = getPreferences();
|
||||
if (!preferences.request) {
|
||||
const updatedPreferences = {
|
||||
...preferences,
|
||||
request: {
|
||||
tlsVerification: sslVerification
|
||||
}
|
||||
};
|
||||
preferencesStore.set('preferences', updatedPreferences);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = preferences;
|
||||
module.exports = {
|
||||
getPreferences,
|
||||
savePreferences,
|
||||
preferences
|
||||
};
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
const _ = require('lodash');
|
||||
const Store = require('electron-store');
|
||||
|
||||
const DEFAULT_WINDOW_WIDTH = 1280;
|
||||
|
||||
Reference in New Issue
Block a user