Skip to content

Commit

Permalink
run formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
peebeejay committed Aug 11, 2021
1 parent e221ab7 commit 4f635cc
Show file tree
Hide file tree
Showing 9 changed files with 225 additions and 165 deletions.
17 changes: 8 additions & 9 deletions src/electron/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BrowserWindow, app, globalShortcut } from "electron";
import { BrowserWindow, app, globalShortcut } from 'electron';

app.on("ready", () => {
app.on('ready', () => {
// once electron has started up, create a window.
const window = new BrowserWindow({
width: 900,
Expand All @@ -12,18 +12,17 @@ app.on("ready", () => {

// TODO: is it a problem to disable this?
// https://www.electronjs.org/docs/tutorial/context-isolation#security-considerations
contextIsolation: false
}
contextIsolation: false,
},
});

// hide the default menu bar that comes with the browser window
window.setMenuBarVisibility(false);


globalShortcut.register('CommandOrControl+R', function() {
console.log('CommandOrControl+R is pressed')
window.reload()
})
globalShortcut.register('CommandOrControl+R', function () {
console.log('CommandOrControl+R is pressed');
window.reload();
});

// load a website to display
window.loadURL(`file://${__dirname}/../react/index.html`);
Expand Down
4 changes: 2 additions & 2 deletions src/react/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { Background } from './colors';
import { Deposit } from './components/Deposit';
import { Home } from './components/Home';
import { InstallFailed } from './components/InstallFailed';
import Installing from './components/Installing';
import Status from './components/Status';
import { Installing } from './components/Installing';
import { StatusPage as Status } from './components/Status';
import { SystemCheck } from './components/SystemCheck';

const Container = styled.main`
Expand Down
34 changes: 16 additions & 18 deletions src/react/colors.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
export const Gray1 = "#F1F6FE";
export const Gray2 = "#E3EBF7";
export const Gray3 = "#d0dae8";
export const Gray4 = "#ACBED5";
export const DarkGray = "#A9A9A9";
export const Gray1 = '#F1F6FE';
export const Gray2 = '#E3EBF7';
export const Gray3 = '#d0dae8';
export const Gray4 = '#ACBED5';
export const DarkGray = '#A9A9A9';

export const TextDark = "#0B1E58";
export const TextDark = '#0B1E58';

export const PrimaryBlue = "#3366FF";
export const PrimaryBlueDark = "#174BE6";
export const PrimaryBlue = '#3366FF';
export const PrimaryBlueDark = '#174BE6';

// https://colorhunt.co/palette/167893
export const DarkBlue = "#0f4c75";
export const MediumBlue = "#3282b8";
export const LightBlue = "#bbe1fa";
export const White = "#FFFFFF";
export const Red = "#fa1e0e";
export const DarkBlue = '#0f4c75';
export const MediumBlue = '#3282b8';
export const LightBlue = '#bbe1fa';
export const White = '#FFFFFF';
export const Red = '#fa1e0e';

export const LightGreen = "#52b788";
export const LightGreen = '#52b788';

export const Background = "#1b262c";
export const Background = '#1b262c';
export const Button = LightBlue;
export const ButtonHover = LightGreen;
export const Heading = MediumBlue;
export const MainContent = Gray3;
export const MainContentAlert = Red;
export const Black = "#000000"
export const Black = '#000000';
export const DisabledButton = DarkGray;


29 changes: 13 additions & 16 deletions src/react/commands/BashUtils.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
import { executeCommandSync, executeCommandSyncReturnStdout } from "./ExecuteCommand";
import {
executeCommandSync,
executeCommandSyncReturnStdout,
} from './ExecuteCommand';

const doesFileExist = (filename: string): boolean => {
const cmd = "test -f " + filename;
export const doesFileExist = (filename: string): boolean => {
const cmd = 'test -f ' + filename;
const result = executeCommandSync(cmd);
return result == 0;
};

//TODO: add error handling
const readlink = (file: string): string => {
return executeCommandSyncReturnStdout("readlink -f " + file).trim();
}
// TODO: add error handling
export const readlink = (file: string): string => {
return executeCommandSyncReturnStdout('readlink -f ' + file).trim();
};

const which = (tool: string): boolean => {
const cmd = "which " + tool;
export const which = (tool: string): boolean => {
const cmd = 'which ' + tool;
const result = executeCommandSync(cmd);
return result == 0;
}

export {
doesFileExist,
readlink,
which
};
};
73 changes: 44 additions & 29 deletions src/react/commands/ExecuteCommand.ts
Original file line number Diff line number Diff line change
@@ -1,44 +1,49 @@
import { exec, execSync, spawn } from 'child_process';
import { streamEnd, streamWrite } from '@rauschma/stringio';

import { Writable } from 'stream';

// TODO: better error handling and logging
// TODO: remove console.log

// TODO: make this work for different operating systems
const UBUNTU_TERMINAL_COMMAND = "/usr/bin/gnome-terminal";
const UBUNTU_TERMINAL_COMMAND = '/usr/bin/gnome-terminal';

type StdoutCallback = (text: string) => void;

const executeCommandAsync = async (cmd: string): Promise<any> => {
console.log("running command async with: " + cmd);
console.log('running command async with: ' + cmd);

return new Promise((resolve, reject) => {
const child = exec(cmd);

child.once('exit', function (code) {
resolve(code);
});

child.on('error', function (err) {
reject(err);
});
});
}
};

const executeCommandInNewTerminal = (cmd: string, title: string): number => {
return executeCommandSync(UBUNTU_TERMINAL_COMMAND + " --title=\"" + title + "\" -- bash -c '" + cmd + "'");
}
return executeCommandSync(
UBUNTU_TERMINAL_COMMAND +
' --title="' +
title +
'" -- bash -c \'' +
cmd +
"'",
);
};

const executeCommandSync = (cmd: string): number => {
console.log("running command sync with: " + cmd);
console.log('running command sync with: ' + cmd);

try {
execSync(cmd, {stdio: 'inherit'});
execSync(cmd, { stdio: 'inherit' });
return 0;
}
catch (error) {
} catch (error) {
// TODO: more robust error handling
error.status;
error.message;
Expand All @@ -47,15 +52,14 @@ const executeCommandSync = (cmd: string): number => {
console.log(error.message);
return error.status;
}
}
};

const executeCommandSyncReturnStdout = (cmd: string): string => {
console.log("running command sync stdout with: " + cmd);
console.log('running command sync stdout with: ' + cmd);

try {
return execSync(cmd).toString();
}
catch (error) {
} catch (error) {
// TODO: more robust error handling
error.status;
error.message;
Expand All @@ -64,13 +68,16 @@ const executeCommandSyncReturnStdout = (cmd: string): string => {
console.log(error.message);
return error.message;
}
}
};

const executeCommandStream = (cmd: string, stdoutCallback: StdoutCallback): Promise<any> => {
console.log("running command stream with: " + cmd);
const executeCommandStream = (
cmd: string,
stdoutCallback: StdoutCallback,
): Promise<any> => {
console.log('running command stream with: ' + cmd);
return new Promise((resolve, reject) => {
const child = spawn(cmd, {
shell: true
shell: true,
});

child.stdout.on('data', (data: Buffer) => {
Expand All @@ -89,12 +96,20 @@ const executeCommandStream = (cmd: string, stdoutCallback: StdoutCallback): Prom
reject(err);
});
});
}

};

// good resource for this: https://2ality.com/2018/05/child-process-streams.html
const executeCommandWithPromptsAsync = (cmd: string, responses: string[], stdoutCallback: StdoutCallback): Promise<any> => {
console.log("running command with prompts async with: " + cmd + " and responses " + responses.join());
const executeCommandWithPromptsAsync = (
cmd: string,
responses: string[],
stdoutCallback: StdoutCallback,
): Promise<any> => {
console.log(
'running command with prompts async with: ' +
cmd +
' and responses ' +
responses.join(),
);

return new Promise((resolve, reject) => {
const child = spawn(cmd, {
Expand All @@ -111,19 +126,19 @@ const executeCommandWithPromptsAsync = (cmd: string, responses: string[], stdout
child.once('exit', function (code) {
resolve(code);
});

child.on('error', function (err) {
reject(err);
});
});
}
};

// TODO: using this sync wait to get the prompt responses to work properly is
// probably not the best - come up with alternative solution
const syncWait = (ms: number) => {
const end = Date.now() + ms
while (Date.now() < end) continue
}
const end = Date.now() + ms;
while (Date.now() < end) continue;
};

async function writeToWritable(writable: Writable, responses: string[]) {
syncWait(1000);
Expand All @@ -143,4 +158,4 @@ export {
executeCommandSync,
executeCommandSyncReturnStdout,
executeCommandWithPromptsAsync,
};
};
Loading

0 comments on commit 4f635cc

Please sign in to comment.