From 9ed54c036babf131662f6f6503048e75437d822a Mon Sep 17 00:00:00 2001 From: gasinvein Date: Wed, 2 Feb 2022 21:55:54 +0300 Subject: [PATCH 01/13] Split to inner and outer wrappers Outer is the entrypoint, it handles initial cli args and opening readmes Inner wrapper only handles setting up the environment. --- vscode.sh => editor-wrapper.sh | 19 ++++--------------- editor.sh | 23 +++++++++++++++++++++++ meson.build | 13 ++++++++++++- 3 files changed, 39 insertions(+), 16 deletions(-) rename vscode.sh => editor-wrapper.sh (89%) create mode 100644 editor.sh diff --git a/vscode.sh b/editor-wrapper.sh similarity index 89% rename from vscode.sh rename to editor-wrapper.sh index 523e0a1..05b42c6 100755 --- a/vscode.sh +++ b/editor-wrapper.sh @@ -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() { @@ -14,13 +12,13 @@ function msg() { fi } -function exec_vscode() { - exec "@EDITOR_BINARY@" @EDITOR_ARGS@ "$@" +function exec_editor() { + exec "@EDITOR_BINARY@" "$@" } if [ -n "${FLATPAK_IDE_ENV}" ]; then msg "Environment is already set up" - exec_vscode "$@" + exec_editor "$@" fi declare -A PATH_SUBDIRS @@ -142,13 +140,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 "$@" diff --git a/editor.sh b/editor.sh new file mode 100644 index 0000000..f273422 --- /dev/null +++ b/editor.sh @@ -0,0 +1,23 @@ +#!@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@" + +function exec_editor() { + exec "@WRAPPER_PATH@" @EDITOR_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 diff --git a/meson.build b/meson.build index 5c66f7e..075bf22 100644 --- a/meson.build +++ b/meson.build @@ -36,6 +36,10 @@ foreach arg : get_option('editor_args') editor_args += '"@0@"'.format(arg) 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')) @@ -43,6 +47,7 @@ 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), 'EDITOR_TITLE': get_option('editor_title'), @@ -61,7 +66,13 @@ readme_data = configuration_data({ 'SDK_VERSION': sdk_version }) -configure_file(input: 'vscode.sh', +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'), From 119b3d9d707430960a2d8cc30e95a46a83b2677f Mon Sep 17 00:00:00 2001 From: gasinvein Date: Thu, 3 Feb 2022 22:30:04 +0300 Subject: [PATCH 02/13] Add zypak support --- editor-wrapper.sh | 9 ++++++++- meson.build | 11 +++++++++++ meson_options.txt | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/editor-wrapper.sh b/editor-wrapper.sh index 05b42c6..be1681e 100755 --- a/editor-wrapper.sh +++ b/editor-wrapper.sh @@ -13,7 +13,14 @@ function msg() { } function exec_editor() { - exec "@EDITOR_BINARY@" "$@" + 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" host "@EDITOR_BINARY@" "$@" + else + exec "@EDITOR_BINARY@" "$@" + fi } if [ -n "${FLATPAK_IDE_ENV}" ]; then diff --git a/meson.build b/meson.build index 075bf22..af5e6d4 100644 --- a/meson.build +++ b/meson.build @@ -66,6 +66,17 @@ readme_data = configuration_data({ 'SDK_VERSION': sdk_version }) +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, diff --git a/meson_options.txt b/meson_options.txt index 867daec..4a79832 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -8,3 +8,4 @@ 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('zypak', type: 'feature', value: 'disabled') From 18a1c880b23ad916d0035016553118deb6ebdbc7 Mon Sep 17 00:00:00 2001 From: gasinvein Date: Tue, 8 Mar 2022 22:48:01 +0300 Subject: [PATCH 03/13] Allow passing environment variables --- editor-wrapper.sh | 1 + editor.sh | 1 + meson.build | 14 ++++++++++++++ meson_options.txt | 2 ++ 4 files changed, 18 insertions(+) diff --git a/editor-wrapper.sh b/editor-wrapper.sh index be1681e..848c666 100755 --- a/editor-wrapper.sh +++ b/editor-wrapper.sh @@ -13,6 +13,7 @@ function msg() { } function exec_editor() { + @EXPORT_ENVS_INNER@ if [ -n "@ZYPAK_BINDIR@" ]; then export ZYPAK_BIN="@ZYPAK_BINDIR@" export ZYPAK_LIB="@ZYPAK_LIBDIR@" diff --git a/editor.sh b/editor.sh index f273422..ef2d4a5 100644 --- a/editor.sh +++ b/editor.sh @@ -8,6 +8,7 @@ FIRST_RUN="${XDG_CONFIG_HOME}/@FLAGFILE_PREFIX@-first-run" SDK_UPDATE="${XDG_CONFIG_HOME}/@FLAGFILE_PREFIX@-sdk-update-@SDK_VERSION@" function exec_editor() { + @EXPORT_ENVS@ exec "@WRAPPER_PATH@" @EDITOR_ARGS@ "$@" } diff --git a/meson.build b/meson.build index af5e6d4..4219268 100644 --- a/meson.build +++ b/meson.build @@ -36,6 +36,18 @@ foreach arg : get_option('editor_args') editor_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) @@ -50,6 +62,8 @@ wrapper_data = configuration_data({ 'WRAPPER_PATH': wrapper_path, 'EDITOR_BINARY': editor_path, 'EDITOR_ARGS': ' '.join(editor_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), diff --git a/meson_options.txt b/meson_options.txt index 4a79832..1c130dc 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -9,3 +9,5 @@ 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('zypak', type: 'feature', value: 'disabled') +option('envs', type: 'array', value: []) +option('envs_inner', type: 'array', value: []) From b090f37a9c9c7fda00e81c72d60870b39799a2bc Mon Sep 17 00:00:00 2001 From: noons Date: Wed, 18 Oct 2023 03:30:46 -0300 Subject: [PATCH 04/13] Allow passing arguments to zypak-helper This support the new changes on zypak-helper https://github.com/refi64/zypak/blob/ded79a2f8a509adc21834b95a9892073d4a91fdc/zypak-wrapper.sh#L12 --- editor-wrapper.sh | 2 +- meson.build | 6 ++++++ meson_options.txt | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/editor-wrapper.sh b/editor-wrapper.sh index 848c666..7c3b02e 100755 --- a/editor-wrapper.sh +++ b/editor-wrapper.sh @@ -18,7 +18,7 @@ function exec_editor() { export ZYPAK_BIN="@ZYPAK_BINDIR@" export ZYPAK_LIB="@ZYPAK_LIBDIR@" export CHROME_WRAPPER="@WRAPPER_PATH@" - exec "@ZYPAK_BINDIR@/zypak-helper" host "@EDITOR_BINARY@" "$@" + exec "@ZYPAK_BINDIR@/zypak-helper" @ZYPAK_ARGS@ "@EDITOR_BINARY@" "$@" else exec "@EDITOR_BINARY@" "$@" fi diff --git a/meson.build b/meson.build index 4219268..29ef743 100644 --- a/meson.build +++ b/meson.build @@ -36,6 +36,11 @@ 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('=') @@ -62,6 +67,7 @@ wrapper_data = configuration_data({ 'WRAPPER_PATH': wrapper_path, 'EDITOR_BINARY': editor_path, 'EDITOR_ARGS': ' '.join(editor_args), + 'ZYPAK_ARGS': ' '.join(zypak_args), 'EXPORT_ENVS': ' && '.join(export_envs), 'EXPORT_ENVS_INNER': ' && '.join(export_envs_inner), 'EDITOR_TITLE': get_option('editor_title'), diff --git a/meson_options.txt b/meson_options.txt index 1c130dc..0095e6a 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -9,5 +9,6 @@ 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('zypak', type: 'feature', value: 'disabled') +option('zypak_args', type: 'array', value: ['host']) option('envs', type: 'array', value: []) option('envs_inner', type: 'array', value: []) From e564fe5678efd7d314d6ca03140bea7bdaf554dc Mon Sep 17 00:00:00 2001 From: noons Date: Thu, 22 Feb 2024 16:12:14 -0300 Subject: [PATCH 05/13] :hammer: Wayland support for electron apps --- editor.sh | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/editor.sh b/editor.sh index ef2d4a5..d48f1f9 100644 --- a/editor.sh +++ b/editor.sh @@ -7,9 +7,25 @@ shopt -s nullglob FIRST_RUN="${XDG_CONFIG_HOME}/@FLAGFILE_PREFIX@-first-run" SDK_UPDATE="${XDG_CONFIG_HOME}/@FLAGFILE_PREFIX@-sdk-update-@SDK_VERSION@" +function display_server_args (){ + # See https://github.com/flathub/im.riot.Riot/blob/3fdd41c84f40fa1e8e186bade5d832d79045600c/element.sh + if [ "wayland" == "${XDG_SESSION_TYPE}" ] && [ -e "${XDG_RUNTIME_DIR}/${WAYLAND_DISPLAY}" ] + then + DISPLAY_SERVER_ARGS="--ozone-platform-hint=auto --enable-wayland-ime --enable-features=WaylandWindowDecorations" + if [ -c /dev/nvidia0 ] + then + DISPLAY_SERVER_ARGS="${DISPLAY_SERVER_ARGS} --disable-gpu-sandbox" + fi + else + DISPLAY_SERVER_ARGS="--ozone-platform=x11" + fi + echo "${DISPLAY_SERVER_ARGS}" +} + function exec_editor() { @EXPORT_ENVS@ - exec "@WRAPPER_PATH@" @EDITOR_ARGS@ "$@" + # shellcheck disable=SC2046 + exec "@WRAPPER_PATH@" @EDITOR_ARGS@ $(display_server_args) "$@" } if [ ! -f "${FIRST_RUN}" ]; then From e1ca5c811c739c8c289d4689281a2bf5fdda872b Mon Sep 17 00:00:00 2001 From: noons Date: Sun, 5 May 2024 22:57:17 -0300 Subject: [PATCH 06/13] :bug: Fix KDE wayland check --- editor.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/editor.sh b/editor.sh index d48f1f9..7c9f367 100644 --- a/editor.sh +++ b/editor.sh @@ -9,7 +9,9 @@ SDK_UPDATE="${XDG_CONFIG_HOME}/@FLAGFILE_PREFIX@-sdk-update-@SDK_VERSION@" function display_server_args (){ # See https://github.com/flathub/im.riot.Riot/blob/3fdd41c84f40fa1e8e186bade5d832d79045600c/element.sh - if [ "wayland" == "${XDG_SESSION_TYPE}" ] && [ -e "${XDG_RUNTIME_DIR}/${WAYLAND_DISPLAY}" ] + # See also https://gaultier.github.io/blog/wayland_from_scratch.html + # and https://github.com/flathub/com.vscodium.codium/issues/321 + if [[ ${WAYLAND_DISPLAY} == "/run/flatpak/wayland-"* ]] || [[ -e "${XDG_RUNTIME_DIR}/${WAYLAND_DISPLAY}" ]] && [[ "wayland" == "${XDG_SESSION_TYPE}" ]] then DISPLAY_SERVER_ARGS="--ozone-platform-hint=auto --enable-wayland-ime --enable-features=WaylandWindowDecorations" if [ -c /dev/nvidia0 ] @@ -24,8 +26,8 @@ function display_server_args (){ function exec_editor() { @EXPORT_ENVS@ - # shellcheck disable=SC2046 - exec "@WRAPPER_PATH@" @EDITOR_ARGS@ $(display_server_args) "$@" + # shellcheck disable=SC2046,SC2086 + exec "@WRAPPER_PATH@" @EDITOR_ARGS@ $(display_server_args) ${EDITOR_RUNTIME_ARGS} "$@" } if [ ! -f "${FIRST_RUN}" ]; then From bc8655dd465619ed5dd8653dd33952b036be337e Mon Sep 17 00:00:00 2001 From: noons Date: Sun, 26 May 2024 01:25:41 -0300 Subject: [PATCH 07/13] :wrench: Add EDITOR_RUNTIME_ARGS environment variable usage example --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 53e5d53..f242997 100644 --- a/README.md +++ b/README.md @@ -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" ...` + From ce6bafd90b2617bf5940f86b60ce37f73d464e5b Mon Sep 17 00:00:00 2001 From: noons Date: Sun, 26 May 2024 02:27:47 -0300 Subject: [PATCH 08/13] :hammer: Check for wayland socket --- editor.sh | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/editor.sh b/editor.sh index 7c9f367..3502acb 100644 --- a/editor.sh +++ b/editor.sh @@ -11,16 +11,24 @@ function 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_DISPLAY} == "/run/flatpak/wayland-"* ]] || [[ -e "${XDG_RUNTIME_DIR}/${WAYLAND_DISPLAY}" ]] && [[ "wayland" == "${XDG_SESSION_TYPE}" ]] + if [ "wayland" == "${XDG_DISPLAY_TYPE}" ] && [ -n "${WAYLAND_DISPLAY}" ] then - DISPLAY_SERVER_ARGS="--ozone-platform-hint=auto --enable-wayland-ime --enable-features=WaylandWindowDecorations" - if [ -c /dev/nvidia0 ] - then - DISPLAY_SERVER_ARGS="${DISPLAY_SERVER_ARGS} --disable-gpu-sandbox" - fi + if [[ "${WAYLAND_DISPLAY}" =~ ^/ ]] + then + wayland_socket="${WAYLAND_DISPLAY}" + else + wayland_socket="${XDG_RUNTIME_DIR:-/run/user/${UID}}/${WAYLAND_DISPLAY}" + fi + fi + + if [ -e "$wayland_socket" ] + then + DISPLAY_SERVER_ARGS="--ozone-platform=wayland --enable-wayland-ime --enable-features=WaylandWindowDecorations" + [ -c /dev/nvidia0 ] && DISPLAY_SERVER_ARGS="${DISPLAY_SERVER_ARGS} --disable-gpu-sandbox" else - DISPLAY_SERVER_ARGS="--ozone-platform=x11" + DISPLAY_SERVER_ARGS="--ozone-platform=x11" fi + echo "${DISPLAY_SERVER_ARGS}" } From b51ea4ba6ed87ca2eba20f3f2c7e0fd63e30a212 Mon Sep 17 00:00:00 2001 From: noons Date: Sun, 26 May 2024 02:49:03 -0300 Subject: [PATCH 09/13] :bug: Fix wrong variable name --- editor.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/editor.sh b/editor.sh index 3502acb..de3ff81 100644 --- a/editor.sh +++ b/editor.sh @@ -11,7 +11,7 @@ function 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_DISPLAY_TYPE}" ] && [ -n "${WAYLAND_DISPLAY}" ] + if [ "wayland" == "${XDG_SESSION_TYPE}" ] && [ -n "${WAYLAND_DISPLAY}" ] then if [[ "${WAYLAND_DISPLAY}" =~ ^/ ]] then From 7b72347aad88e21a49d6d5299fcd94cedd16624a Mon Sep 17 00:00:00 2001 From: noons Date: Sat, 8 Jun 2024 15:45:24 -0300 Subject: [PATCH 10/13] :wrench: match the existing format --- editor.sh | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/editor.sh b/editor.sh index de3ff81..174844c 100644 --- a/editor.sh +++ b/editor.sh @@ -11,18 +11,15 @@ function 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 + 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 - if [ -e "$wayland_socket" ] - then + if [ -e "$wayland_socket" ]; then DISPLAY_SERVER_ARGS="--ozone-platform=wayland --enable-wayland-ime --enable-features=WaylandWindowDecorations" [ -c /dev/nvidia0 ] && DISPLAY_SERVER_ARGS="${DISPLAY_SERVER_ARGS} --disable-gpu-sandbox" else From 3a3555904173b6f9de8a6fd9852298a57c8acf61 Mon Sep 17 00:00:00 2001 From: Filippe LeMarchand Date: Sun, 9 Jun 2024 12:31:05 +0300 Subject: [PATCH 11/13] ci: Shellcheck the outer wrapper, too --- .github/workflows/ci.yml | 2 +- editor-wrapper.sh | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1564835..b7e4bec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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} diff --git a/editor-wrapper.sh b/editor-wrapper.sh index 7c3b02e..840224c 100755 --- a/editor-wrapper.sh +++ b/editor-wrapper.sh @@ -14,6 +14,7 @@ function msg() { function exec_editor() { @EXPORT_ENVS_INNER@ + # shellcheck disable=SC2157 if [ -n "@ZYPAK_BINDIR@" ]; then export ZYPAK_BIN="@ZYPAK_BINDIR@" export ZYPAK_LIB="@ZYPAK_LIBDIR@" From dfc6d2bdaa6f872eaf86ac6581c8035c46a58a34 Mon Sep 17 00:00:00 2001 From: Filippe LeMarchand Date: Sun, 9 Jun 2024 12:29:05 +0300 Subject: [PATCH 12/13] Use array for display server args --- editor.sh | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/editor.sh b/editor.sh index 174844c..5d05857 100644 --- a/editor.sh +++ b/editor.sh @@ -7,7 +7,9 @@ shopt -s nullglob FIRST_RUN="${XDG_CONFIG_HOME}/@FLAGFILE_PREFIX@-first-run" SDK_UPDATE="${XDG_CONFIG_HOME}/@FLAGFILE_PREFIX@-sdk-update-@SDK_VERSION@" -function display_server_args (){ +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 @@ -20,19 +22,24 @@ function display_server_args (){ fi if [ -e "$wayland_socket" ]; then - DISPLAY_SERVER_ARGS="--ozone-platform=wayland --enable-wayland-ime --enable-features=WaylandWindowDecorations" - [ -c /dev/nvidia0 ] && DISPLAY_SERVER_ARGS="${DISPLAY_SERVER_ARGS} --disable-gpu-sandbox" + 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" + DISPLAY_SERVER_ARGS=("--ozone-platform=x11") fi - - echo "${DISPLAY_SERVER_ARGS}" } function exec_editor() { @EXPORT_ENVS@ - # shellcheck disable=SC2046,SC2086 - exec "@WRAPPER_PATH@" @EDITOR_ARGS@ $(display_server_args) ${EDITOR_RUNTIME_ARGS} "$@" + update_display_server_args + # shellcheck disable=SC2086 + exec "@WRAPPER_PATH@" @EDITOR_ARGS@ "${DISPLAY_SERVER_ARGS[@]}" ${EDITOR_RUNTIME_ARGS} "$@" } if [ ! -f "${FIRST_RUN}" ]; then From e39b1d775dad273a6ec8d88a52e961511ab6aeba Mon Sep 17 00:00:00 2001 From: Filippe LeMarchand Date: Sun, 9 Jun 2024 12:32:39 +0300 Subject: [PATCH 13/13] Gate appending electron args by meson feature --- editor.sh | 5 +++++ meson.build | 12 ++++++++++++ meson_options.txt | 1 + 3 files changed, 18 insertions(+) diff --git a/editor.sh b/editor.sh index 5d05857..0d032ae 100644 --- a/editor.sh +++ b/editor.sh @@ -21,6 +21,11 @@ function update_display_server_args () { 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" diff --git a/meson.build b/meson.build index 29ef743..6bda4d7 100644 --- a/meson.build +++ b/meson.build @@ -31,6 +31,17 @@ 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) @@ -67,6 +78,7 @@ wrapper_data = configuration_data({ '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), diff --git a/meson_options.txt b/meson_options.txt index 0095e6a..8f0a4b9 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -8,6 +8,7 @@ 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: [])