Skip to content

Commit

Permalink
add CLI support to Debian package, add Elementary OS shell and editor…
Browse files Browse the repository at this point in the history
… support (#231)
  • Loading branch information
jfgordon2 authored and shiftkey committed Apr 23, 2020
1 parent a2dcefa commit 1607b7f
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 6 deletions.
2 changes: 2 additions & 0 deletions app/src/cli/open-desktop.ts
Expand Up @@ -12,6 +12,8 @@ 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 ${
Expand Down
17 changes: 17 additions & 0 deletions app/src/lib/editors/linux.ts
Expand Up @@ -11,6 +11,7 @@ export enum ExternalEditor {
SublimeText = 'Sublime Text',
Typora = 'Typora',
SlickEdit = 'SlickEdit',
ElementaryCode = 'Code',
}

export function parse(label: string): ExternalEditor | null {
Expand Down Expand Up @@ -42,6 +43,10 @@ export function parse(label: string): ExternalEditor | null {
return ExternalEditor.SlickEdit
}

if (label === ExternalEditor.ElementaryCode) {
return ExternalEditor.ElementaryCode
}

return null
}

Expand Down Expand Up @@ -85,6 +90,9 @@ async function getEditorPath(editor: ExternalEditor): Promise<string | null> {
'/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}`)
}
Expand All @@ -103,6 +111,7 @@ export async function getAvailableEditors(): Promise<
sublimePath,
typoraPath,
slickeditPath,
elementaryCodePath,
] = await Promise.all([
getEditorPath(ExternalEditor.Atom),
getEditorPath(ExternalEditor.VSCode),
Expand All @@ -111,6 +120,7 @@ export async function getAvailableEditors(): Promise<
getEditorPath(ExternalEditor.SublimeText),
getEditorPath(ExternalEditor.Typora),
getEditorPath(ExternalEditor.SlickEdit),
getEditorPath(ExternalEditor.ElementaryCode),
])

if (atomPath) {
Expand Down Expand Up @@ -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
}
5 changes: 4 additions & 1 deletion app/src/lib/editors/shared.ts
Expand Up @@ -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 {
Expand Down
15 changes: 15 additions & 0 deletions app/src/lib/shells/linux.ts
Expand Up @@ -13,6 +13,7 @@ export enum Shell {
Xterm = 'XTerm',
Terminology = 'Terminology',
Deepin = 'Deepin Terminal',
Elementary = 'Elementary Terminal',
}

export const Default = Shell.Gnome
Expand Down Expand Up @@ -54,6 +55,10 @@ export function parse(label: string): Shell {
return Shell.Deepin
}

if (label === Shell.Elementary) {
return Shell.Elementary
}

return Default
}

Expand Down Expand Up @@ -81,6 +86,8 @@ function getShellPath(shell: Shell): Promise<string | null> {
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}`)
}
Expand All @@ -99,6 +106,7 @@ export async function getAvailableShells(): Promise<
xtermPath,
terminologyPath,
deepinPath,
elementaryPath,
] = await Promise.all([
getShellPath(Shell.Gnome),
getShellPath(Shell.Mate),
Expand All @@ -109,6 +117,7 @@ export async function getAvailableShells(): Promise<
getShellPath(Shell.Xterm),
getShellPath(Shell.Terminology),
getShellPath(Shell.Deepin),
getShellPath(Shell.Elementary),
])

const shells: Array<IFoundShell<Shell>> = []
Expand Down Expand Up @@ -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
}

Expand All @@ -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}`)
}
Expand Down
28 changes: 28 additions & 0 deletions app/static/linux/github
@@ -0,0 +1,28 @@
#!/bin/sh

if [ ! -L "$0" ]; then
# if path is not a symlink, find relatively
GITHUB_PATH=$(dirname "$(dirname "$(dirname "$(dirname "$0")")")")
else
if command -v readlink >/dev/null; then
# if readlink exists, follow the symlink and then 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
# 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"

ELECTRON_RUN_AS_NODE=1 "$ELECTRON" "$CLI" "$@"

exit $?
18 changes: 13 additions & 5 deletions script/linux-after-install.sh
Expand Up @@ -4,13 +4,21 @@ set -e

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"

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)
Expand All @@ -22,4 +30,4 @@ case "$1" in
;;
esac

exit 0
exit 0
4 changes: 4 additions & 0 deletions script/linux-after-remove.sh
Expand Up @@ -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 || :
;;

*)
Expand Down

0 comments on commit 1607b7f

Please sign in to comment.