Skip to content

Commit

Permalink
window: Add error dialog when outside of sandboxed format
Browse files Browse the repository at this point in the history
  • Loading branch information
TheEvilSkeleton authored and mirkobrombin committed Dec 7, 2024
1 parent 6206301 commit 779951d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
8 changes: 1 addition & 7 deletions bottles/frontend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
gi.require_version("Xdp", "1.0")
# gi.require_version("XdpGtk4", "1.0")

from gi.repository import Gtk, Gio, GLib, GObject, Adw, Xdp # type: ignore
from gi.repository import Gtk, Gio, GLib, GObject, Adw # type: ignore

from bottles.frontend.params import *
from bottles.backend.logger import Logger
Expand Down Expand Up @@ -251,12 +251,6 @@ def do_activate(self):
win = MainWindow(application=self, arg_bottle=self.arg_bottle)
self.win = win

# Be VERY explicit that non-sandboxed environments are unsupported
if not Xdp.Portal.running_under_sandbox():
logging.error(_("Bottles is only supported within a sandboxed format. Official sources of Bottles are available at:"))
logging.error("https://usebottles.com/download/")
quit(1)

win.present()

def __quit(self, *args):
Expand Down
24 changes: 23 additions & 1 deletion bottles/frontend/windows/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from gettext import gettext as _
from typing import Optional

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

from bottles.backend.globals import Paths
from bottles.backend.health import HealthChecker
Expand Down Expand Up @@ -96,6 +96,28 @@ def __init__(self, arg_bottle, **kwargs):
manager = Adw.StyleManager.get_default()
manager.set_color_scheme(Adw.ColorScheme.FORCE_DARK)

# Be VERY explicit that non-sandboxed environments are unsupported
if not Xdp.Portal.running_under_sandbox():
def response(dialog, response, *args):
if response == "close":
quit(1)

body = _("Bottles is only supported within a sandboxed environment. Official sources of Bottles are available at")
download_url = "usebottles.com/download"

error_dialog = Adw.AlertDialog.new(
_("Unsupported Environment"),
f"{body} <a href='https://{download_url}' title='https://{download_url}'>{download_url}.</a>"
)

error_dialog.add_response("close", _("Close"))
error_dialog.set_body_use_markup(True)
error_dialog.connect("response", response)
error_dialog.present(self)
logging.error(_("Bottles is only supported within a sandboxed format. Official sources of Bottles are available at:"))
logging.error("https://usebottles.com/download/")
return

# Loading view
self.page_loading = LoadingView()

Expand Down

0 comments on commit 779951d

Please sign in to comment.