Skip to content

Commit 418d58a

Browse files
committed
mintinstall-fp-handler: Handle http/https+flatpak browser links also.
Mintinstall already handled opening a .flatpakref from a file manager. This allows it to receive and process browser links directly when encountered on a site like Flathub - clicking 'Install' on the page will now open the software manager automatically. ref: #473 Fixes #484.
1 parent 071b766 commit 418d58a

2 files changed

Lines changed: 46 additions & 2 deletions

File tree

usr/bin/mintinstall-fp-handler

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,50 @@
11
#!/usr/bin/python3
22

3+
import os
34
import subprocess
45
import sys
6+
import tempfile
57

6-
subprocess.call(["/usr/lib/linuxmint/mintinstall/mintinstall.py", "install"] + sys.argv[1:])
8+
import gi
9+
gi.require_version('Gio', '2.0')
10+
gi.require_version('XApp', '1.0')
11+
from gi.repository import Gio, GLib, XApp
12+
13+
14+
def main():
15+
args = sys.argv[1:]
16+
tmp_path = None
17+
18+
if len(args) == 1 and args[0].lower().startswith(("flatpak+https://", "flatpak+http://")):
19+
url = args[0][len("flatpak+"):]
20+
21+
if url.lower().endswith(".flatpakrepo"):
22+
suffix = ".flatpakrepo"
23+
else:
24+
suffix = ".flatpakref"
25+
26+
try:
27+
fd, tmp_path = tempfile.mkstemp(suffix=suffix, prefix="mintinstall-", dir=XApp.get_tmp_dir())
28+
os.close(fd)
29+
30+
src = Gio.File.new_for_uri(url)
31+
dst = Gio.File.new_for_path(tmp_path)
32+
src.copy(dst, Gio.FileCopyFlags.OVERWRITE, None, None, None)
33+
34+
args = [tmp_path]
35+
except GLib.Error as e:
36+
print("mintinstall-fp-handler: Failed to download %s: %s" % (url, e.message), file=sys.stderr)
37+
sys.exit(1)
38+
39+
try:
40+
subprocess.call(["/usr/lib/linuxmint/mintinstall/mintinstall.py", "install"] + args)
41+
finally:
42+
if tmp_path:
43+
try:
44+
os.unlink(tmp_path)
45+
except OSError:
46+
pass
47+
48+
49+
if __name__ == "__main__":
50+
main()

usr/share/applications/mintinstall-fp-handler.desktop

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ Terminal=false
77
Type=Application
88
Encoding=UTF-8
99
NoDisplay=true
10-
MimeType=application/vnd.flatpak.ref;application/vnd.flatpak.repo
10+
MimeType=application/vnd.flatpak.ref;application/vnd.flatpak.repo;x-scheme-handler/flatpak+https;x-scheme-handler/flatpak+http;

0 commit comments

Comments
 (0)