From e64d72967516eeb45fc98f6adf0d519fd7a8c8cc Mon Sep 17 00:00:00 2001 From: Jeff Gordon Date: Tue, 17 Mar 2020 16:23:12 -0500 Subject: [PATCH 1/6] Added linux CLI Added github.sh script to launch electron app from CLI, and added linux environment to CLI file; tested successfully in Elementary OS 5.1.2; still needs modification on linux-after-install script for PATH --- app/src/cli/open-desktop.ts | 4 +++- app/static/linux/github.sh | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 app/static/linux/github.sh diff --git a/app/src/cli/open-desktop.ts b/app/src/cli/open-desktop.ts index 3398f5b3945..b56091747a2 100644 --- a/app/src/cli/open-desktop.ts +++ b/app/src/cli/open-desktop.ts @@ -12,10 +12,12 @@ export function openDesktop(url: string = '') { return ChildProcess.spawn('open', [url], { env }) } else if (__WIN32__) { return ChildProcess.spawn('cmd', ['/c', 'start', url], { env }) + } else if (__LINUX__) { + return ChildProcess.spawn('xdg-open', [url], { env }) } else { throw new Error( `Desktop command line interface not currently supported on platform ${ - process.platform + process.platform }` ) } diff --git a/app/static/linux/github.sh b/app/static/linux/github.sh new file mode 100644 index 00000000000..ddedb27c260 --- /dev/null +++ b/app/static/linux/github.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +if [ ! -L $0 ]; then + # if path is not a symlink, find relatively + GITHUB_PATH="../../.$(dirname $0)" +else + if command -v readlink >/dev/null; then + # if readlink exists, follow the symlink and find relatively + SYMLINK=$(readlink -f "$0") + GITHUB_PATH=$(dirname "$(dirname "$(dirname "$(dirname "$SYMLINK")")")") + else + # else use the standard install location + GITHUB_PATH="/opt/GitHub Desktop" + fi +fi +BINARY_NAME="github-desktop" +ELECTRON="$GITHUB_PATH/$BINARY_NAME" +CLI="$GITHUB_PATH/resources/app/cli.js" + +ELECTRON_RUN_AS_NODE=1 "$ELECTRON" "$CLI" "$@" + +exit $? \ No newline at end of file From 0022f556ca82576c8374cf3a0ab348d5009034d4 Mon Sep 17 00:00:00 2001 From: Jeff Gordon Date: Wed, 18 Mar 2020 15:11:08 -0500 Subject: [PATCH 2/6] Updated Linux github CLI Removed restriction on electron CLI for linux, added shim to find binary, and added to path; also bugfixed check for editors to also include linux enums to allow linux-only editors to not error out, and added Elementary Code and Elementary Terminal --- app/src/lib/editors/linux.ts | 17 +++++++++++++++++ app/src/lib/editors/shared.ts | 5 ++++- app/src/lib/shells/linux.ts | 15 +++++++++++++++ app/static/linux/{github.sh => github} | 14 ++++++++++---- script/linux-after-install.sh | 8 +++++--- 5 files changed, 51 insertions(+), 8 deletions(-) rename app/static/linux/{github.sh => github} (56%) diff --git a/app/src/lib/editors/linux.ts b/app/src/lib/editors/linux.ts index 66a28ee7245..181beee7c98 100644 --- a/app/src/lib/editors/linux.ts +++ b/app/src/lib/editors/linux.ts @@ -11,6 +11,7 @@ export enum ExternalEditor { SublimeText = 'Sublime Text', Typora = 'Typora', SlickEdit = 'SlickEdit', + ElementaryCode = 'Code', } export function parse(label: string): ExternalEditor | null { @@ -42,6 +43,10 @@ export function parse(label: string): ExternalEditor | null { return ExternalEditor.SlickEdit } + if (label === ExternalEditor.ElementaryCode) { + return ExternalEditor.ElementaryCode + } + return null } @@ -85,6 +90,9 @@ async function getEditorPath(editor: ExternalEditor): Promise { '/opt/slickedit-pro2016/bin/vs', '/opt/slickedit-pro2015/bin/vs', ]) + case ExternalEditor.ElementaryCode: + return getPathIfAvailable('/usr/bin/io.elementary.code') + default: return assertNever(editor, `Unknown editor: ${editor}`) } @@ -103,6 +111,7 @@ export async function getAvailableEditors(): Promise< sublimePath, typoraPath, slickeditPath, + elementaryCodePath, ] = await Promise.all([ getEditorPath(ExternalEditor.Atom), getEditorPath(ExternalEditor.VSCode), @@ -111,6 +120,7 @@ export async function getAvailableEditors(): Promise< getEditorPath(ExternalEditor.SublimeText), getEditorPath(ExternalEditor.Typora), getEditorPath(ExternalEditor.SlickEdit), + getEditorPath(ExternalEditor.ElementaryCode), ]) if (atomPath) { @@ -141,5 +151,12 @@ export async function getAvailableEditors(): Promise< results.push({ editor: ExternalEditor.SlickEdit, path: slickeditPath }) } + if (elementaryCodePath) { + results.push({ + editor: ExternalEditor.ElementaryCode, + path: elementaryCodePath, + }) + } + return results } diff --git a/app/src/lib/editors/shared.ts b/app/src/lib/editors/shared.ts index 3ae86dce69d..14b8c322095 100644 --- a/app/src/lib/editors/shared.ts +++ b/app/src/lib/editors/shared.ts @@ -2,7 +2,10 @@ import * as Darwin from './darwin' import * as Win32 from './win32' import * as Linux from './linux' -export type ExternalEditor = Darwin.ExternalEditor | Win32.ExternalEditor +export type ExternalEditor = + | Darwin.ExternalEditor + | Win32.ExternalEditor + | Linux.ExternalEditor /** Parse the label into the specified shell type. */ export function parse(label: string): ExternalEditor | null { diff --git a/app/src/lib/shells/linux.ts b/app/src/lib/shells/linux.ts index 00420362a2c..43fc061330b 100644 --- a/app/src/lib/shells/linux.ts +++ b/app/src/lib/shells/linux.ts @@ -13,6 +13,7 @@ export enum Shell { Xterm = 'XTerm', Terminology = 'Terminology', Deepin = 'Deepin Terminal', + Elementary = 'Elementary Terminal', } export const Default = Shell.Gnome @@ -54,6 +55,10 @@ export function parse(label: string): Shell { return Shell.Deepin } + if (label === Shell.Elementary) { + return Shell.Elementary + } + return Default } @@ -81,6 +86,8 @@ function getShellPath(shell: Shell): Promise { return getPathIfAvailable('/usr/bin/terminology') case Shell.Deepin: return getPathIfAvailable('/usr/bin/deepin-terminal') + case Shell.Elementary: + return getPathIfAvailable('/usr/bin/io.elementary.terminal') default: return assertNever(shell, `Unknown shell: ${shell}`) } @@ -99,6 +106,7 @@ export async function getAvailableShells(): Promise< xtermPath, terminologyPath, deepinPath, + elementaryPath, ] = await Promise.all([ getShellPath(Shell.Gnome), getShellPath(Shell.Mate), @@ -109,6 +117,7 @@ export async function getAvailableShells(): Promise< getShellPath(Shell.Xterm), getShellPath(Shell.Terminology), getShellPath(Shell.Deepin), + getShellPath(Shell.Elementary), ]) const shells: Array> = [] @@ -148,6 +157,10 @@ export async function getAvailableShells(): Promise< shells.push({ shell: Shell.Deepin, path: deepinPath }) } + if (elementaryPath) { + shells.push({ shell: Shell.Elementary, path: elementaryPath }) + } + return shells } @@ -172,6 +185,8 @@ export function launch( return spawn(foundShell.path, ['-d', path]) case Shell.Deepin: return spawn(foundShell.path, ['-w', path]) + case Shell.Elementary: + return spawn(foundShell.path, ['-w', path]) default: return assertNever(shell, `Unknown shell: ${shell}`) } diff --git a/app/static/linux/github.sh b/app/static/linux/github similarity index 56% rename from app/static/linux/github.sh rename to app/static/linux/github index ddedb27c260..e29abfbf6dd 100644 --- a/app/static/linux/github.sh +++ b/app/static/linux/github @@ -1,11 +1,11 @@ #!/bin/sh -if [ ! -L $0 ]; then +if [ ! -L "$0" ]; then # if path is not a symlink, find relatively - GITHUB_PATH="../../.$(dirname $0)" + GITHUB_PATH=$(dirname "$(dirname "$(dirname "$(dirname "$0")")")") else if command -v readlink >/dev/null; then - # if readlink exists, follow the symlink and find relatively + # if readlink exists, follow the symlink and then find relatively SYMLINK=$(readlink -f "$0") GITHUB_PATH=$(dirname "$(dirname "$(dirname "$(dirname "$SYMLINK")")")") else @@ -13,7 +13,13 @@ else GITHUB_PATH="/opt/GitHub Desktop" fi fi -BINARY_NAME="github-desktop" +# check if this is a dev install or standard +if [ -f "$GITHUB_PATH/github-desktop-dev" ]; then + BINARY_NAME="github-desktop-dev" +else + BINARY_NAME="github-desktop" +fi + ELECTRON="$GITHUB_PATH/$BINARY_NAME" CLI="$GITHUB_PATH/resources/app/cli.js" diff --git a/script/linux-after-install.sh b/script/linux-after-install.sh index b6f0a7d1f0c..d562422d8fc 100644 --- a/script/linux-after-install.sh +++ b/script/linux-after-install.sh @@ -1,11 +1,13 @@ #!/bin/bash set -e - +productFilename="GitHub Desktop" PROFILE_D_FILE="/etc/profile.d/github-desktop.sh" INSTALL_DIR="/opt/${productFilename}" -SCRIPT=$"#!/bin/sh -export PATH=\"$INSTALL_DIR:\$PATH\"" +CLI_DIR="$INSTALL_DIR/resources/app/static" +SCRIPT="#!/bin/sh +export PATH=\"$INSTALL_DIR:$CLI_DIR:\$PATH\"" + case "$1" in configure) From 4948c5bc6485e31f345d0106129f57c67751221d Mon Sep 17 00:00:00 2001 From: Jeff Gordon Date: Wed, 18 Mar 2020 15:35:16 -0500 Subject: [PATCH 3/6] Clean-Up Removed value set during testing to prevent conflict on install --- script/linux-after-install.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/script/linux-after-install.sh b/script/linux-after-install.sh index d562422d8fc..1e10eecf9bf 100644 --- a/script/linux-after-install.sh +++ b/script/linux-after-install.sh @@ -1,13 +1,13 @@ #!/bin/bash set -e -productFilename="GitHub Desktop" + PROFILE_D_FILE="/etc/profile.d/github-desktop.sh" INSTALL_DIR="/opt/${productFilename}" CLI_DIR="$INSTALL_DIR/resources/app/static" -SCRIPT="#!/bin/sh -export PATH=\"$INSTALL_DIR:$CLI_DIR:\$PATH\"" - +SCRIPT=$"#!/bin/sh +export PATH=\"$INSTALL_DIR:\$PATH\" +export PATH=\"$CLI_DIR:\$PATH\"" case "$1" in configure) @@ -24,4 +24,4 @@ case "$1" in ;; esac -exit 0 +exit 0 \ No newline at end of file From 2f87032962c13fab552cbce8a54cea6e44e0ae8b Mon Sep 17 00:00:00 2001 From: jfgordon2 <55799997+jfgordon2@users.noreply.github.com> Date: Fri, 20 Mar 2020 12:13:59 -0500 Subject: [PATCH 4/6] Update app/src/cli/open-desktop.ts Co-Authored-By: Brendan Forster --- app/src/cli/open-desktop.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/cli/open-desktop.ts b/app/src/cli/open-desktop.ts index b56091747a2..6b33438b6a0 100644 --- a/app/src/cli/open-desktop.ts +++ b/app/src/cli/open-desktop.ts @@ -17,7 +17,7 @@ export function openDesktop(url: string = '') { } else { throw new Error( `Desktop command line interface not currently supported on platform ${ - process.platform + process.platform }` ) } From 1de65a4903a315ceb7908c0d768b5c8124dc1d40 Mon Sep 17 00:00:00 2001 From: jfgordon2 <55799997+jfgordon2@users.noreply.github.com> Date: Fri, 20 Mar 2020 12:14:14 -0500 Subject: [PATCH 5/6] Update app/static/linux/github Co-Authored-By: Brendan Forster --- app/static/linux/github | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/static/linux/github b/app/static/linux/github index e29abfbf6dd..dfb32bf6ea4 100644 --- a/app/static/linux/github +++ b/app/static/linux/github @@ -17,7 +17,7 @@ fi if [ -f "$GITHUB_PATH/github-desktop-dev" ]; then BINARY_NAME="github-desktop-dev" else - BINARY_NAME="github-desktop" + BINARY_NAME="github-desktop" fi ELECTRON="$GITHUB_PATH/$BINARY_NAME" @@ -25,4 +25,4 @@ CLI="$GITHUB_PATH/resources/app/cli.js" ELECTRON_RUN_AS_NODE=1 "$ELECTRON" "$CLI" "$@" -exit $? \ No newline at end of file +exit $? From 2f1b16f66977b4a928a1f084d9330e05402ff23c Mon Sep 17 00:00:00 2001 From: Jeff Gordon Date: Sun, 29 Mar 2020 15:05:01 -0500 Subject: [PATCH 6/6] Added binary to /usr/bin Added binary to /usr/bin to avoid having to add to PATH --- script/linux-after-install.sh | 16 +++++++++++----- script/linux-after-remove.sh | 4 ++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/script/linux-after-install.sh b/script/linux-after-install.sh index 1e10eecf9bf..204b930b83d 100644 --- a/script/linux-after-install.sh +++ b/script/linux-after-install.sh @@ -5,14 +5,20 @@ set -e PROFILE_D_FILE="/etc/profile.d/github-desktop.sh" INSTALL_DIR="/opt/${productFilename}" CLI_DIR="$INSTALL_DIR/resources/app/static" -SCRIPT=$"#!/bin/sh -export PATH=\"$INSTALL_DIR:\$PATH\" -export PATH=\"$CLI_DIR:\$PATH\"" case "$1" in configure) - echo "$SCRIPT" > "${PROFILE_D_FILE}"; - . "${PROFILE_D_FILE}"; + # add executable permissions for CLI interface + chmod +x "$CLI_DIR"/github || : + # check if this is a dev install or standard + if [ -f "$INSTALL_DIR/github-desktop-dev" ]; then + BINARY_NAME="github-desktop-dev" + else + BINARY_NAME="github-desktop" + fi + # create symbolic links to /usr/bin directory + ln -f -s "$INSTALL_DIR"/$BINARY_NAME /usr/bin || : + ln -f -s "$CLI_DIR"/github /usr/bin || : ;; abort-upgrade|abort-remove|abort-deconfigure) diff --git a/script/linux-after-remove.sh b/script/linux-after-remove.sh index 9a73886e2a5..64c0803dec3 100644 --- a/script/linux-after-remove.sh +++ b/script/linux-after-remove.sh @@ -8,6 +8,10 @@ case "$1" in echo "#!/bin/sh" > "${PROFILE_D_FILE}"; . "${PROFILE_D_FILE}"; rm "${PROFILE_D_FILE}"; + # remove symbolic links in /usr/bin directory + unlink /usr/bin/github-desktop || : + unlink /usr/bin/github-desktop-dev || : + unlink /usr/bin/github || : ;; *)