|
23 | 23 |
|
24 | 24 | import icoextract # type: ignore [import-untyped] |
25 | 25 |
|
| 26 | +from bottles.backend.params import APP_ID |
| 27 | + |
26 | 28 | from bottles.backend.globals import Paths |
27 | 29 | from bottles.backend.logger import Logger |
28 | 30 | from bottles.backend.models.config import BottleConfig |
|
31 | 33 | from bottles.backend.utils.generic import get_mime |
32 | 34 | from bottles.backend.utils.imagemagick import ImageMagickUtils |
33 | 35 |
|
| 36 | +import uuid |
| 37 | +from gi.repository import GLib, Gio, Gtk, Xdp, XdpGtk4 |
| 38 | + |
| 39 | +portal = Xdp.Portal() |
| 40 | + |
34 | 41 | logging = Logger() |
35 | 42 |
|
36 | 43 |
|
@@ -210,6 +217,7 @@ def create_desktop_entry( |
210 | 217 | skip_icon: bool = False, |
211 | 218 | custom_icon: str = "", |
212 | 219 | use_xdp: bool = False, |
| 220 | + window: Gtk.Window = None, |
213 | 221 | ) -> bool: |
214 | 222 | if not os.path.exists(Paths.applications) and not use_xdp: |
215 | 223 | return False |
@@ -265,41 +273,49 @@ def create_desktop_entry( |
265 | 273 | f.write(f"Exec={cmd_legacy} -b '{config.get('Name')}'\n") |
266 | 274 |
|
267 | 275 | return True |
268 | | - ''' |
269 | | - WIP: the following code is not working yet, it raises an error: |
270 | | - GDBus.Error:org.freedesktop.DBus.Error.UnknownMethod |
271 | | - import uuid |
272 | | - from gi.repository import Gio, Xdp |
273 | 276 |
|
274 | | - portal = Xdp.Portal() |
| 277 | + def prepare_install_cb (self, result): |
| 278 | + ret = portal.dynamic_launcher_prepare_install_finish(result) |
| 279 | + id = f"{config.get('Name')}.{program.get('name')}" |
| 280 | + sum_type = GLib.ChecksumType.SHA1 |
| 281 | + exec = "bottles-cli run -p {} -b '{}' -- %u".format( |
| 282 | + shlex.quote(program.get('name')), config.get('Name') |
| 283 | + ) |
| 284 | + portal.dynamic_launcher_install( |
| 285 | + ret["token"], |
| 286 | + "{}.App_{}.desktop".format( |
| 287 | + APP_ID, GLib.compute_checksum_for_string(sum_type, id, -1) |
| 288 | + ), |
| 289 | + """[Desktop Entry] |
| 290 | + Exec={} |
| 291 | + Type=Application |
| 292 | + Terminal=false |
| 293 | + Categories=Application; |
| 294 | + Comment=Launch {} using Bottles. |
| 295 | + StartupWMClass={}""".format( |
| 296 | + exec, program.get("name"), program.get("name") |
| 297 | + ) |
| 298 | + #TODO: Desktop Actions Configure missing |
| 299 | + #[Desktop Action Configure] |
| 300 | + #Name=Configure in Bottles |
| 301 | + #Exec={} |
| 302 | + ) |
| 303 | + #TODO: Require xdp>=1.20.1 |
275 | 304 | if icon == "com.usebottles.bottles-program": |
276 | | - _icon = Gio.BytesIcon.new(icon.encode("utf-8")) |
| 305 | + icon += ".svg" |
| 306 | + _icon = Gio.File.new_for_uri( |
| 307 | + f"resource:/com/usebottles/bottles/icons/scalable/apps/{icon}" |
| 308 | + ) |
277 | 309 | else: |
278 | | - _icon = Gio.FileIcon.new(Gio.File.new_for_path(icon)) |
279 | | - icon_v = _icon.serialize() |
280 | | - token = portal.dynamic_launcher_request_install_token(program.get("name"), icon_v) |
281 | | - portal.dynamic_launcher_install( |
282 | | - token, |
283 | | - f"com.usebottles.bottles.{config.get('Name')}.{program.get('name')}.{str(uuid.uuid4())}.desktop", |
284 | | - """ |
285 | | - [Desktop Entry] |
286 | | - Exec={} |
287 | | - Type=Application |
288 | | - Terminal=false |
289 | | - Categories=Application; |
290 | | - Comment=Launch {} using Bottles. |
291 | | - Actions=Configure; |
292 | | - [Desktop Action Configure] |
293 | | - Name=Configure in Bottles |
294 | | - Exec={} |
295 | | - """.format( |
296 | | - f"{cmd_cli} run -p {shlex.quote(program.get('name'))} -b '{config.get('Path')}'", |
297 | | - program.get("name"), |
298 | | - f"{cmd_legacy} -b '{config.get('Name')}'" |
299 | | - ).encode("utf-8") |
300 | | - ) |
301 | | - ''' |
302 | | - return False |
| 310 | + _icon = Gio.File.new_for_path(icon) |
| 311 | + icon_v = Gio.BytesIcon.new(_icon.load_bytes()[0]).serialize() |
| 312 | + portal.dynamic_launcher_prepare_install(XdpGtk4.parent_new_gtk(window), |
| 313 | + program.get("name"), icon_v, |
| 314 | + Xdp.LauncherType.APPLICATION, |
| 315 | + None, True, False, None, |
| 316 | + prepare_install_cb) |
| 317 | + #TODO: Rework to delay showing the toast |
| 318 | + return True |
303 | 319 |
|
304 | 320 | @staticmethod |
305 | 321 | def browse_wineprefix(wineprefix: dict): |
|
0 commit comments