Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions system_files/bluefin/etc/bazaar/bazaar.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,57 @@ yaml-blocklist-paths:

curated-config-paths:
- /run/host/etc/bazaar/curated.yaml


hooks:
- id: jetbrains-toolbox
when: before-transaction
dialogs:
- id: jetbrains-warning
title: >-
JetBrains IDEs are not supported in this format
# If true, render inline markup commands in body; see
# https://docs.gtk.org/Pango/pango_markup.html
body-use-markup: true
body: >-
This is a <a href="https://www.jetbrains.com/">JetBrains</a>
application and is not officially supported on Flatpak. We
recommend using the Toolbox app to manage JetBrains IDEs.
# Determines which option will be assumed if the user hits the
# escape key or otherwise cancels the dialog
default-response-id: cancel
options:
- id: cancel
string: "Cancel"
- id: run-ujust
string: "Download JetBrains Toolbox"
# can be "destructive" or "suggested" or omit for no
# styling
style: suggested
shell: exec python3 /run/host/etc/bazaar/hooks.py

- id: code
when: before-transaction
dialogs:
- id: code-warning
title: >-
VS Code like IDEs are not supported in this format
# If true, render inline markup commands in body; see
# https://docs.gtk.org/Pango/pango_markup.html
body-use-markup: true
body: >-
This is an app based on <a href="https://code.visualstudio.com/">Visual Studio Code</a>
and is not officially supported on Flatpak. We
recommend using the Homebrew version of the app instead.
# Determines which option will be assumed if the user hits the
# escape key or otherwise cancels the dialog
default-response-id: cancel
options:
- id: cancel
string: "Cancel"
- id: download
string: "Download from Homebrew"
# can be "destructive" or "suggested" or omit for no
# styling
style: suggested
shell: exec python3 /run/host/etc/bazaar/hooks.py
15 changes: 0 additions & 15 deletions system_files/bluefin/etc/bazaar/blocklist.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,7 @@
blocklists:
- block:
- com.visualstudio.code
- com.visualstudio.code-oss
- com.vscodium.codium
- com.vscodium.codium-insiders
- com.jetbrains.CLion
- com.jetbrains.DataGrip
- com.jetbrains.GoLand
- com.jetbrains.IntelliJ-IDEA-Community
- com.jetbrains.IntelliJ-IDEA-Ultimate
- com.jetbrains.PyCharm-Professional
- com.jetbrains.WebStorm
- com.jetbrains.PhpStorm
- com.jetbrains.PyCharm-Community
- com.jetbrains.Rider
- com.jetbrains.RubyMine
- com.jetbrains.RustRover
- com.google.AndroidStudio
- io.neovim.nvim
- org.vim.Vim
- io.github.zyedidia.micro
Expand Down
119 changes: 119 additions & 0 deletions system_files/bluefin/etc/bazaar/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# See https://github.com/kolunmi/bazaar/blob/main/docs/overview.md#hooks

import os, subprocess, sys

unix_timestamp = os.getenv('BAZAAR_HOOK_INITIATED_UNIX_STAMP')
unix_timestamp_usec = os.getenv('BAZAAR_HOOK_INITIATED_UNIX_STAMP_USEC')

hook_id = os.getenv('BAZAAR_HOOK_ID')
hook_type = os.getenv('BAZAAR_HOOK_TYPE')
was_aborted = os.getenv('BAZAAR_HOOK_WAS_ABORTED')
dialog_id = os.getenv('BAZAAR_HOOK_DIALOG_ID')
dialog_response_id = os.getenv('BAZAAR_HOOK_DIALOG_RESPONSE_ID')

non_transaction_appid = os.getenv('BAZAAR_APPID')
transaction_appid = os.getenv('BAZAAR_TS_APPID')
transaction_type = os.getenv('BAZAAR_TS_TYPE')

stage = os.getenv('BAZAAR_HOOK_STAGE')
stage_idx = os.getenv('BAZAAR_HOOK_STAGE_IDX')

# ---

def spawn_and_detach(args):
subprocess.Popen(args, start_new_session=True, stdout=subprocess.DEVNULL)

def spawn_ujust(id):
spawn_and_detach(['flatpak-spawn', '--host', 'xdg-terminal-exec', '-x', f'ujust {id}'])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The command and its arguments are being passed as a single string f'ujust {id}' to xdg-terminal-exec. This is likely to fail because the shell will try to execute a program named "ujust install-jetbrains-toolbox" instead of the ujust command with install-jetbrains-toolbox as an argument. The command and its arguments should be passed as separate elements in the list.

Suggested change
spawn_and_detach(['flatpak-spawn', '--host', 'xdg-terminal-exec', '-x', f'ujust {id}'])
spawn_and_detach(['flatpak-spawn', '--host', 'xdg-terminal-exec', '-x', 'ujust', id])


def spawn_brew(app):
brew = '/home/linuxbrew/.linuxbrew/bin/brew'
spawn_and_detach([
'flatpak-spawn', '--host', 'xdg-terminal-exec', '-x',
'bash', '-c', f'{brew} install --cask {app}'
])

def handle_jetbrains():

def appid_is_jetbrains(appid):
return appid.startswith('com.jetbrains.') or appid == ('com.google.AndroidStudio')

match stage:
case 'setup':
if transaction_type == 'install' and appid_is_jetbrains(transaction_appid):
return 'ok'
else:
return 'pass'

case 'setup-dialog':
return 'ok'

case 'teardown-dialog':
if dialog_response_id == 'run-ujust':
return 'ok'
else:
return 'abort'

case 'catch':
return 'abort'

case 'action':
try:
spawn_ujust('install-jetbrains-toolbox')
except:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Using a bare except: is generally discouraged as it catches all exceptions, including system-exiting ones like SystemExit or KeyboardInterrupt. This can hide bugs and make the program difficult to interrupt or debug. It's better to catch a more specific exception, like Exception.

Suggested change
except:
except Exception:

pass
return ''

case 'teardown':
# always prevent installation of JetBrains flatpaks
return 'deny'

def handle_code():

def appid_is_code(appid):
return appid == ('com.visualstudio.code') or appid == ('com.vscodium.codium')

match stage:
case 'setup':
if transaction_type == 'install' and appid_is_code(transaction_appid):
return 'ok'
else:
return 'pass'

case 'setup-dialog':
return 'ok'

case 'teardown-dialog':
if dialog_response_id == 'download':
return 'ok'
else:
return 'abort'

case 'catch':
return 'abort'

case 'action':
try:
if transaction_appid == ('com.vscodium.codium'):
spawn_brew('ublue/tap/vscodium-linux')
else:
spawn_brew('ublue/tap/visual-studio-code-linux')
except:
pass
return ''

case 'teardown':
return 'deny'

# ---

response = 'pass'
match hook_id:
case 'jetbrains-toolbox':
response = handle_jetbrains()
case 'code':
response = handle_code()

print(response)
sys.exit(0)

Loading