Merge branch 'canary'

This commit is contained in:
Labhansh Agrawal 2021-08-03 19:22:23 +05:30
commit 584045ecc1
15 changed files with 367 additions and 290 deletions

View file

@ -157,6 +157,9 @@ module.exports = {
// if `false` (without backticks and without quotes), Hyper will use ligatures provided by some fonts
disableLigatures: true,
// set to true to disable auto updates
disableAutoUpdates: false,
// for advanced config flags please refer to https://hyper.is/#cfg
},

View file

@ -12,13 +12,12 @@
"dependencies": {
"async-retry": "1.3.1",
"chokidar": "^3.5.2",
"color": "3.1.3",
"color": "4.0.0",
"convert-css-color-name-to-hex": "0.1.1",
"default-shell": "1.0.1",
"electron-fetch": "1.7.3",
"electron-is-dev": "2.0.0",
"electron-store": "8.0.0",
"file-uri-to-path": "2.0.0",
"fs-extra": "10.0.0",
"git-describe": "4.0.4",
"lodash": "4.17.21",

View file

@ -1,7 +1,7 @@
/* eslint-disable eslint-comments/disable-enable-pair */
/* eslint-disable @typescript-eslint/no-unsafe-return */
/* eslint-disable @typescript-eslint/no-unsafe-call */
import {app, dialog, BrowserWindow, App} from 'electron';
import {app, dialog, BrowserWindow, App, ipcMain} from 'electron';
import {resolve, basename} from 'path';
import {writeFileSync} from 'fs';
import Config from 'electron-store';
@ -15,6 +15,8 @@ import {install} from './plugins/install';
import {plugs} from './config/paths';
import mapKeys from './utils/map-keys';
import {configOptions} from '../lib/config';
import {promisify} from 'util';
import {exec, execFile} from 'child_process';
// local storage
const cache = new Config();
@ -449,3 +451,13 @@ export const decorateSessionClass = <T>(Session: T): T => {
};
export {toDependencies as _toDependencies};
ipcMain.handle('child_process.exec', (event, args) => {
const {command, options} = args;
return promisify(exec)(command, options);
});
ipcMain.handle('child_process.execFile', (event, _args) => {
const {file, args, options} = _args;
return promisify(execFile)(file, args, options);
});

View file

@ -1,8 +1,7 @@
import {app, BrowserWindow, shell, Menu, BrowserWindowConstructorOptions} from 'electron';
import {app, BrowserWindow, shell, Menu, BrowserWindowConstructorOptions, Event} from 'electron';
import {isAbsolute, normalize, sep} from 'path';
import {parse as parseUrl} from 'url';
import {URL, fileURLToPath} from 'url';
import {v4 as uuidv4} from 'uuid';
import fileUriToPath from 'file-uri-to-path';
import isDev from 'electron-is-dev';
import updater from '../updater';
import toElectronBackgroundColor from '../utils/to-electron-background-color';
@ -259,30 +258,22 @@ export function newWindow(
}
});
// If file is dropped onto the terminal window, navigate event is prevented
// and his path is added to active session.
window.webContents.on('will-navigate', (event, url) => {
const protocol = typeof url === 'string' && parseUrl(url).protocol;
const handleDrop = (event: Event, url: string) => {
const protocol = typeof url === 'string' && new URL(url).protocol;
if (protocol === 'file:') {
event.preventDefault();
const path = fileUriToPath(url);
const path = fileURLToPath(url);
rpc.emit('session data send', {data: path, escaped: true});
} else if (protocol === 'http:' || protocol === 'https:') {
event.preventDefault();
rpc.emit('session data send', {data: url});
}
});
};
// xterm makes link clickable
window.webContents.on('new-window', (event, url) => {
const protocol = typeof url === 'string' && parseUrl(url).protocol;
if (protocol === 'http:' || protocol === 'https:') {
event.preventDefault();
void shell.openExternal(url);
}
});
// If file is dropped onto the terminal window, navigate and new-window events are prevented
// and his path is added to active session.
window.webContents.on('will-navigate', handleDrop);
window.webContents.on('new-window', handleDrop);
// expose internals to extension authors
window.rpc = rpc;

View file

@ -7,19 +7,53 @@ 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';
const autoUpdater: AutoUpdater = isLinux ? autoUpdaterLinux : electron.autoUpdater;
const getDecoratedConfigWithRetry = async () => {
return await retry(() => {
const content = getDecoratedConfig();
if (!content) {
throw new Error('No config content loaded');
}
return content;
});
};
const checkForUpdates = async () => {
const config = await getDecoratedConfigWithRetry();
if (!config.disableAutoUpdates) {
autoUpdater.checkForUpdates();
}
};
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';
return `https://${updatePrefix}.hyper.is/update/${isLinux ? 'deb' : platform}/${currentVersion}`;
const archSuffix = process.arch === 'arm64' || isRosetta() ? '_arm64' : '';
return `https://${updatePrefix}.hyper.is/update/${isLinux ? 'deb' : platform}${archSuffix}/${currentVersion}`;
};
const isCanary = (updateChannel: string) => updateChannel === 'canary';
@ -29,15 +63,7 @@ async function init() {
console.error('Error fetching updates', `${err.message} (${err.stack})`);
});
const config = await retry(() => {
const content = getDecoratedConfig();
if (!content) {
throw new Error('No config content loaded');
}
return content;
});
const config = await getDecoratedConfigWithRetry();
// If defined in the config, switch to the "canary" channel
if (config.updateChannel && isCanary(config.updateChannel)) {
@ -49,11 +75,11 @@ async function init() {
autoUpdater.setFeedURL({url: feedURL});
setTimeout(() => {
autoUpdater.checkForUpdates();
void checkForUpdates();
}, ms('10s'));
setInterval(() => {
autoUpdater.checkForUpdates();
void checkForUpdates();
}, ms('30m'));
isInit = true;
@ -86,15 +112,15 @@ export default (win: BrowserWindow) => {
autoUpdater.quitAndInstall();
});
app.config.subscribe(() => {
const {updateChannel} = app.plugins.getDecoratedConfig();
app.config.subscribe(async () => {
const {updateChannel} = await getDecoratedConfigWithRetry();
const newUpdateIsCanary = isCanary(updateChannel);
if (newUpdateIsCanary !== canaryUpdates) {
const feedURL = buildFeedUrl(newUpdateIsCanary, version);
autoUpdater.setFeedURL({url: feedURL});
autoUpdater.checkForUpdates();
void checkForUpdates();
canaryUpdates = newUpdateIsCanary;
}

View file

@ -71,38 +71,33 @@ chokidar@^3.5.2:
optionalDependencies:
fsevents "~2.3.2"
color-convert@^1.9.1:
version "1.9.3"
resolved "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz#bb71850690e1f136567de629d2d5471deda4c1e8"
integrity sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==
color-convert@^2.0.1:
version "2.0.1"
resolved "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz#72d3a68d598c9bdb3af2ad1e84f21d896abd4de3"
integrity sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==
dependencies:
color-name "1.1.3"
color-name "~1.1.4"
color-name@1.1.3:
version "1.1.3"
resolved "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25"
integrity sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=
color-name@^1.0.0:
color-name@^1.0.0, color-name@~1.1.4:
version "1.1.4"
resolved "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2"
integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==
color-string@^1.5.4:
version "1.5.5"
resolved "https://registry.npmjs.org/color-string/-/color-string-1.5.5.tgz#65474a8f0e7439625f3d27a6a19d89fc45223014"
integrity sha512-jgIoum0OfQfq9Whcfc2z/VhCNcmQjWbey6qBX0vqt7YICflUmBCh9E9CiQD5GSJ+Uehixm3NUwHVhqUAWRivZg==
color-string@^1.6.0:
version "1.6.0"
resolved "https://registry.npmjs.org/color-string/-/color-string-1.6.0.tgz#c3915f61fe267672cb7e1e064c9d692219f6c312"
integrity sha512-c/hGS+kRWJutUBEngKKmk4iH3sD59MBkoxVapS/0wgpCz2u7XsNloxknyvBhzwEs1IbV36D9PwqLPJ2DTu3vMA==
dependencies:
color-name "^1.0.0"
simple-swizzle "^0.2.2"
color@3.1.3:
version "3.1.3"
resolved "https://registry.npmjs.org/color/-/color-3.1.3.tgz#ca67fb4e7b97d611dcde39eceed422067d91596e"
integrity sha512-xgXAcTHa2HeFCGLE9Xs/R82hujGtu9Jd9x4NW3T34+OMs7VoPsjwzRczKHvTAHeJwWFwX5j15+MgAppE8ztObQ==
color@4.0.0:
version "4.0.0"
resolved "https://registry.npmjs.org/color/-/color-4.0.0.tgz#7f0c89d3fcf04c45e20c81c7c24cd73314acac1f"
integrity sha512-aVUOa5aYWJSimvei14J5rdxLeljG0EB/uXTovVaaSokW+D4MsAz3MrKsRNaKqPa2KL7Wfvh7PZyIIaaX4lYdzQ==
dependencies:
color-convert "^1.9.1"
color-string "^1.5.4"
color-convert "^2.0.1"
color-string "^1.6.0"
conf@^10.0.0:
version "10.0.1"
@ -249,11 +244,6 @@ fast-deep-equal@^3.1.1:
resolved "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz#3a7d56b559d6cbc3eb512325244e619a65c6c525"
integrity sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==
file-uri-to-path@2.0.0:
version "2.0.0"
resolved "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-2.0.0.tgz#7b415aeba227d575851e0a5b0c640d7656403fba"
integrity sha512-hjPFI8oE/2iQPVe4gbrJ73Pp+Xfub2+WI2LlXDbsaJBwT5wuMh35WNWVYYTpnz895shtwfyutMFLFywpQAFdLg==
fill-range@^7.0.1:
version "7.0.1"
resolved "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz#1919a6a7c75fe38b2c7c77e5198535da9acdda40"