diff --git a/app/commands.ts b/app/commands.ts index 2b2ba795..e201355d 100644 --- a/app/commands.ts +++ b/app/commands.ts @@ -147,6 +147,9 @@ const commands: Record void> = { //Profile specific commands getConfig().profiles.forEach((profile) => { + commands[`window:new:${profile.name}`] = () => { + setTimeout(() => app.createWindow(undefined, undefined, profile.name), 0); + }; commands[`tab:new:${profile.name}`] = (focusedWindow) => { focusedWindow?.rpc.emit('termgroup add req', {profile: profile.name}); }; diff --git a/app/extend-electron.d.ts b/app/extend-electron.d.ts index 557d5cc1..e01f4e30 100644 --- a/app/extend-electron.d.ts +++ b/app/extend-electron.d.ts @@ -10,7 +10,8 @@ declare global { windowCallback?: (win: BrowserWindow) => void; createWindow: ( fn?: (win: BrowserWindow) => void, - options?: {size?: [number, number]; position?: [number, number]} + options?: {size?: [number, number]; position?: [number, number]}, + profileName?: string ) => BrowserWindow; setVersion: (version: string) => void; } @@ -22,6 +23,7 @@ declare global { focusTime: number; clean: () => void; rpc: Server; + profileName: string; } } } diff --git a/app/index.ts b/app/index.ts index a0c428d9..9ad26c06 100644 --- a/app/index.ts +++ b/app/index.ts @@ -90,9 +90,10 @@ app.on('ready', () => .then(() => { function createWindow( fn?: (win: BrowserWindow) => void, - options: {size?: [number, number]; position?: [number, number]} = {} + options: {size?: [number, number]; position?: [number, number]} = {}, + profileName: string = config.getDefaultProfile() ) { - const cfg = plugins.getDecoratedConfig(config.getDefaultProfile()); + const cfg = plugins.getDecoratedConfig(profileName); const winSet = config.getWin(); let [startX, startY] = winSet.position; @@ -134,7 +135,7 @@ app.on('ready', () => [startX, startY] = config.windowDefaults.windowPosition; } - const hwin = newWindow({width, height, x: startX, y: startY}, cfg, fn); + const hwin = newWindow({width, height, x: startX, y: startY}, cfg, fn, profileName); windowSet.add(hwin); void hwin.loadURL(url); diff --git a/app/menus/menus/shell.ts b/app/menus/menus/shell.ts index 99d65723..9b4c1947 100644 --- a/app/menus/menus/shell.ts +++ b/app/menus/menus/shell.ts @@ -54,6 +54,12 @@ export default ( execCommand(`tab:new:${profile}`, focusedWindow); } }, + { + label: 'New Window', + click(item, focusedWindow) { + execCommand(`window:new:${profile}`, focusedWindow); + } + }, { type: 'separator' }, diff --git a/app/plugins.ts b/app/plugins.ts index ecfe75f2..a839c435 100644 --- a/app/plugins.ts +++ b/app/plugins.ts @@ -425,10 +425,6 @@ export const getDecoratedEnv = (baseEnv: Record) => { return decorateObject(baseEnv, 'decorateEnv'); }; -export const getDefaultProfile = () => { - return config.getDefaultProfile(); -}; - export const getDecoratedConfig = (profile: string) => { const baseConfig = config.getProfileConfig(profile); const decoratedConfig = decorateObject(baseConfig, 'decorateConfig'); diff --git a/app/ui/window.ts b/app/ui/window.ts index 2e6c1434..519adb1c 100644 --- a/app/ui/window.ts +++ b/app/ui/window.ts @@ -25,7 +25,8 @@ import {getDefaultProfile} from '../config'; export function newWindow( options_: BrowserWindowConstructorOptions, cfg: configOptions, - fn?: (win: BrowserWindow) => void + fn?: (win: BrowserWindow) => void, + profileName: string = getDefaultProfile() ): BrowserWindow { const classOpts = Object.assign({uid: uuidv4()}); app.plugins.decorateWindowClass(classOpts); @@ -51,6 +52,8 @@ export function newWindow( }; const window = new BrowserWindow(app.plugins.getDecoratedBrowserOptions(winOpts)); + window.profileName = profileName; + // Enable remote module on this window remoteEnable(window.webContents); @@ -63,13 +66,13 @@ export function newWindow( const sessions = new Map(); const updateBackgroundColor = () => { - const cfg_ = app.plugins.getDecoratedConfig(getDefaultProfile()); + const cfg_ = app.plugins.getDecoratedConfig(profileName); window.setBackgroundColor(toElectronBackgroundColor(cfg_.backgroundColor || '#000')); }; // config changes const cfgUnsubscribe = app.config.subscribe(() => { - const cfg_ = app.plugins.getDecoratedConfig(getDefaultProfile()); + const cfg_ = app.plugins.getDecoratedConfig(profileName); // notify renderer window.webContents.send('config change'); @@ -119,7 +122,7 @@ export function newWindow( if (extraOptions[key] !== undefined) extraOptionsFiltered[key] = extraOptions[key]; }); - const profile = extraOptionsFiltered.profile || getDefaultProfile(); + const profile = extraOptionsFiltered.profile || profileName; const activeSession = extraOptionsFiltered.activeUid ? sessions.get(extraOptionsFiltered.activeUid) : undefined; let cwd = ''; if (cfg.preserveCWD !== false && activeSession && activeSession.profile === profile) { @@ -161,7 +164,7 @@ export function newWindow( }, extraOptionsFiltered, { - profile: extraOptionsFiltered.profile || getDefaultProfile(), + profile: extraOptionsFiltered.profile || profileName, uid } ); diff --git a/lib/actions/term-groups.ts b/lib/actions/term-groups.ts index 4210a33c..45dd1327 100644 --- a/lib/actions/term-groups.ts +++ b/lib/actions/term-groups.ts @@ -20,7 +20,7 @@ function requestSplit(direction: 'VERTICAL' | 'HORIZONTAL') { effect: () => { const {ui, sessions} = getState(); const activeUid = _activeUid ? _activeUid : sessions.activeUid; - const profile = _profile ? _profile : activeUid ? sessions.sessions[activeUid].profile : undefined; + const profile = _profile ? _profile : activeUid ? sessions.sessions[activeUid].profile : window.profileName; rpc.emit('new', { splitDirection: direction, cwd: ui.cwd, @@ -51,7 +51,7 @@ export function requestTermGroup(_activeUid: string | undefined, _profile: strin const {ui, sessions} = getState(); const {cwd} = ui; const activeUid = _activeUid ? _activeUid : sessions.activeUid; - const profile = _profile ? _profile : activeUid ? sessions.sessions[activeUid].profile : undefined; + const profile = _profile ? _profile : activeUid ? sessions.sessions[activeUid].profile : window.profileName; rpc.emit('new', { isNewGroup: true, cwd, diff --git a/lib/hyper.d.ts b/lib/hyper.d.ts index 1996ca7f..90c67012 100644 --- a/lib/hyper.d.ts +++ b/lib/hyper.d.ts @@ -6,6 +6,7 @@ declare global { __rpcId: string; rpc: Client; focusActiveTerm: (uid?: string) => void; + profileName: string; } const snapshotResult: { diff --git a/lib/utils/config.ts b/lib/utils/config.ts index b3539422..0cdab4d8 100644 --- a/lib/utils/config.ts +++ b/lib/utils/config.ts @@ -1,11 +1,20 @@ import {ipcRenderer} from 'electron'; -import {require as remoteRequire} from '@electron/remote'; +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'); +Object.defineProperty(window, 'profileName', { + get() { + return getCurrentWindow().profileName; + }, + set() { + throw new Error('profileName is readonly'); + } +}); + export function getConfig() { - return plugins.getDecoratedConfig(plugins.getDefaultProfile()); + return plugins.getDecoratedConfig(window.profileName); } export function subscribe(fn: (event: Electron.IpcRendererEvent, ...args: any[]) => void) {