Skip to content

Commit

Permalink
Merge branch 'canary'
Browse files Browse the repository at this point in the history
  • Loading branch information
LabhanshAgrawal committed Feb 4, 2022
2 parents 355f507 + 70f4564 commit b96a388
Show file tree
Hide file tree
Showing 25 changed files with 307 additions and 341 deletions.
3 changes: 3 additions & 0 deletions app/config/config-default.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ module.exports = {
// set to true to enable screen reading apps (like NVDA) to read the contents of the terminal
screenReaderMode: false,

// set to true to preserve working directory when creating splits or tabs
preserveCWD: true,

// for advanced config flags please refer to https://hyper.is/#cfg
},

Expand Down
42 changes: 22 additions & 20 deletions app/extend-electron.d.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
import type {Server} from './rpc';

declare module 'electron' {
interface App {
config: typeof import('./config');
plugins: typeof import('./plugins');
getWindows: () => Set<BrowserWindow>;
getLastFocusedWindow: () => BrowserWindow | null;
windowCallback?: (win: BrowserWindow) => void;
createWindow: (
fn?: (win: BrowserWindow) => void,
options?: {size?: [number, number]; position?: [number, number]}
) => BrowserWindow;
setVersion: (version: string) => void;
}
declare global {
namespace Electron {
interface App {
config: typeof import('./config');
plugins: typeof import('./plugins');
getWindows: () => Set<BrowserWindow>;
getLastFocusedWindow: () => BrowserWindow | null;
windowCallback?: (win: BrowserWindow) => void;
createWindow: (
fn?: (win: BrowserWindow) => void,
options?: {size?: [number, number]; position?: [number, number]}
) => BrowserWindow;
setVersion: (version: string) => void;
}

// type Server = import('./rpc').Server;
interface BrowserWindow {
uid: string;
sessions: Map<any, any>;
focusTime: number;
clean: () => void;
rpc: Server;
// type Server = import('./rpc').Server;
interface BrowserWindow {
uid: string;
sessions: Map<any, any>;
focusTime: number;
clean: () => void;
rpc: Server;
}
}
}
2 changes: 1 addition & 1 deletion app/menus/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const createMenu = (
void dialog.showMessageBox({
title: `About ${appName}`,
message: `${appName} ${appVersion} (${updateChannel})`,
detail: `Renderers: ${renderers}\nPlugins: ${pluginList}\n\nCreated by Guillermo Rauch\nCopyright © 2021 Vercel, Inc.`,
detail: `Renderers: ${renderers}\nPlugins: ${pluginList}\n\nCreated by Guillermo Rauch\nCopyright © 2022 Vercel, Inc.`,
buttons: [],
icon: icon as any
});
Expand Down
2 changes: 1 addition & 1 deletion app/menus/menus/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default (
execCommand: (command: string, focusedWindow?: BrowserWindow) => void
): MenuItemConstructorOptions => {
// Generating tab:jump array
const tabJump = [];
const tabJump: MenuItemConstructorOptions[] = [];
for (let i = 1; i <= 9; i++) {
// 9 is a special number because it means 'last'
const label = i === 9 ? 'Last' : `${i}`;
Expand Down
7 changes: 4 additions & 3 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
},
"repository": "zeit/hyper",
"dependencies": {
"@electron/remote": "2.0.1",
"@electron/remote": "2.0.4",
"async-retry": "1.3.3",
"chokidar": "^3.5.2",
"color": "4.1.0",
"chokidar": "^3.5.3",
"color": "4.2.0",
"default-shell": "1.0.1",
"electron-fetch": "1.7.4",
"electron-is-dev": "2.0.0",
Expand All @@ -23,6 +23,7 @@
"lodash": "4.17.21",
"mkdirp": "1.0.4",
"ms": "2.1.3",
"native-process-working-directory": "^1.0.2",
"node-pty": "0.10.1",
"os-locale": "5.0.0",
"parse-url": "5.0.7",
Expand Down
2 changes: 1 addition & 1 deletion app/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ function toDependencies(plugins_: {plugins: string[]}) {

if (match) {
const index = match.index + 1;
const pieces = [];
const pieces: string[] = [];

pieces[0] = plugin.substring(0, index);
pieces[1] = plugin.substring(index + 1, plugin.length);
Expand Down
3 changes: 2 additions & 1 deletion app/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"extends": "../tsconfig.base.json",
"compilerOptions": {
"declarationDir": "../dist/tmp/appdts/",
"outDir": "../target/"
"outDir": "../target/",
"noImplicitAny": false
},
"include": [
"./**/*",
Expand Down
17 changes: 15 additions & 2 deletions app/ui/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ import {execCommand} from '../commands';
import {setRendererType, unsetRendererType} from '../utils/renderer-utils';
import {decorateSessionOptions, decorateSessionClass} from '../plugins';
import {enable as remoteEnable} from '@electron/remote/main';
import {configOptions} from '../../lib/config';
import {getWorkingDirectoryFromPID} from 'native-process-working-directory';

export function newWindow(
options_: BrowserWindowConstructorOptions,
cfg: any,
cfg: configOptions,
fn?: (win: BrowserWindow) => void
): BrowserWindow {
const classOpts = Object.assign({uid: uuidv4()});
Expand Down Expand Up @@ -128,10 +130,21 @@ export function newWindow(
if (extraOptions[key] !== undefined) extraOptionsFiltered[key] = extraOptions[key];
});

let cwd = '';
if (cfg.preserveCWD === undefined || cfg.preserveCWD) {
const activePID = extraOptionsFiltered.activeUid && sessions.get(extraOptionsFiltered.activeUid)?.pty?.pid;
try {
cwd = activePID && getWorkingDirectoryFromPID(activePID);
} catch (error) {
console.error(error);
}
cwd = cwd && isAbsolute(cwd) ? cwd : '';
}

// remove the rows and cols, the wrong value of them will break layout when init create
const defaultOptions = Object.assign(
{
cwd: workingDirectory,
cwd: cwd || workingDirectory,
splitDirection: undefined,
shell: cfg.shell,
shellArgs: cfg.shellArgs && Array.from(cfg.shellArgs)
Expand Down
18 changes: 1 addition & 17 deletions app/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import retry from 'async-retry';
import {version} from './package.json';
import {getDecoratedConfig} from './plugins';
import autoUpdaterLinux from './auto-updater-linux';
import {execSync} from 'child_process';

const {platform} = process;
const isLinux = platform === 'linux';
Expand Down Expand Up @@ -35,24 +34,9 @@ let isInit = false;
// Default to the "stable" update channel
let canaryUpdates = false;

// Detect if we are running inside Rosetta emulation
const isRosetta = () => {
if (platform !== 'darwin') {
return false;
}
const sysctlRosettaInfoKey = 'sysctl.proc_translated';
let results = '';
try {
results = execSync(`sysctl ${sysctlRosettaInfoKey}`).toString();
} catch (error) {
console.log('Failed to detect Rosetta');
}
return results.includes(`${sysctlRosettaInfoKey}: 1`);
};

const buildFeedUrl = (canary: boolean, currentVersion: string) => {
const updatePrefix = canary ? 'releases-canary' : 'releases';
const archSuffix = process.arch === 'arm64' || isRosetta() ? '_arm64' : '';
const archSuffix = process.arch === 'arm64' || app.runningUnderARM64Translation ? '_arm64' : '';
return `https://${updatePrefix}.hyper.is/update/${isLinux ? 'deb' : platform}${archSuffix}/${currentVersion}`;
};

Expand Down
36 changes: 24 additions & 12 deletions app/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# yarn lockfile v1


"@electron/[email protected].1":
version "2.0.1"
resolved "https://registry.npmjs.org/@electron/remote/-/remote-2.0.1.tgz#810cbc595a21f0f94641eb2d7e8264063a3f84de"
integrity sha512-bGX4/yB2bPZwXm1DsxgoABgH0Cz7oFtXJgkerB8VrStYdTyvhGAULzNLRn9rVmeAuC3VUDXaXpZIlZAZHpsLIA==
"@electron/[email protected].4":
version "2.0.4"
resolved "https://registry.npmjs.org/@electron/remote/-/remote-2.0.4.tgz#c3dae436aed79d1b8adcefc5a4963c06750ad5d8"
integrity sha512-8m2P/d2RH986PmMW5lKygbPEjEYJ7RgCe37Y8DQ1wujKMH6VjmLIB+Y+DP2SA611svCZc58TRSd8FraGvcfGZw==

"@types/semver@^7.3.8":
version "7.3.8"
Expand Down Expand Up @@ -61,10 +61,10 @@ braces@~3.0.2:
dependencies:
fill-range "^7.0.1"

chokidar@^3.5.2:
version "3.5.2"
resolved "https://registry.npmjs.org/chokidar/-/chokidar-3.5.2.tgz#dba3976fcadb016f66fd365021d91600d01c1e75"
integrity sha512-ekGhOnNVPgT77r4K/U3GDhu+FQ2S8TnK/s2KbIGXi0SZWuwkZ2QNyfWdZW+TVfn84DpEP7rLeCt2UI6bJ8GwbQ==
chokidar@^3.5.3:
version "3.5.3"
resolved "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz#1cf37c8707b932bd1af1ae22c0432e2acd1903bd"
integrity sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==
dependencies:
anymatch "~3.1.2"
braces "~3.0.2"
Expand Down Expand Up @@ -96,10 +96,10 @@ color-string@^1.9.0:
color-name "^1.0.0"
simple-swizzle "^0.2.2"

color@4.1.0:
version "4.1.0"
resolved "https://registry.npmjs.org/color/-/color-4.1.0.tgz#9502e6a2dcacb26adf4c60910a27628d010b3de3"
integrity sha512-o2rkkxyLGgYoeUy1OodXpbPAQNmlNBrirQ8ODO8QutzDiDMNdezSOZLNnusQ6pUpCQJUsaJIo9DZJKqa2HgH7A==
color@4.2.0:
version "4.2.0"
resolved "https://registry.npmjs.org/color/-/color-4.2.0.tgz#0c782459a3e98838ea01e4bc0fb43310ca35af78"
integrity sha512-hHTcrbvEnGjC7WBMk6ibQWFVDgEFTVmjrz2Q5HlU6ltwxv0JJN2Z8I7uRbWeQLF04dikxs8zgyZkazRJvSMtyQ==
dependencies:
color-convert "^2.0.1"
color-string "^1.9.0"
Expand Down Expand Up @@ -441,13 +441,25 @@ nan@^2.14.0:
resolved "https://registry.npmjs.org/nan/-/nan-2.14.2.tgz#f5376400695168f4cc694ac9393d0c9585eeea19"
integrity sha512-M2ufzIiINKCuDfBSAUr1vWQ+vuVcA9kqx8JJUsbQi6yf1uGRyb7HfpdfUr5qLXf3B/t8dPvcjhKMmlfnP47EzQ==

native-process-working-directory@^1.0.2:
version "1.0.2"
resolved "https://registry.npmjs.org/native-process-working-directory/-/native-process-working-directory-1.0.2.tgz#7843e2fa1490f53cf8d2c7d1913de8b275e8b89a"
integrity sha512-3a67QQV8r3YMUTSOgvtMOCjPDgCpb/8xjv93L8Cqb8bv3hOKsWis4/+8HCu3bgj8ADQV75SCYFSsAGM5G0cXmQ==
dependencies:
node-addon-api "^3.1.0"

[email protected]:
version "1.0.0"
resolved "https://registry.npmjs.org/native-reg/-/native-reg-1.0.0.tgz#77f9acbf59eda02680c00b0b1b9d1e0078b7820d"
integrity sha512-MxukmqY7jOeiS9+b4TAlfG9cvaQ03oLET35nUGYGHDRcLx0NFk7eeoWqX4wAXaFiMW50ZiFalOA6W8q3fprcsw==
dependencies:
node-gyp-build "4"

node-addon-api@^3.1.0:
version "3.2.1"
resolved "https://registry.npmjs.org/node-addon-api/-/node-addon-api-3.2.1.tgz#81325e0a2117789c0128dab65e7e38f07ceba161"
integrity sha512-mmcei9JghVNDYydghQmeDX8KoAm0FAiYyIcUt/N4nhyAipB17pllZQDOJD2fotxABnt4Mdz+dKTO7eftLg4d0A==

node-gyp-build@4:
version "4.3.0"
resolved "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.3.0.tgz#9f256b03e5826150be39c764bf51e993946d71a3"
Expand Down
8 changes: 6 additions & 2 deletions electron-builder.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@
"afterInstall": "./build/linux/after-install.tpl"
},
"rpm": {
"afterInstall": "./build/linux/after-install.tpl"
"afterInstall": "./build/linux/after-install.tpl",
"fpm": [
"--rpm-rpmbuild-define",
"_build_id_links none"
]
},
"snap": {
"confinement": "classic",
Expand All @@ -132,4 +136,4 @@
"ssh"
]
}
}
}
13 changes: 7 additions & 6 deletions lib/actions/sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import {
SESSION_CLEAR_ACTIVE,
SESSION_USER_DATA,
SESSION_SET_XTERM_TITLE,
SESSION_SEARCH,
SESSION_SEARCH_CLOSE
SESSION_SEARCH
} from '../constants/sessions';
import {HyperState, session, HyperDispatch, HyperActions} from '../hyper';

Expand Down Expand Up @@ -135,12 +134,13 @@ export function resizeSession(uid: string, cols: number, rows: number) {
};
}

export function onSearch(uid?: string) {
export function openSearch(uid?: string) {
return (dispatch: HyperDispatch, getState: () => HyperState) => {
const targetUid = uid || getState().sessions.activeUid!;
dispatch({
type: SESSION_SEARCH,
uid: targetUid
uid: targetUid,
value: true
});
};
}
Expand All @@ -150,8 +150,9 @@ export function closeSearch(uid?: string, keyEvent?: any) {
const targetUid = uid || getState().sessions.activeUid!;
if (getState().sessions.sessions[targetUid]?.search) {
dispatch({
type: SESSION_SEARCH_CLOSE,
uid: targetUid
type: SESSION_SEARCH,
uid: targetUid,
value: false
});
} else {
if (keyEvent) {
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 @@ -45,12 +45,12 @@ export function requestTermGroup(activeUid: string) {
dispatch({
type: TERM_GROUP_REQUEST,
effect: () => {
const {ui} = getState();
const {ui, sessions} = getState();
const {cwd} = ui;
rpc.emit('new', {
isNewGroup: true,
cwd,
activeUid
activeUid: activeUid ? activeUid : sessions.activeUid
});
}
});
Expand Down
3 changes: 2 additions & 1 deletion lib/components/term-group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ class TermGroup_ extends React.PureComponent<TermGroupProps> {
onResize: this.bind(this.props.onResize, null, uid),
onTitle: this.bind(this.props.onTitle, null, uid),
onData: this.bind(this.props.onData, null, uid),
toggleSearch: this.bind(this.props.toggleSearch, null, uid),
onOpenSearch: this.bind(this.props.onOpenSearch, null, uid),
onCloseSearch: this.bind(this.props.onCloseSearch, null, uid),
onContextMenu: this.bind(this.props.onContextMenu, null, uid),
borderColor: this.props.borderColor,
selectionColor: this.props.selectionColor,
Expand Down
3 changes: 2 additions & 1 deletion lib/components/term.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@ export default class Term extends React.PureComponent<TermProps> {
};

closeSearchBox = () => {
this.props.toggleSearch();
this.props.onCloseSearch();
this.term.focus();
};

resize(cols: number, rows: number) {
Expand Down
3 changes: 2 additions & 1 deletion lib/components/terms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ export default class Terms extends React.Component<TermsProps> {
onResize: this.props.onResize,
onTitle: this.props.onTitle,
onData: this.props.onData,
toggleSearch: this.props.toggleSearch,
onOpenSearch: this.props.onOpenSearch,
onCloseSearch: this.props.onCloseSearch,
onContextMenu: this.props.onContextMenu,
quickEdit: this.props.quickEdit,
webGLRenderer: this.props.webGLRenderer,
Expand Down
2 changes: 2 additions & 0 deletions lib/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export type configOptions = {
cmdIsMeta: boolean;
};
padding: string;
preserveCWD: boolean;
quickEdit: boolean;
screenReaderMode: boolean;
scrollback: number;
Expand All @@ -65,6 +66,7 @@ export type configOptions = {
webGLRenderer: boolean;
webLinksActivationKey: 'ctrl' | 'alt' | 'meta' | 'shift';
windowSize: [number, number];
workingDirectory: string;
};

export type rawConfig = {
Expand Down
Loading

0 comments on commit b96a388

Please sign in to comment.