Skip to content
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

Add lutris wrapper #219

Merged
merged 1 commit into from
Mar 21, 2022
Merged
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
128 changes: 128 additions & 0 deletions lutris_wrapper/lutris_wrapper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#!/usr/bin/env python3
import configparser
import sys
import os
import logging

import gi

gi.require_version("Gtk", "4.0")
from gi.repository import Gtk

COMPAT_EXT = "org.gnome.Platform.Compat.i386"
FLATPAK_INFO = "/.flatpak-info"
LUTRIS_PATH = "/app/bin/lutris"

# COMPAT_EXT = "org.gnome.Platform.FakeCompat.i386" # testing
# FLATPAK_INFO = "flatpak-info" # testing
# LUTRIS_PATH = "/usr/bin/pwd" # testing


def build_window(window):
window.props.title = "Flatpak Extension Missing"

box = Gtk.Box.new(Gtk.Orientation.VERTICAL, 6)
box.props.hexpand = True

def on_clicked(_button):
window.destroy()
run_lutris()

def on_copy_clicked(button):
clipboard = button.get_display().get_clipboard()
clipboard.set(get_command())

button = Gtk.Button.new_with_label("Close")
button.connect("clicked", on_clicked)

copy_button = Gtk.Button.new_from_icon_name("edit-copy-symbolic")
copy_button.connect("clicked", on_copy_clicked)

label = Gtk.Label.new(
"The GL compat extension is missing, wine apps won't work properly.\nPlease run:"
)

command = Gtk.Label.new("<tt>{}</tt>".format(get_command()))
command.props.use_markup = True
command.props.selectable = True
command.add_css_class("view")

hbox = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 6)
hbox.append(command)
hbox.append(copy_button)

end_label = Gtk.Label.new("And then restart Lutris.")

window.set_child(box)
box.append(label)
box.append(hbox)
box.append(end_label)
box.append(button)


def on_activate(app):
window = Gtk.ApplicationWindow.new(app)
build_window(window)
window.present()


def get_command():
flatpak_info = read_flatpak_info()
_, _, _, version = flatpak_info["runtime"].split("/")
command = "flatpak install --user flathub {}//{}".format(COMPAT_EXT, version)
return command


def read_flatpak_info():
flatpak_info = configparser.ConfigParser()
with open(FLATPAK_INFO, "r") as f:
flatpak_info.read_file(f)

return {
"runtime": flatpak_info.get("Application", "runtime"),
"app-extensions": dict(
(
s.split("=")
for s in flatpak_info.get(
"Instance", "app-extensions", fallback=""
).split(";")
if s
)
),
"runtime-extensions": dict(
(
s.split("=")
for s in flatpak_info.get(
"Instance", "runtime-extensions", fallback=""
).split(";")
if s
)
),
}


def run_lutris():
argv = sys.argv[1:]
os.execv(LUTRIS_PATH, [LUTRIS_PATH] + argv)


def main():
info = read_flatpak_info()

is_installed = COMPAT_EXT in info["app-extensions"]

if is_installed:
run_lutris()
else:
logging.warning(
"Missing extension {}, see https://github.com/flathub/net.lutris.Lutris/issues/53".format(
COMPAT_EXT
)
)
app = Gtk.Application()
app.connect("activate", on_activate)
app.run()


if __name__ == "__main__":
main()
13 changes: 13 additions & 0 deletions lutris_wrapper/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from setuptools import setup

setup(
name="lutris_wrapper",
description="Lutris wrapper for Lutris Flatpak",
py_modules=["lutris_wrapper"],
version="1.0.0",
entry_points={
"console_scripts": [
"lutris-wrapper = lutris_wrapper:main",
]
}
)
10 changes: 9 additions & 1 deletion net.lutris.Lutris.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ id: net.lutris.Lutris
sdk: org.gnome.Sdk
runtime: org.gnome.Platform
runtime-version: '41'
command: lutris
command: lutris-wrapper
rename-icon: lutris
copy-icon: true
base: org.winehq.Wine
Expand Down Expand Up @@ -663,3 +663,11 @@ modules:
post-install:
- cp -r . $FLATPAK_DEST/lib/kitty
- ln -s /app/lib/kitty/kitty/launcher/kitty $FLATPAK_DEST/bin/kitty

- name: lutris_wrapper
buildsystem: simple
sources:
- type: dir
path: lutris_wrapper
build-commands:
- python3 -mpip install . --prefix=/app --no-index --find-links .