mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-12 20:18:41 -09:00
Add profile > new window menu
This commit is contained in:
parent
354c0aa7dd
commit
fd20ce660a
9 changed files with 38 additions and 17 deletions
|
|
@ -147,6 +147,9 @@ const commands: Record<string, (focusedWindow?: BrowserWindow) => 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});
|
||||
};
|
||||
|
|
|
|||
4
app/extend-electron.d.ts
vendored
4
app/extend-electron.d.ts
vendored
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -54,6 +54,12 @@ export default (
|
|||
execCommand(`tab:new:${profile}`, focusedWindow);
|
||||
}
|
||||
},
|
||||
{
|
||||
label: 'New Window',
|
||||
click(item, focusedWindow) {
|
||||
execCommand(`window:new:${profile}`, focusedWindow);
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'separator'
|
||||
},
|
||||
|
|
|
|||
|
|
@ -425,10 +425,6 @@ export const getDecoratedEnv = (baseEnv: Record<string, string>) => {
|
|||
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');
|
||||
|
|
|
|||
|
|
@ -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<string, Session>();
|
||||
|
||||
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
|
||||
}
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
1
lib/hyper.d.ts
vendored
1
lib/hyper.d.ts
vendored
|
|
@ -6,6 +6,7 @@ declare global {
|
|||
__rpcId: string;
|
||||
rpc: Client;
|
||||
focusActiveTerm: (uid?: string) => void;
|
||||
profileName: string;
|
||||
}
|
||||
|
||||
const snapshotResult: {
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue