Skip to content

Commit d3c68d6

Browse files
committed
wip
1 parent c85edf8 commit d3c68d6

File tree

5 files changed

+55
-34
lines changed

5 files changed

+55
-34
lines changed

bottles/backend/managers/installer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ def install(
478478
# create Desktop entry
479479
bottles_icons_path = os.path.join(ManagerUtils.get_bottle_path(config), "icons")
480480
icon_path = os.path.join(bottles_icons_path, executable.get("icon"))
481-
ManagerUtils.create_desktop_entry(_config, _program, False, icon_path)
481+
ManagerUtils.create_desktop_entry(_config, _program, False, icon_path, True)
482482

483483
if is_final:
484484
step_fn()

bottles/backend/utils/imagemagick.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,4 @@ def convert(
8585
cmd += " -flatten"
8686

8787
cmd += f" '{dest}'"
88-
subprocess.Popen(["bash", "-c", cmd])
88+
subprocess.run(["bash", "-c", cmd])

bottles/backend/utils/manager.py

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
import icoextract # type: ignore [import-untyped]
2525

26+
from bottles.backend.params import APP_ID
27+
2628
from bottles.backend.globals import Paths
2729
from bottles.backend.logger import Logger
2830
from bottles.backend.models.config import BottleConfig
@@ -31,6 +33,11 @@
3133
from bottles.backend.utils.generic import get_mime
3234
from bottles.backend.utils.imagemagick import ImageMagickUtils
3335

36+
import uuid
37+
from gi.repository import GLib, Gio, Gtk, Xdp, XdpGtk4
38+
39+
portal = Xdp.Portal()
40+
3441
logging = Logger()
3542

3643

@@ -210,6 +217,7 @@ def create_desktop_entry(
210217
skip_icon: bool = False,
211218
custom_icon: str = "",
212219
use_xdp: bool = False,
220+
window: Gtk.Window = None,
213221
) -> bool:
214222
if not os.path.exists(Paths.applications) and not use_xdp:
215223
return False
@@ -265,41 +273,49 @@ def create_desktop_entry(
265273
f.write(f"Exec={cmd_legacy} -b '{config.get('Name')}'\n")
266274

267275
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
273276

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
275304
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+
)
277309
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
303319

304320
@staticmethod
305321
def browse_wineprefix(wineprefix: dict):

bottles/frontend/program_row.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@ def update(result, _error=False):
306306
"executable": self.program["executable"],
307307
"path": self.program["path"],
308308
},
309+
use_xdp=True,
310+
window=self.window,
309311
)
310312

311313
def add_to_library(self, _widget):

data/data.gresource.xml.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
<gresource prefix="/com/usebottles/bottles">
44
<file preprocess="xml-stripblanks" alias="appdata">@APP_ID@.metainfo.xml</file>
55
</gresource>
6+
<gresource prefix="/com/usebottles/bottles/icons/scalable/apps">
7+
<file preprocess="xml-stripblanks" alias="com.usebottles.bottles-program.svg">icons/hicolor/scalable/apps/com.usebottles.bottles-program.svg</file>
8+
</gresource>
69
<gresource prefix="/com/usebottles/bottles/icons/scalable/actions">
710
<file preprocess="xml-stripblanks" alias="bottles-steam-symbolic.svg">icons/hicolor/symbolic/apps/bottles-steam-symbolic.svg</file>
811
<file preprocess="xml-stripblanks" alias="external-link-symbolic.svg">icons/hicolor/symbolic/actions/external-link-symbolic.svg</file>

0 commit comments

Comments
 (0)