Auto-detect terminal on first run
This commit is contained in:
@@ -89,7 +89,7 @@
|
||||
<key name="desktop" type="b">
|
||||
<default>true</default>
|
||||
</key>
|
||||
<key name='desktop-terminal' enum='@APP_ID@.terminals'>
|
||||
<key name="desktop-terminal" enum="@APP_ID@.terminals">
|
||||
<default>"xdg-terminal-exec"</default>
|
||||
</key>
|
||||
<key name="desktop-terminal-custom-exec" type="s">
|
||||
@@ -141,5 +141,8 @@
|
||||
<key name="steam-limiter-tokens-history" type="s">
|
||||
<default>"[]"</default>
|
||||
</key>
|
||||
<key name="terminal-check-done" type="b">
|
||||
<default>false</default>
|
||||
</key>
|
||||
</schema>
|
||||
</schemalist>
|
||||
|
||||
22
src/main.py
22
src/main.py
@@ -20,6 +20,8 @@
|
||||
import json
|
||||
import lzma
|
||||
import os
|
||||
import shlex
|
||||
import subprocess
|
||||
import sys
|
||||
from typing import Any, Optional
|
||||
|
||||
@@ -73,6 +75,10 @@ class CartridgesApplication(Adw.Application):
|
||||
|
||||
if os.name == "nt":
|
||||
migrate_files_v1_to_v2()
|
||||
else:
|
||||
if not shared.state_schema.get_boolean("terminal-check-done"):
|
||||
self.check_desktop_terminals()
|
||||
shared.state_schema.set_boolean("terminal-check-done", True)
|
||||
|
||||
# Set fallback icon-name
|
||||
Gtk.Window.set_default_icon_name(shared.APP_ID)
|
||||
@@ -143,6 +149,22 @@ class CartridgesApplication(Adw.Application):
|
||||
|
||||
self.win.present()
|
||||
|
||||
def check_desktop_terminals(self) -> None:
|
||||
"""Look for an installed terminal for desktop entries"""
|
||||
terminals = ("xdg-terminal-exec", "kgx", "gnome-terminal", "konsole", "xterm")
|
||||
|
||||
for index, command in enumerate(terminals):
|
||||
command = f"type {command} &> /dev/null"
|
||||
if os.getenv("FLATPAK_ID") == shared.APP_ID:
|
||||
command = "flatpak-spawn --host /bin/sh -c " + shlex.quote(command)
|
||||
|
||||
try:
|
||||
subprocess.run(command, shell=True, check=True)
|
||||
shared.schema.set_enum("desktop-terminal", index + 1)
|
||||
return
|
||||
except subprocess.CalledProcessError:
|
||||
pass
|
||||
|
||||
def load_games_from_disk(self) -> None:
|
||||
if shared.games_dir.is_dir():
|
||||
for game_file in shared.games_dir.iterdir():
|
||||
|
||||
Reference in New Issue
Block a user