hyper/lib/utils/config.ts

27 lines
834 B
TypeScript
Raw Normal View History

2023-07-22 05:57:32 -08:00
import {ipcRenderer} from './ipc';
2023-06-30 11:07:04 -08:00
import {require as remoteRequire, getCurrentWindow} from '@electron/remote';
// TODO: Should be updates to new async API https://medium.com/@nornagon/electrons-remote-module-considered-harmful-70d69500f31
const plugins = remoteRequire('./plugins') as typeof import('../../app/plugins');
2016-07-13 12:44:24 -08:00
2023-06-30 11:07:04 -08:00
Object.defineProperty(window, 'profileName', {
get() {
return getCurrentWindow().profileName;
},
set() {
throw new Error('profileName is readonly');
}
});
export function getConfig() {
2023-06-30 11:07:04 -08:00
return plugins.getDecoratedConfig(window.profileName);
2016-07-13 12:44:24 -08:00
}
2019-10-12 02:16:45 -08:00
export function subscribe(fn: (event: Electron.IpcRendererEvent, ...args: any[]) => void) {
2016-07-13 12:44:24 -08:00
ipcRenderer.on('config change', fn);
ipcRenderer.on('plugins change', fn);
2016-07-13 12:44:24 -08:00
return () => {
ipcRenderer.removeListener('config change', fn);
};
}