Skip to content
This repository has been archived by the owner on May 21, 2019. It is now read-only.

Commit

Permalink
Merge branch 'master' into strict-null-checks
Browse files Browse the repository at this point in the history
  • Loading branch information
vlad-shatskyi committed May 13, 2016
2 parents be11e30 + e4b1698 commit a037922
Show file tree
Hide file tree
Showing 18 changed files with 116 additions and 167 deletions.
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
"shell",
"console"
],
"electronVersion": "0.37.8",
"dependencies": {
"chokidar": "1.4.3",
"chokidar": "1.5.0",
"fixed-sticky": "0.1.7",
"font-awesome": "4.6.1",
"fs-extra": "0.30.0",
Expand All @@ -46,7 +45,7 @@
"chai": "3.5.0",
"del": "2.2.0",
"electron-packager": "7.0.1",
"electron-prebuilt": "0.37.8",
"electron-prebuilt": "1.0.1",
"electron-rebuild": "1.1.3",
"gulp": "3.9.1",
"gulp-cached": "1.1.0",
Expand All @@ -63,18 +62,19 @@
"npm-check-updates": "2.6.4",
"run-sequence": "1.1.5",
"ts-node": "0.7.2",
"tslint": "3.9.0",
"tslint": "3.10.1",
"typescript": "1.9.0-dev.20160425",
"typings": "0.8.1"
},
"scripts": {
"preinstall": "npm prune",
"postinstall": "npm run recompile",
"recompile": "HOME=~/.electron-gyp cd node_modules/pty.js; node-gyp rebuild --target=$npm_package_electronVersion --arch=x64 --dist-url=https://atom.io/download/atom-shell",
"electron-version": "cat package.json | grep 'electron-prebuilt\": \"' | cut -d '\"' -f 4",
"recompile": "export ELECTRON_VERSION=$(npm run electron-version --silent); HOME=~/.electron-gyp cd node_modules/pty.js; node-gyp rebuild --target=$ELECTRON_VERSION --arch=x64 --dist-url=https://atom.io/download/atom-shell",
"electron": "electron .",
"start": "gulp",
"package": "gulp build && electron-packager . \"$npm_package_productName\" --overwrite --platform=darwin --arch=x64 --version=$npm_package_electronVersion --out='/Applications' --icon='./icon.icns' --asar=true",
"test": "mocha --require ts-node/register test/**",
"package": "gulp build && electron-packager . \"$npm_package_productName\" --overwrite --platform=darwin --arch=x64 --version=$(npm run electron-version --silent) --out='/Applications' --icon='./icon.icns' --asar=true",
"test": "ELECTRON_RUN_AS_NODE=1 electron $(which mocha) --require ts-node/register test/**",
"update-typings": "typings ls | awk '$2 ~ /.+/ {print $2}' | xargs -I {} typings i '{}' -S -A --source dt",
"update-dependencies": "ncu -u",
"lint": "tslint `find src -name '*.ts*'`",
Expand Down
4 changes: 2 additions & 2 deletions src/Buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as i from "./Interfaces";
import * as e from "./Enums";
import {List} from "immutable";
import {error, times} from "./utils/Common";
const shell: Electron.Shell = require("remote").require("electron").shell;
import {remote} from "electron";

export default class Buffer extends events.EventEmitter {
public static hugeOutputThreshold = 300;
Expand All @@ -32,7 +32,7 @@ export default class Buffer extends events.EventEmitter {
if (charObject.isSpecial()) {
switch (charObject.keyCode) {
case e.KeyCode.Bell:
shell.beep();
remote.shell.beep();
break;
case e.KeyCode.Backspace:
this.moveCursorRelative({horizontal: -1});
Expand Down
53 changes: 30 additions & 23 deletions src/PTY.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,56 @@
import * as ChildProcess from "child_process";
import * as OS from "os";
import * as _ from "lodash";
import * as pty from "pty.js";
import {baseName, resolveFile, exists, filterAsync, shell} from "./utils/Common";
const ptyInternalPath = require.resolve("./PTYInternal");

interface Message {
data?: string;
exit?: number;
}
const noConfigSwitches: Dictionary<string[]> = {
zsh: ["--no-globalrcs", "--no-rcs"],
bash: ["--noprofile", "--norc"],
};

export default class PTY {
private process: ChildProcess.ChildProcess;
private terminal: pty.Terminal;

// TODO: write proper signatures.
// TODO: use generators.
// TODO: terminate. https://github.com/atom/atom/blob/v1.0.15/src/task.coffee#L151
constructor(command: string, args: string[], env: ProcessEnvironment, dimensions: Dimensions, dataHandler: (d: string) => void, exitHandler: (c: number) => void) {
this.process = ChildProcess.fork(
ptyInternalPath,
[command, dimensions.columns.toString(), dimensions.rows.toString(), ...args],
{env: env, cwd: env.PWD}
);
this.terminal = pty.fork(shell(), [...noConfigSwitches[baseName(shell())], "-c", `${command} ${args.map(arg => `'${arg}'`).join(" ")}`], {
cols: dimensions.columns,
rows: dimensions.rows,
cwd: env.PWD,
env: env,
});

this.process.on("message", (message: Message) => {
if (message.hasOwnProperty("data")) {
dataHandler(message.data);
} else if (message.hasOwnProperty("exit")) {
exitHandler(message.exit);
this.process.disconnect();
} else {
throw `Unhandled message: ${JSON.stringify(message)}`;
}
this.terminal.on("data", (data: string) => dataHandler(data));
this.terminal.on("exit", (code: number) => {
exitHandler(code);
});
}

write(data: string): void {
this.process.send({input: data});
this.terminal.write(data);
}

set dimensions(dimensions: Dimensions) {
this.process.send({resize: [dimensions.columns, dimensions.rows]});
this.terminal.resize(dimensions.columns, dimensions.rows);
}

kill(signal: string): void {
this.process.send({signal: signal});
/**
* The if branch is necessary because pty.js doesn"t handle SIGINT correctly.
* You can test whether it works by executing
* ruby -e "loop { puts "yes"; sleep 1 }"
* and trying to kill it with SIGINT.
*
* {@link https://github.com/chjj/pty.js/issues/58}
*/
if (signal === "SIGINT") {
this.terminal.kill("SIGTERM");
} else {
this.terminal.kill(signal);
}
}
}

Expand Down
52 changes: 0 additions & 52 deletions src/PTYInternal.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/Prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default class Prompt extends events.EventEmitter {
this._value = value;

this._lexemes = lex(this.value);
this._historyExpanded = await expandHistory(this._lexemes);
this._historyExpanded = expandHistory(this._lexemes);
this._expanded = await expandAliases(this._historyExpanded);
}

Expand Down
16 changes: 7 additions & 9 deletions src/Session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,16 @@ import {Status} from "./Enums";
import ApplicationComponent from "./views/1_ApplicationComponent";
import Environment from "./Environment";
import {homeDirectory, normalizeDirectory} from "./utils/Common";
const remote = require("remote");
const app = remote.require("app");
const browserWindow: typeof Electron.BrowserWindow = remote.require("electron").BrowserWindow;
import {remote} from "electron";

export default class Session extends EmitterWithUniqueID {
jobs: Array<Job> = [];
environment = new Environment();
readonly environment = new Environment();
history: typeof History;
historicalCurrentDirectoriesStack: string[] = [];
private stateFileName = `${homeDirectory()}/.black-screen-state`;
private readonly stateFileName = `${homeDirectory()}/.black-screen-state`;
// The value of the dictionary is the default value used if there is no serialized data.
private serializableProperties: Dictionary<any> = {
private readonly serializableProperties: Dictionary<string> = {
directory: `String:${homeDirectory()}`,
history: `History:[]`,
};
Expand All @@ -42,9 +40,9 @@ export default class Session extends EmitterWithUniqueID {
const job = new Job(this);

job.once("end", () => {
if (app.dock && !browserWindow.getAllWindows().some(window => window.isFocused())) {
app.dock.bounce("informational");
app.dock.setBadge(job.status === Status.Success ? "1" : "✕");
if (remote.app.dock && !remote.BrowserWindow.getAllWindows().some(window => window.isFocused())) {
remote.app.dock.bounce("informational");
remote.app.dock.setBadge(job.status === Status.Success ? "1" : "✕");
/* tslint:disable:no-unused-expression */
new Notification("Command has been completed", { body: job.prompt.value });
}
Expand Down
7 changes: 2 additions & 5 deletions src/main/Main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
const app: Electron.App = require("app");
const browserWindowConstructor: typeof Electron.BrowserWindow = require("browser-window");
import {ipcMain, nativeImage} from "electron";
import {app, ipcMain, nativeImage, BrowserWindow, screen} from "electron";
import menu from "./Menu";

let browserWindow: Electron.BrowserWindow = undefined;
Expand All @@ -17,7 +15,6 @@ app.on("mainWindow-all-closed", () => process.platform === "darwin" || app.quit(
ipcMain.on("quit", app.quit);

function getMainWindow(): Electron.BrowserWindow {
const screen: Electron.Screen = require("screen");
const workAreaSize = screen.getPrimaryDisplay().workAreaSize;

if (!browserWindow) {
Expand All @@ -34,7 +31,7 @@ function getMainWindow(): Electron.BrowserWindow {
height: workAreaSize.height,
show: false,
};
browserWindow = new browserWindowConstructor(options);
browserWindow = new BrowserWindow(options);

browserWindow.loadURL("file://" + __dirname + "/../views/index.html");
menu.setMenu(app, browserWindow);
Expand Down
12 changes: 6 additions & 6 deletions src/main/Menu.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const menuConstructor: typeof Electron.Menu = require("menu");
import {Menu, shell} from "electron";

export default {
setMenu: (app: Electron.App, browserWindow: Electron.BrowserWindow) => {
Expand Down Expand Up @@ -91,15 +91,15 @@ export default {
label: "GitHub Repository",
click: function () {
/* tslint:disable:no-unused-expression */
require("shell").openExternal("https://github.com/shockone/black-screen");
shell.openExternal("https://github.com/shockone/black-screen");
},
},
],
},
];

let menu = menuConstructor.buildFromTemplate(template);
menuConstructor.setApplicationMenu(menu);
let menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);
} else {
const template = [
{
Expand Down Expand Up @@ -134,14 +134,14 @@ export default {
{
label: "GitHub Repository",
click: function () {
require("shell").openExternal("https://github.com/shockone/black-screen");
shell.openExternal("https://github.com/shockone/black-screen");
},
},
],
},
];

let menu = menuConstructor.buildFromTemplate(template);
let menu = Menu.buildFromTemplate(template);
browserWindow.setMenu(menu);
}
},
Expand Down
5 changes: 2 additions & 3 deletions src/plugins/PWDOperatingSystemIntegrator.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import Session from "../Session";
import PluginManager from "../PluginManager";
const remote = require("remote");
const app = remote.require("app");
import {remote} from "electron";

PluginManager.registerEnvironmentObserver({
currentWorkingDirectoryWillChange: () => { /* do nothing */ },

currentWorkingDirectoryDidChange: (session: Session, directory: string) => {
app.addRecentDocument(directory);
remote.app.addRecentDocument(directory);
remote.getCurrentWindow().setRepresentedFilename(directory);
},
});
6 changes: 3 additions & 3 deletions src/views/1_ApplicationComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as _ from "lodash";
import Session from "../Session";
import {ipcRenderer} from "electron";
import {KeyCode} from "../Enums";
const shell: Electron.Shell = require("remote").require("electron").shell;
import {remote} from "electron";

interface State {
sessions: Session[];
Expand Down Expand Up @@ -77,7 +77,7 @@ export default class ApplicationComponent extends React.Component<{}, State> {
this.addTab();
this.setState({sessions: this.activeTab.sessions});
} else {
shell.beep();
remote.shell.beep();
}

event.stopPropagation();
Expand All @@ -98,7 +98,7 @@ export default class ApplicationComponent extends React.Component<{}, State> {
this.activeTabIndex = newTabIndex;
this.setState({sessions: this.activeTab.sessions});
} else {
shell.beep();
remote.shell.beep();
}

event.stopPropagation();
Expand Down
6 changes: 4 additions & 2 deletions src/views/4_PromptComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default class PromptComponent extends React.Component<Props, State> imple
promptKeys
.filter(keys.deleteWord).forEach(() => this.deleteWord());
promptKeys
.filter(keys.enter).forEach(() => this.execute());
.filter(keys.enter).forEach((event: KeyboardEvent) => this.execute(event));
promptKeys
.filter(keys.interrupt).forEach(() => this.prompt.setValue("").then(() => this.setDOMValueProgrammatically("")));
promptKeys
Expand Down Expand Up @@ -187,7 +187,9 @@ export default class PromptComponent extends React.Component<Props, State> imple
);
}

private execute(): void {
private async execute(event: KeyboardEvent): Promise<void> {
await this.prompt.setValue((event.target as HTMLElement).innerText);

if (!this.isEmpty()) {
this.prompt.execute();
}
Expand Down
5 changes: 3 additions & 2 deletions src/views/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {loadEnvironment} from "../Environment";
$(() => {
// FIXME: Remove loadAllPlugins after switching to Webpack (because all the files will be loaded at start anyway).
Promise.all([loadAllPlugins(), loadEnvironment()])
.then(() => reactDOM.render(<ApplicationComponent/>, document.getElementById("black-screen")) )
.then(() => Aliases.all());
.then(() => reactDOM.render(<ApplicationComponent/>, document.getElementById("black-screen")));

Aliases.all();
});
7 changes: 1 addition & 6 deletions tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,7 @@
200
],
"member-access": false,
"member-ordering": [
true,
"public-before-private",
"static-before-instance",
"variables-before-functions"
],
"member-ordering": false,
"no-any": false,
"no-arg": true,
"no-bitwise": true,
Expand Down
Loading

0 comments on commit a037922

Please sign in to comment.