Skip to content

Commit

Permalink
Merge branch 'main' into bug_fixes_and_cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
mirkobrombin authored Dec 1, 2023
2 parents e59489b + 9304cf4 commit f1a5d16
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 31 deletions.
5 changes: 4 additions & 1 deletion bottles/backend/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from functools import lru_cache
from pathlib import Path
from typing import Dict

from bottles.backend.utils import yaml, json

@lru_cache
class Paths:
Expand Down Expand Up @@ -79,6 +79,9 @@ class TrdyPaths:
mangohud_available = shutil.which("mangohud") or False
obs_vkc_available = shutil.which("obs-vkcapture") or False
vmtouch_available = shutil.which("vmtouch") or False
base_version = ""
if os.path.isfile("/app/manifest.json"):
base_version = json.load(open("/app/manifest.json")).get("base-version","").removeprefix("stable-")

# encoding detection correction, following windows defaults
locale_encodings: Dict[str, str] = {
Expand Down
4 changes: 4 additions & 0 deletions bottles/backend/managers/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ def install(self, config: BottleConfig, dependency: list) -> Result:
Here we execute all steps in the manifest.
Steps are the actions performed to install the dependency.
"""
arch = step.get("for", "win64_win32")
if config.Arch not in arch:
continue

res = self.__perform_steps(config, step)
if not res.ok:
TaskManager.remove(task_id)
Expand Down
18 changes: 7 additions & 11 deletions bottles/frontend/views/bottle_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
from bottles.frontend.widgets.dependency import DependencyEntry


@Gtk.Template(resource_path='/com/usebottles/bottles/details-dependencies.ui')
@Gtk.Template(resource_path="/com/usebottles/bottles/details-dependencies.ui")
class DependenciesView(Adw.Bin):
__gtype_name__ = 'DetailsDependencies'
__gtype_name__ = "DetailsDependencies"
__registry = []

# region Widgets
Expand Down Expand Up @@ -63,7 +63,7 @@ def __init__(self, details, config: BottleConfig, **kwargs):
self.btn_report.connect("clicked", open_doc_url, "contribute/missing-dependencies")
self.btn_help.connect("clicked", open_doc_url, "bottles/dependencies")

if self.manager.utils_conn.status == False:
if not self.manager.utils_conn.status:
self.stack.set_visible_child_name("page_offline")

self.spinner_loading.start()
Expand All @@ -89,7 +89,7 @@ def empty_list(self):
r.get_parent().remove(r)
self.__registry = []

def update(self, widget=False, config: Optional[BottleConfig] = None):
def update(self, _widget=False, config: Optional[BottleConfig] = None):
"""
This function update the dependencies list with the
supported by the manager.
Expand All @@ -99,7 +99,7 @@ def update(self, widget=False, config: Optional[BottleConfig] = None):
self.config = config

# Not sure if it's the best place to make this check
if self.manager.utils_conn.status == False:
if not self.manager.utils_conn.status:
return

self.stack.set_visible_child_name("page_loading")
Expand All @@ -115,7 +115,7 @@ def new_dependency(dependency, plain=False):
self.list_dependencies.append(entry)

@GtkUtils.run_in_main_loop
def callback(result, error=False):
def callback(_result, _error=False):
self.stack.set_visible_child_name("page_deps")

def process_dependencies():
Expand All @@ -128,11 +128,7 @@ def process_dependencies():
if len(dependencies.keys()) > 0:
for dep in dependencies.items():
if dep[0] in self.config.Installed_Dependencies:
continue # Do not list already installed dependencies'

if dep[1].get("Arch", "win64") != self.config.Arch:
# NOTE: avoid listing dependencies not supported by the bottle arch
continue
continue # Do not list already installed dependencies

GLib.idle_add(new_dependency, dep)

Expand Down
14 changes: 9 additions & 5 deletions bottles/frontend/views/bottle_preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from gi.repository import Gtk, Adw

from bottles.backend.globals import gamemode_available, vkbasalt_available, mangohud_available, obs_vkc_available, \
vmtouch_available, gamescope_available
vmtouch_available, gamescope_available, base_version
from bottles.backend.logger import Logger
from bottles.backend.managers.library import LibraryManager
from bottles.backend.managers.runtime import RuntimeManager
Expand Down Expand Up @@ -194,11 +194,15 @@ def __init__(self, details, config, **kwargs):
self.switch_vmtouch.set_sensitive(vmtouch_available)
_not_available = _("This feature is unavailable on your system.")
_flatpak_not_available = _("{} To add this feature, please run flatpak install").format(_not_available)
_gamescope_pkg_name = "org.freedesktop.Platform.VulkanLayer.gamescope"
_vkbasalt_pkg_name = "org.freedesktop.Platform.VulkanLayer.vkBasalt"
_mangohud_pkg_name = "org.freedesktop.Platform.VulkanLayer.MangoHud"
_obsvkc_pkg_name = "com.obsproject.Studio.Plugin.OBSVkCapture"
_flatpak_pkg_name = {
"gamescope": "org.freedesktop.Platform.VulkanLayer.gamescope",
"vkbasalt": "org.freedesktop.Platform.VulkanLayer.vkBasalt//22.08",
"mangohud": "org.freedesktop.Platform.VulkanLayer.MangoHud//22.08",
"obsvkc": "com.obsproject.Studio.Plugin.OBSVkCapture"
"gamescope": f"{_gamescope_pkg_name}//{base_version}" if base_version else _gamescope_pkg_name,
"vkbasalt": f"{_vkbasalt_pkg_name}//{base_version}" if base_version else _vkbasalt_pkg_name,
"mangohud": f"{_mangohud_pkg_name}//{base_version}" if base_version else _mangohud_pkg_name,
"obsvkc": _obsvkc_pkg_name
}

if not gamemode_available:
Expand Down
36 changes: 22 additions & 14 deletions bottles/frontend/widgets/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
from bottles.frontend.windows.generic import SourceDialog


@Gtk.Template(resource_path='/com/usebottles/bottles/dependency-entry.ui')
@Gtk.Template(resource_path="/com/usebottles/bottles/dependency-entry.ui")
class DependencyEntry(Adw.ActionRow):
__gtype_name__ = 'DependencyEntry'
__gtype_name__ = "DependencyEntry"

# region Widgets
label_category = Gtk.Template.Child()
Expand All @@ -56,17 +56,24 @@ def __init__(self, window, config: BottleConfig, dependency, plain=False, **kwar
self.queue = window.page_details.queue

if plain:
'''
"""
If the dependency is plain, treat it as a placeholder, it
can be used to display "fake" elements on the list
'''
"""
self.set_title(dependency)
self.set_subtitle("")
self.btn_install.set_visible(False)
self.btn_remove.set_visible(False)
self.btn_reinstall.set_visible(True)
return

if self.config.Arch not in dependency[1].get("Arch", "win64_win32"):
self.btn_install.set_visible(False)
self.btn_remove.set_visible(False)
self.btn_reinstall.set_visible(False)
self.btn_err.set_visible(True)
self.btn_err.set_tooltip_text(_("This dependency is not compatible with this bottle architecture."))

# populate widgets
self.set_title(dependency[0])
self.set_subtitle(dependency[1].get("Description"))
Expand All @@ -80,24 +87,24 @@ def __init__(self, window, config: BottleConfig, dependency, plain=False, **kwar
self.btn_license.connect("clicked", self.open_license)

if dependency[0] in self.config.Installed_Dependencies:
'''
"""
If the dependency is installed, hide the btn_install
button and show the btn_remove button
'''
"""
self.btn_install.set_visible(False)
self.btn_remove.set_visible(True)
self.btn_reinstall.set_visible(True)

if dependency[0] in self.config.Uninstallers.keys():
'''
"""
If the dependency has no uninstaller, disable the
btn_remove button
'''
"""
uninstaller = self.config.Uninstallers[dependency[0]]
if uninstaller in [False, "NO_UNINSTALLER"]:
self.btn_remove.set_sensitive(False)

def open_manifest(self, widget):
def open_manifest(self, _widget):
"""
This function pop up a dialog with the manifest
of the dependency
Expand All @@ -111,7 +118,7 @@ def open_manifest(self, widget):
)
).present()

def open_license(self, widget):
def open_license(self, _widget):
"""
This function pop up a dialog with the license
of the dependency
Expand All @@ -121,7 +128,7 @@ def open_license(self, widget):
)
webbrowser.open(manifest["License_url"])

def install_dependency(self, widget):
def install_dependency(self, _widget):
"""
This function install the dependency in the bottle, it
will also prevent user from installing other dependencies
Expand All @@ -142,12 +149,12 @@ def install_dependency(self, widget):
dependency=self.dependency,
)

def remove_dependency(self, widget):
def remove_dependency(self, _widget):
"""
This function remove the dependency from the bottle
configuration
"""
widget.set_sensitive(False)
_widget.set_sensitive(False)
RunAsync(
task_func=self.manager.remove_dependency,
callback=self.set_install_status,
Expand All @@ -172,7 +179,8 @@ def set_install_status(self, result: Result, error=None):
self.window.show_toast(_("\"{0}\" uninstalled").format(self.dependency[0]))
else:
self.window.show_toast(_("\"{0}\" installed").format(self.dependency[0]))
return self.set_installed(uninstaller, removed)
self.set_installed(uninstaller, removed)
return
self.set_err()

def set_err(self):
Expand Down

0 comments on commit f1a5d16

Please sign in to comment.