Fix desktop/menu shortcuts at the end of the install

This commit is contained in:
Mathieu Comandon 2021-06-04 16:26:56 -07:00
parent d4324b9646
commit fa9e7e159b
3 changed files with 28 additions and 30 deletions

View file

@ -4,7 +4,6 @@ from gettext import gettext as _
from gi.repository import GLib, Gtk
from lutris import settings
from lutris.exceptions import UnavailableGame
from lutris.game import Game
from lutris.gui.dialogs import DirectoryDialog, InstallerSourceDialog, QuestionDialog
@ -39,9 +38,6 @@ class InstallerWindow(BaseApplicationWindow): # pylint: disable=too-many-public
self.install_in_progress = False
self.interpreter = None
self.desktop_shortcut_box = None
self.menu_shortcut_box = None
self.log_buffer = None
self.log_textview = None
@ -422,23 +418,21 @@ class InstallerWindow(BaseApplicationWindow): # pylint: disable=too-many-public
self.clean_widgets()
self.install_in_progress = False
self.desktop_shortcut_box = Gtk.CheckButton(_("Create desktop shortcut"), visible=True)
self.menu_shortcut_box = Gtk.CheckButton(_("Create application menu shortcut"), visible=True)
self.widget_box.pack_start(self.desktop_shortcut_box, False, False, 5)
self.widget_box.pack_start(self.menu_shortcut_box, False, False, 5)
desktop_shortcut_button = Gtk.Button(_("Create desktop shortcut"), visible=True)
desktop_shortcut_button.connect("clicked", self.on_create_desktop_shortcut_clicked)
self.widget_box.pack_start(desktop_shortcut_button, False, False, 5)
menu_shortcut_button = Gtk.Button(_("Create application menu shortcut"), visible=True)
menu_shortcut_button.connect("clicked", self.on_create_menu_shortcut_clicked)
self.widget_box.pack_start(menu_shortcut_button, False, False, 5)
self.widget_box.show()
if settings.read_setting("create_desktop_shortcut") == "True":
self.desktop_shortcut_box.set_active(True)
if settings.read_setting("create_menu_shortcut") == "True":
self.menu_shortcut_box.set_active(True)
self.connect("delete-event", self.create_shortcuts)
self.eject_button.hide()
self.cancel_button.hide()
self.continue_button.hide()
self.install_button.hide()
self.play_button.show()
self.close_button.grab_focus()
self.close_button.show()
@ -473,22 +467,23 @@ class InstallerWindow(BaseApplicationWindow): # pylint: disable=too-many-public
self.interpreter.cleanup()
self.destroy()
def create_shortcuts(self, *args):
"""Create desktop and global menu shortcuts."""
def on_create_desktop_shortcut_clicked(self, _widget):
self.create_shortcut(desktop=True)
def on_create_menu_shortcut_clicked(self, _widget):
self.create_shortcut()
def create_shortcut(self, desktop=False):
"""Create desktop or global menu shortcuts."""
game_slug = self.interpreter.installer.game_slug
game_id = self.interpreter.installer.game_id
game_name = self.interpreter.installer.game_name
create_desktop_shortcut = self.desktop_shortcut_box.get_active()
create_menu_shortcut = self.menu_shortcut_box.get_active()
if create_desktop_shortcut:
if desktop:
xdgshortcuts.create_launcher(game_slug, game_id, game_name, desktop=True)
if create_menu_shortcut:
else:
xdgshortcuts.create_launcher(game_slug, game_id, game_name, menu=True)
settings.write_setting("create_desktop_shortcut", create_desktop_shortcut)
settings.write_setting("create_menu_shortcut", create_menu_shortcut)
def cancel_installation(self, _widget=None):
"""Ask a confirmation before cancelling the install"""
remove_checkbox = Gtk.CheckButton.new_with_label(_("Remove game files"))

View file

@ -258,7 +258,7 @@ def check_inno_exe(path):
def get_innoextract_list(file_path):
"""Return the list of files contained in a GOG archive"""
output = system.read_process_output([get_innoextract_path(), "-lmq", file_path])
return [line[3:] for line in output.decode().split("\n") if line]
return [line[3:] for line in output.split("\n") if line]
def decompress_gog(file_path, destination_path):

View file

@ -1,16 +1,14 @@
"""XDG shortcuts handling"""
# Standard Library
import os
import shutil
import stat
from textwrap import dedent
# Third Party Libraries
from gi.repository import GLib
# Lutris Modules
from lutris.settings import CACHE_DIR
from lutris.util import system
from lutris.util.log import logger
def get_xdg_entry(directory):
@ -48,6 +46,7 @@ def get_xdg_basename(game_slug, game_id, base_dir=None):
def create_launcher(game_slug, game_id, game_name, desktop=False, menu=False):
"""Create a .desktop file."""
desktop_dir = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_DESKTOP)
launcher_content = dedent(
"""
@ -78,12 +77,16 @@ def create_launcher(game_slug, game_id, game_name, desktop=False, menu=False):
if desktop:
if not os.path.exists(desktop_dir):
os.mkdir(desktop_dir)
shutil.copy(tmp_launcher_path, os.path.join(desktop_dir, launcher_filename))
launcher_path = os.path.join(desktop_dir, launcher_filename)
logger.debug("Creating Desktop icon in %s", launcher_path)
shutil.copy(tmp_launcher_path, launcher_path)
if menu:
menu_path = os.path.join(GLib.get_user_data_dir(), "applications")
if not os.path.exists(menu_path):
os.mkdir(menu_path)
shutil.copy(tmp_launcher_path, os.path.join(menu_path, launcher_filename))
launcher_path = os.path.join(menu_path, launcher_filename)
logger.debug("Creating menu launcher in %s", launcher_path)
shutil.copy(tmp_launcher_path, launcher_path)
os.remove(tmp_launcher_path)