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
3 changes: 3 additions & 0 deletions app/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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});
};
Expand Down
370 changes: 314 additions & 56 deletions app/config/schema.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion app/extend-electron.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -22,6 +23,7 @@ declare global {
focusTime: number;
clean: () => void;
rpc: Server;
profileName: string;
}
}
}
7 changes: 4 additions & 3 deletions app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
10 changes: 10 additions & 0 deletions app/menus/menus/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,31 @@ export default (
submenu: [
{
label: 'New Tab',
accelerator: commandKeys[`tab:new:${profile}`],
click(item, focusedWindow) {
execCommand(`tab:new:${profile}`, focusedWindow);
}
},
{
label: 'New Window',
accelerator: commandKeys[`window:new:${profile}`],
click(item, focusedWindow) {
execCommand(`window:new:${profile}`, focusedWindow);
}
},
{
type: 'separator'
},
{
label: 'Split Down',
accelerator: commandKeys[`pane:splitDown:${profile}`],
click(item, focusedWindow) {
execCommand(`pane:splitDown:${profile}`, focusedWindow);
}
},
{
label: 'Split Right',
accelerator: commandKeys[`pane:splitRight:${profile}`],
click(item, focusedWindow) {
execCommand(`pane:splitRight:${profile}`, focusedWindow);
}
Expand Down
4 changes: 0 additions & 4 deletions app/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
13 changes: 8 additions & 5 deletions app/ui/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand All @@ -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');
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -161,7 +164,7 @@ export function newWindow(
},
extraOptionsFiltered,
{
profile: extraOptionsFiltered.profile || getDefaultProfile(),
profile: extraOptionsFiltered.profile || profileName,
uid
}
);
Expand Down
4 changes: 2 additions & 2 deletions lib/actions/term-groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
88 changes: 44 additions & 44 deletions lib/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,49 +19,22 @@ export type ColorMap = {
yellow: string;
};

type profileConfigOptions = {
/** for environment variables */
env: {[k: string]: string};
/**
* the shell to run when spawning a new session (e.g. /usr/local/bin/fish)
* if left empty, your system's login shell will be used by default
*
* Windows
* - Make sure to use a full path if the binary name doesn't work
* - Remove `--login` in shellArgs
*
* Windows Subsystem for Linux (WSL) - previously Bash on Windows
* - Example: `C:\\Windows\\System32\\wsl.exe`
*
* Git-bash on Windows
* - Example: `C:\\Program Files\\Git\\bin\\bash.exe`
*
* PowerShell on Windows
* - Example: `C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`
*
* Cygwin
* - Example: `C:\\cygwin64\\bin\\bash.exe`
*
* Git Bash
* - Example: `C:\\Program Files\\Git\\git-cmd.exe`
* Then Add `--command=usr/bin/bash.exe` to shellArgs
*/
shell: string;
/**
* for setting shell arguments (e.g. for using interactive shellArgs: `['-i']`)
* by default `['--login']` will be used
*/
shellArgs: string[];
/** set custom startup directory (must be an absolute path) */
workingDirectory: string;
};

type rootConfigOptions = {
/**
* if `true` (default), Hyper will update plugins every 5 hours
* you can also set it to a custom time e.g. `1d` or `2h`
*/
autoUpdatePlugins: boolean | string;
/** if `true` hyper will be set as the default protocol client for SSH */
defaultSSHApp: boolean;
/** if `true` hyper will not check for updates */
disableAutoUpdates: boolean;
/** choose either `'stable'` for receiving highly polished, or `'canary'` for less polished but more frequent updates */
updateChannel: 'stable' | 'canary';
useConpty?: boolean;
};

type profileConfigOptions = {
/**
* terminal background color
*
Expand Down Expand Up @@ -105,12 +78,10 @@ type rootConfigOptions = {
cursorColor: string;
/** `'BEAM'` for |, `'UNDERLINE'` for _, `'BLOCK'` for █ */
cursorShape: 'BEAM' | 'UNDERLINE' | 'BLOCK';
/** if `true` hyper will be set as the default protocol client for SSH */
defaultSSHApp: boolean;
/** if `true` hyper will not check for updates */
disableAutoUpdates: boolean;
/** if `false` Hyper will use ligatures provided by some fonts */
disableLigatures: boolean;
/** for environment variables */
env: {[k: string]: string};
/** font family with optional fallbacks */
fontFamily: string;
/** default font size in pixels for all tabs */
Expand Down Expand Up @@ -157,6 +128,36 @@ type rootConfigOptions = {
scrollback: number;
/** terminal selection color */
selectionColor: string;
/**
* the shell to run when spawning a new session (e.g. /usr/local/bin/fish)
* if left empty, your system's login shell will be used by default
*
* Windows
* - Make sure to use a full path if the binary name doesn't work
* - Remove `--login` in shellArgs
*
* Windows Subsystem for Linux (WSL) - previously Bash on Windows
* - Example: `C:\\Windows\\System32\\wsl.exe`
*
* Git-bash on Windows
* - Example: `C:\\Program Files\\Git\\bin\\bash.exe`
*
* PowerShell on Windows
* - Example: `C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`
*
* Cygwin
* - Example: `C:\\cygwin64\\bin\\bash.exe`
*
* Git Bash
* - Example: `C:\\Program Files\\Git\\git-cmd.exe`
* Then Add `--command=usr/bin/bash.exe` to shellArgs
*/
shell: string;
/**
* for setting shell arguments (e.g. for using interactive shellArgs: `['-i']`)
* by default `['--login']` will be used
*/
shellArgs: string[];
/**
* if you're using a Linux setup which show native menus, set to false
*
Expand All @@ -174,9 +175,6 @@ type rootConfigOptions = {
/** custom CSS to embed in the terminal window */
termCSS: string;
uiFontFamily?: string;
/** choose either `'stable'` for receiving highly polished, or `'canary'` for less polished but more frequent updates */
updateChannel: 'stable' | 'canary';
useConpty?: boolean;
/**
* Whether to use the WebGL renderer. Set it to false to use canvas-based
* rendering (slower, but supports transparent backgrounds)
Expand All @@ -189,6 +187,8 @@ type rootConfigOptions = {
webLinksActivationKey: 'ctrl' | 'alt' | 'meta' | 'shift' | '';
/** Initial window size in pixels */
windowSize?: [number, number];
/** set custom startup directory (must be an absolute path) */
workingDirectory: string;
};

export type configOptions = rootConfigOptions &
Expand Down
1 change: 1 addition & 0 deletions lib/hyper.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ declare global {
__rpcId: string;
rpc: Client;
focusActiveTerm: (uid?: string) => void;
profileName: string;
}

const snapshotResult: {
Expand Down
13 changes: 11 additions & 2 deletions lib/utils/config.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down