Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add zypak support #13

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ jobs:

- name: Run shellcheck
run: |
shellcheck --severity=style ide-wrapper-build/bin/dummy-editor
shellcheck --severity=style ide-wrapper-build/bin/dummy-editor{,-wrapper}

7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,10 @@ You may use the following environment variables to change the behaviour of the i
* `FLATPAK_ISOLATE_PIP` (= `FLATPAK_ISOLATE_PACKAGES`)

* `FLATPAK_PREFER_USER_PIP` (= `FLATPAK_PREFER_USER_PACKAGES`)

* `EDITOR_RUNTIME_ARGS`

Add custom arguments to the editor.

Example `flatpak override --user --env=EDITOR_RUNTIME_ARGS="CUSTOM_ARGS" ...`

28 changes: 13 additions & 15 deletions vscode.sh → editor-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
set -e
shopt -s nullglob

FIRST_RUN="${XDG_CONFIG_HOME}/@FLAGFILE_PREFIX@-first-run"
SDK_UPDATE="${XDG_CONFIG_HOME}/@FLAGFILE_PREFIX@-sdk-update-@SDK_VERSION@"
FLATPAK_IDE_LOGLEVEL="${FLATPAK_IDE_LOGLEVEL:-@DEFAULT_LOGLEVEL@}"

function msg() {
Expand All @@ -14,13 +12,22 @@ function msg() {
fi
}

function exec_vscode() {
exec "@EDITOR_BINARY@" @EDITOR_ARGS@ "$@"
function exec_editor() {
@EXPORT_ENVS_INNER@
# shellcheck disable=SC2157
if [ -n "@ZYPAK_BINDIR@" ]; then
export ZYPAK_BIN="@ZYPAK_BINDIR@"
export ZYPAK_LIB="@ZYPAK_LIBDIR@"
export CHROME_WRAPPER="@WRAPPER_PATH@"
exec "@ZYPAK_BINDIR@/zypak-helper" @ZYPAK_ARGS@ "@EDITOR_BINARY@" "$@"
else
exec "@EDITOR_BINARY@" "$@"
fi
}

if [ -n "${FLATPAK_IDE_ENV}" ]; then
msg "Environment is already set up"
exec_vscode "$@"
exec_editor "$@"
fi

declare -A PATH_SUBDIRS
Expand Down Expand Up @@ -142,13 +149,4 @@ fi

export FLATPAK_IDE_ENV=1

if [ ! -f "${FIRST_RUN}" ]; then
touch "${FIRST_RUN}"
touch "${SDK_UPDATE}"
exec_vscode "$@" "@FIRST_RUN_README@"
elif [ ! -f "${SDK_UPDATE}" ]; then
touch "${SDK_UPDATE}"
exec_vscode "$@" "@SDK_UPDATE_README@"
else
exec_vscode "$@"
fi
exec_editor "$@"
59 changes: 59 additions & 0 deletions editor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!@BASH@
# shellcheck shell=bash

set -e
shopt -s nullglob

FIRST_RUN="${XDG_CONFIG_HOME}/@FLAGFILE_PREFIX@-first-run"
SDK_UPDATE="${XDG_CONFIG_HOME}/@FLAGFILE_PREFIX@-sdk-update-@SDK_VERSION@"

declare -a DISPLAY_SERVER_ARGS=()

function update_display_server_args () {
# See https://github.com/flathub/im.riot.Riot/blob/3fdd41c84f40fa1e8e186bade5d832d79045600c/element.sh
# See also https://gaultier.github.io/blog/wayland_from_scratch.html
# and https://github.com/flathub/com.vscodium.codium/issues/321
if [ "wayland" == "${XDG_SESSION_TYPE}" ] && [ -n "${WAYLAND_DISPLAY}" ]; then
if [[ "${WAYLAND_DISPLAY}" =~ ^/ ]]; then
wayland_socket="${WAYLAND_DISPLAY}"
else
wayland_socket="${XDG_RUNTIME_DIR:-/run/user/${UID}}/${WAYLAND_DISPLAY}"
fi
fi

# shellcheck disable=SC2050
if [ "@ELECTRON_ENABLED@" -eq 0 ]; then
return 0
fi

if [ -e "$wayland_socket" ]; then
DISPLAY_SERVER_ARGS=(
"--ozone-platform=wayland"
"--enable-wayland-ime"
"--enable-features=WaylandWindowDecorations"
)
if [ -c /dev/nvidia0 ]; then
DISPLAY_SERVER_ARGS+=("--disable-gpu-sandbox")
fi
else
DISPLAY_SERVER_ARGS=("--ozone-platform=x11")
fi
}

function exec_editor() {
@EXPORT_ENVS@
update_display_server_args
# shellcheck disable=SC2086
exec "@WRAPPER_PATH@" @EDITOR_ARGS@ "${DISPLAY_SERVER_ARGS[@]}" ${EDITOR_RUNTIME_ARGS} "$@"
}

if [ ! -f "${FIRST_RUN}" ]; then
touch "${FIRST_RUN}"
touch "${SDK_UPDATE}"
exec_editor "$@" "@FIRST_RUN_README@"
elif [ ! -f "${SDK_UPDATE}" ]; then
touch "${SDK_UPDATE}"
exec_editor "$@" "@SDK_UPDATE_README@"
else
exec_editor "$@"
fi
56 changes: 55 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,57 @@ else
sdk_version = get_option('sdk_version')
endif

if get_option('electron').enabled()
electron_enabled = true
elif get_option('electron').auto()
electron_enabled = get_option('zypak').enabled()
else
if get_option('zypak').enabled()
error('`electron` feature is required if `zypak` is enabled')
endif
electron_enabled = false
endif

editor_args = []
foreach arg : get_option('editor_args')
editor_args += '"@0@"'.format(arg)
endforeach

zypak_args = []
foreach arg : get_option('zypak_args')
zypak_args += '"@0@"'.format(arg)
endforeach

export_envs = []
foreach env : get_option('envs')
var = env.split('=')
export_envs += 'export @0@="@1@"'.format(var[0], var[1])
endforeach

export_envs_inner = []
foreach env : get_option('envs_inner')
var = env.split('=')
export_envs_inner += 'export @0@="@1@"'.format(var[0], var[1])
endforeach

wrapper_name = '@0@-wrapper'.format(get_option('program_name'))
wrapper_dir = join_paths(get_option('prefix'), get_option('bindir'))
wrapper_path = join_paths(wrapper_dir, wrapper_name)

first_run_template = files(get_option('first_run_template'))
sdk_update_template = files(get_option('sdk_update_template'))
first_run_filename = fs.name(get_option('first_run_template'))
sdk_update_filename = fs.name(get_option('sdk_update_template'))

wrapper_data = configuration_data({
'BASH': bash.path(),
'WRAPPER_PATH': wrapper_path,
'EDITOR_BINARY': editor_path,
'EDITOR_ARGS': ' '.join(editor_args),
'ELECTRON_ENABLED': electron_enabled.to_int(),
'ZYPAK_ARGS': ' '.join(zypak_args),
'EXPORT_ENVS': ' && '.join(export_envs),
'EXPORT_ENVS_INNER': ' && '.join(export_envs_inner),
'EDITOR_TITLE': get_option('editor_title'),
'FIRST_RUN_README': join_paths(datadir, first_run_filename),
'SDK_UPDATE_README': join_paths(datadir, sdk_update_filename),
Expand All @@ -61,7 +98,24 @@ readme_data = configuration_data({
'SDK_VERSION': sdk_version
})

configure_file(input: 'vscode.sh',
if get_option('zypak').enabled()
zypak_helper = find_program('zypak-helper')
zypak_bindir = fs.parent(zypak_helper.path())
zypak_libdir = join_paths(fs.parent(fs.parent(zypak_helper.path())), 'lib')
wrapper_data.set('ZYPAK_BINDIR', zypak_bindir)
wrapper_data.set('ZYPAK_LIBDIR', zypak_libdir)
else
wrapper_data.set('ZYPAK_BINDIR', '')
wrapper_data.set('ZYPAK_LIBDIR', '')
endif

configure_file(input: 'editor-wrapper.sh',
output: wrapper_name,
configuration: wrapper_data,
install_dir: wrapper_dir,
install_mode: 'rwxr-xr-x')

configure_file(input: 'editor.sh',
output: get_option('program_name'),
configuration: wrapper_data,
install_dir: get_option('bindir'),
Expand Down
5 changes: 5 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ option('first_run_template', type: 'string', value: 'first_run.txt')
option('sdk_update_template', type: 'string', value: 'sdk_update.txt')
option('flagfile_prefix', type: 'string', value: 'flatpak-vscode')
option('default_loglevel', type: 'string', value: '1')
option('electron', type: 'feature', value: 'auto')
option('zypak', type: 'feature', value: 'disabled')
option('zypak_args', type: 'array', value: ['host'])
option('envs', type: 'array', value: [])
option('envs_inner', type: 'array', value: [])
Loading