Skip to content

Commit

Permalink
chore: Remove unmaintained sandbox and Bottles runtime
Browse files Browse the repository at this point in the history
This cleans up a considerable chunk of the codebase by removing the dedicated sandbox. As it stands, we only support sandboxed formats, so we might as well delete the unmaintained one.

This also removes a lot of unnecessary checks in regards to packaging. Since the Flatpak includes everything we need, we might as well just not have these checks anymore.

Some of the checks early return.
  • Loading branch information
TheEvilSkeleton committed Dec 19, 2024
1 parent 5fd0a76 commit a7fe231
Show file tree
Hide file tree
Showing 11 changed files with 86 additions and 335 deletions.
147 changes: 3 additions & 144 deletions bottles/backend/health.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import os
from bottles.backend.utils import yaml
import shutil
import contextlib

from bottles.backend.logger import Logger
Expand Down Expand Up @@ -56,42 +55,16 @@ def __init__(self):
self.file_utils = FileUtils()
self.x11 = self.check_x11()
self.wayland = self.check_wayland()
self.xwayland = self.check_xwayland()
self.xwayland = self.x11 and self.wayland
self.desktop = self.check_desktop()
self.gpus = self.check_gpus()
self.gpus = GPUUtils().get_gpu()
self.glibc_min = is_glibc_min_available()
self.bottles_envs = self.get_bottles_envs()
self.check_system_info()
self.disk = self.get_disk_data()
self.ram = {"MemTotal": "n/a", "MemAvailable": "n/a"}
self.get_ram_data()

if "FLATPAK_ID" not in os.environ:
self.cabextract = self.check_cabextract()
self.p7zip = self.check_p7zip()
self.patool = self.check_patool()
self.icoextract = self.check_icoextract()
self.pefile = self.check_pefile()
self.orjson = self.check_orjson()
self.markdown = self.check_markdown()
self.xdpyinfo = self.check_xdpyinfo()
self.ImageMagick = self.check_ImageMagick()
self.FVS = self.check_FVS()
else:
self.cabextract = True
self.p7zip = True
self.patool = True
self.icoextract = True
self.pefile = True
self.orjson = True
self.markdown = True
self.ImageMagick = True
self.FVS = True

@staticmethod
def check_gpus():
return GPUUtils().get_gpu()

def check_x11(self):
port = DisplayUtils.get_x_display()
if port:
Expand All @@ -101,98 +74,11 @@ def check_x11(self):

@staticmethod
def check_wayland():
if "WAYLAND_DISPLAY" in os.environ or "WAYLAND_SOCKET" in os.environ:
return True
return False

def check_xwayland(self):
if self.x11 and self.wayland:
return True
return False
return "WAYLAND_DISPLAY" in os.environ or "WAYLAND_SOCKET" in os.environ

def check_desktop(self):
return os.environ.get("DESKTOP_SESSION")

@staticmethod
def check_cabextract():
res = shutil.which("cabextract")
if res is None:
return False
return True

@staticmethod
def check_p7zip():
res = shutil.which("7z")
if res is None:
return False
return True

@staticmethod
def check_patool():
res = shutil.which("patool")
if res is None:
return False
return True

@staticmethod
def check_icoextract():
try:
import icoextract

return True
except ModuleNotFoundError:
return False

@staticmethod
def check_pefile():
try:
import pefile

return True
except ModuleNotFoundError:
return False

@staticmethod
def check_markdown():
try:
import markdown

return True
except ModuleNotFoundError:
return False

@staticmethod
def check_orjson():
try:
import orjson

return True
except ModuleNotFoundError:
return False

@staticmethod
def check_xdpyinfo():
res = shutil.which("xdpyinfo")
if res is None:
return False
return True

@staticmethod
def check_ImageMagick():
res = shutil.which("identify")
if res is None:
return False
return True

@staticmethod
def check_FVS():
try:
from fvs.repo import FVSRepo

return True
except ModuleNotFoundError:
return False

@staticmethod
def get_bottles_envs():
look = [
Expand Down Expand Up @@ -246,36 +132,9 @@ def get_results(self, plain: bool = False):
"Bottles_envs": self.bottles_envs,
}

if "FLATPAK_ID" not in os.environ:
results["Tools and Libraries"] = {
"cabextract": self.cabextract,
"p7zip": self.p7zip,
"patool": self.patool,
"glibc_min": self.glibc_min,
"icoextract": self.icoextract,
"pefile": self.pefile,
"orjson": self.orjson,
"markdown": self.markdown,
"ImageMagick": self.ImageMagick,
"FVS": self.FVS,
"xdpyinfo": self.xdpyinfo,
}

if plain:
_yaml = yaml.dump(results, sort_keys=False, indent=4)
_yaml = _yaml.replace("&id", "&id")
return _yaml

return results

def has_core_deps(self):
result = True

for k, v in self.get_results()["Tools and Libraries"].items():
if v is False:
logging.error(
f"Core dependency {k} not found, Bottles can't be started."
)
result = False

return result
72 changes: 32 additions & 40 deletions bottles/backend/managers/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1312,50 +1312,42 @@ def components_check():
wineboot.init()
log_update(_("Wine config updated!"))

if "FLATPAK_ID" in os.environ or sandbox:
"""
If running as Flatpak, or sandbox flag is set to True, unlink home
directories and make them as folders.
"""
if "FLATPAK_ID":
log_update(_("Running as Flatpak, sandboxing userdir…"))
if sandbox:
log_update(_("Sandboxing userdir…"))

userdir = f"{bottle_complete_path}/drive_c/users"
if os.path.exists(userdir):
# userdir may not exists when unpacking a template, safely
# ignore as it will be created on first winebot.
links = []
for user in os.listdir(userdir):
_user_dir = os.path.join(userdir, user)

if os.path.isdir(_user_dir):
for _dir in os.listdir(_user_dir):
_dir_path = os.path.join(_user_dir, _dir)
log_update(_("Sandboxing user directory…"))

userdir = f"{bottle_complete_path}/drive_c/users"
if os.path.exists(userdir):
# userdir may not exists when unpacking a template, safely
# ignore as it will be created on first winebot.
links = []
for user in os.listdir(userdir):
_user_dir = os.path.join(userdir, user)

if os.path.isdir(_user_dir):
for _dir in os.listdir(_user_dir):
_dir_path = os.path.join(_user_dir, _dir)
if os.path.islink(_dir_path):
links.append(_dir_path)

_documents_dir = os.path.join(_user_dir, "Documents")
if os.path.isdir(_documents_dir):
for _dir in os.listdir(_documents_dir):
_dir_path = os.path.join(_documents_dir, _dir)
if os.path.islink(_dir_path):
links.append(_dir_path)

_documents_dir = os.path.join(_user_dir, "Documents")
if os.path.isdir(_documents_dir):
for _dir in os.listdir(_documents_dir):
_dir_path = os.path.join(_documents_dir, _dir)
if os.path.islink(_dir_path):
links.append(_dir_path)
_win_dir = os.path.join(
_user_dir, "AppData", "Roaming", "Microsoft", "Windows"
)
if os.path.isdir(_win_dir):
for _dir in os.listdir(_win_dir):
_dir_path = os.path.join(_win_dir, _dir)
if os.path.islink(_dir_path):
links.append(_dir_path)

_win_dir = os.path.join(
_user_dir, "AppData", "Roaming", "Microsoft", "Windows"
)
if os.path.isdir(_win_dir):
for _dir in os.listdir(_win_dir):
_dir_path = os.path.join(_win_dir, _dir)
if os.path.islink(_dir_path):
links.append(_dir_path)

for link in links:
with contextlib.suppress(IOError, OSError):
os.unlink(link)
os.makedirs(link)
for link in links:
with contextlib.suppress(IOError, OSError):
os.unlink(link)
os.makedirs(link)

# wait for registry files to be created
FileUtils.wait_for_files(reg_files)
Expand Down
2 changes: 0 additions & 2 deletions bottles/backend/managers/sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,6 @@ def __get_flatpak_spawn(self, cmd: str):
def get_cmd(self, cmd: str):
if "FLATPAK_ID" in os.environ:
_cmd = self.__get_flatpak_spawn(cmd)
else:
_cmd = self.__get_bwrap(cmd)

return " ".join(_cmd)

Expand Down
10 changes: 0 additions & 10 deletions bottles/frontend/ui/new.blp
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,6 @@ template $NewView: Adw.Window {
title: _("Custom");
sensitive: false;

Adw.ActionRow row_sandbox {
title: _("Share User Directory");
subtitle: _("This makes the user directory discoverable in the bottle, at the risk of sharing personal information to Windows software. This option cannot be changed after the bottle has been created.");
activatable-widget: switch_sandbox;

Switch switch_sandbox {
valign: center;
}
}

Adw.ComboRow combo_runner {
title: _("Runner");
subtitle: _("The version of the Wine compatibility layer.");
Expand Down
14 changes: 0 additions & 14 deletions bottles/frontend/ui/preferences.blp
Original file line number Diff line number Diff line change
Expand Up @@ -284,20 +284,6 @@ template $PreferencesWindow: Adw.PreferencesWindow {
}
}

Adw.PreferencesPage pref_core {
icon-name: "application-x-addon-symbolic";
title: _("Core");
visible: false;

Adw.PreferencesGroup list_runtimes {
title: _("Runtime");
}

Adw.PreferencesGroup list_winebridge {
title: _("WineBridge");
}
}

Adw.PreferencesPage {
icon-name: "applications-science-symbolic";
title: _("Experiments");
Expand Down
39 changes: 15 additions & 24 deletions bottles/frontend/views/bottle_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

import os
import uuid
from datetime import datetime
from gettext import gettext as _
from typing import List, Optional

from gi.repository import Gtk, Gio, Adw, Gdk, GLib
from gi.repository import Gtk, Gio, Adw, Gdk, GLib, Xdp

from bottles.backend.managers.backup import BackupManager
from bottles.backend.models.config import BottleConfig
Expand Down Expand Up @@ -150,13 +149,6 @@ def __init__(self, details, config, **kwargs):
"clicked", open_doc_url, "flatpak/black-screen-or-silent-crash"
)

if "FLATPAK_ID" in os.environ:
"""
If Flatpak, show the btn_flatpak_doc widget to reach
the documentation on how to expose directories
"""
self.btn_flatpak_doc.set_visible(True)

def __change_page(self, _widget, page_name):
"""
This function try to change the page based on user choice, if
Expand Down Expand Up @@ -433,21 +425,20 @@ def callback(a, b):
dialog.connect("response", execute)
dialog.show()

if "FLATPAK_ID" in os.environ and self.window.settings.get_boolean(
"show-sandbox-warning"
):
dialog = Adw.MessageDialog.new(
self.window,
_("Be Aware of Sandbox"),
_(
"Bottles is running in a sandbox, a restricted permission environment needed to keep you safe. If the program won't run, consider moving inside the bottle (3 dots icon on the top), then launch from there."
),
)
dialog.add_response("ok", _("_Dismiss"))
dialog.connect("response", show_chooser)
dialog.present()
else:
show_chooser()
if Xdp.Portal.running_under_sandbox():
if self.window.settings.get_boolean("show-sandbox-warning"):
dialog = Adw.MessageDialog.new(
self.window,
_("Be Aware of Sandbox"),
_(
"Bottles is running in a sandbox, a restricted permission environment needed to keep you safe. If the program won't run, consider moving inside the bottle (3 dots icon on the top), then launch from there."
),
)
dialog.add_response("dismiss", _("_Dismiss"))
dialog.connect("response", show_chooser)
dialog.present()
else:
show_chooser()

def __backup(self, widget, backup_type):
"""
Expand Down
Loading

0 comments on commit a7fe231

Please sign in to comment.