-
-
Notifications
You must be signed in to change notification settings - Fork 338
Add support for the Dynamic Launcher portal #3948
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,8 @@ | |
|
|
||
| import icoextract # type: ignore [import-untyped] | ||
|
|
||
| from bottles.backend.params import APP_ID | ||
|
|
||
| from bottles.backend.globals import Paths | ||
| from bottles.backend.logger import Logger | ||
| from bottles.backend.models.config import BottleConfig | ||
|
|
@@ -32,6 +34,11 @@ | |
| from bottles.backend.utils.generic import get_mime | ||
| from bottles.backend.utils.imagemagick import ImageMagickUtils | ||
|
|
||
| import uuid | ||
| from gi.repository import GLib, Gio, Gtk, Xdp, XdpGtk4 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. GUI libs shall not be used in the backend, do they?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't |
||
|
|
||
| portal = Xdp.Portal() | ||
|
|
||
| logging = Logger() | ||
|
|
||
|
|
||
|
|
@@ -224,6 +231,7 @@ def create_desktop_entry( | |
| skip_icon: bool = False, | ||
| custom_icon: str = "", | ||
| use_xdp: bool = False, | ||
| window: Gtk.Window = None, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The type signature is lying. Obviously it is an What is this window used for? Is it even needed? Consider renaming the variable. |
||
| ) -> bool: | ||
| if not os.path.exists(Paths.applications) and not use_xdp: | ||
| return False | ||
|
|
@@ -279,41 +287,49 @@ def create_desktop_entry( | |
| f.write(f"Exec={cmd_legacy} -b '{config.get('Name')}'\n") | ||
|
|
||
| return True | ||
| ''' | ||
| WIP: the following code is not working yet, it raises an error: | ||
| GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod | ||
| import uuid | ||
| from gi.repository import Gio, Xdp | ||
|
|
||
| portal = Xdp.Portal() | ||
| def prepare_install_cb (self, result): | ||
| ret = portal.dynamic_launcher_prepare_install_finish(result) | ||
| id = f"{config.get('Name')}.{program.get('name')}" | ||
| sum_type = GLib.ChecksumType.SHA1 | ||
| exec = "bottles-cli run -p {} -b '{}' -- %u".format( | ||
| shlex.quote(program.get('name')), config.get('Name') | ||
| ) | ||
| portal.dynamic_launcher_install( | ||
| ret["token"], | ||
| "{}.App_{}.desktop".format( | ||
| APP_ID, GLib.compute_checksum_for_string(sum_type, id, -1) | ||
| ), | ||
| """[Desktop Entry] | ||
| Exec={} | ||
| Type=Application | ||
| Terminal=false | ||
| Categories=Application; | ||
| Comment=Launch {} using Bottles. | ||
| StartupWMClass={}""".format( | ||
| exec, program.get("name"), program.get("name") | ||
| ) | ||
| #TODO: Desktop Actions Configure missing | ||
| #[Desktop Action Configure] | ||
| #Name=Configure in Bottles | ||
| #Exec={} | ||
| ) | ||
| #TODO: Require xdp>=1.20.1 | ||
| if icon == "com.usebottles.bottles-program": | ||
| _icon = Gio.BytesIcon.new(icon.encode("utf-8")) | ||
| icon += ".svg" | ||
| _icon = Gio.File.new_for_uri( | ||
| f"resource:/com/usebottles/bottles/icons/scalable/apps/{icon}" | ||
| ) | ||
| else: | ||
| _icon = Gio.FileIcon.new(Gio.File.new_for_path(icon)) | ||
| icon_v = _icon.serialize() | ||
| token = portal.dynamic_launcher_request_install_token(program.get("name"), icon_v) | ||
| portal.dynamic_launcher_install( | ||
| token, | ||
| f"com.usebottles.bottles.{config.get('Name')}.{program.get('name')}.{str(uuid.uuid4())}.desktop", | ||
| """ | ||
| [Desktop Entry] | ||
| Exec={} | ||
| Type=Application | ||
| Terminal=false | ||
| Categories=Application; | ||
| Comment=Launch {} using Bottles. | ||
| Actions=Configure; | ||
| [Desktop Action Configure] | ||
| Name=Configure in Bottles | ||
| Exec={} | ||
| """.format( | ||
| f"{cmd_cli} run -p {shlex.quote(program.get('name'))} -b '{config.get('Path')}'", | ||
| program.get("name"), | ||
| f"{cmd_legacy} -b '{config.get('Name')}'" | ||
| ).encode("utf-8") | ||
| ) | ||
| ''' | ||
| return False | ||
| _icon = Gio.File.new_for_path(icon) | ||
| icon_v = Gio.BytesIcon.new(_icon.load_bytes()[0]).serialize() | ||
| portal.dynamic_launcher_prepare_install(XdpGtk4.parent_new_gtk(window), | ||
| program.get("name"), icon_v, | ||
| Xdp.LauncherType.APPLICATION, | ||
| None, True, False, None, | ||
| prepare_install_cb) | ||
| #TODO: Rework to delay showing the toast | ||
| return True | ||
|
|
||
| @staticmethod | ||
| def browse_wineprefix(wineprefix: dict): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,9 @@ | |
| <gresource prefix="/com/usebottles/bottles"> | ||
| <file preprocess="xml-stripblanks" alias="appdata">@[email protected]</file> | ||
| </gresource> | ||
| <gresource prefix="/com/usebottles/bottles/icons/scalable/apps"> | ||
| <file preprocess="xml-stripblanks" alias="com.usebottles.bottles-program.svg">icons/hicolor/scalable/apps/com.usebottles.bottles-program.svg</file> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this SVG committed to git? |
||
| </gresource> | ||
| <gresource prefix="/com/usebottles/bottles/icons/scalable/actions"> | ||
| <file preprocess="xml-stripblanks" alias="bottles-steam-symbolic.svg">icons/hicolor/symbolic/apps/bottles-steam-symbolic.svg</file> | ||
| <file preprocess="xml-stripblanks" alias="external-link-symbolic.svg">icons/hicolor/symbolic/actions/external-link-symbolic.svg</file> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this module used anywhere?