[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [sandboxed-tor-browser/master] Bug 21055: Fall back gracefully if the Adwaita theme is not present.



commit 8aaa94a766a4154be4027a65aa86ad000d696f07
Author: Yawning Angel <yawning@xxxxxxxxxxxxxxx>
Date:   Wed Dec 21 18:33:18 2016 +0000

    Bug 21055: Fall back gracefully if the Adwaita theme is not present.
    
    This will look horrendous, because the default Gtk+-2.0 appearnce is
    such, but it should work even on weird systems that don't have the
    "Standard GNOME theme" installed.
---
 ChangeLog                                          |  1 +
 README.md                                          |  1 +
 data/gtkrc-2.0-fallback                            |  1 +
 .../internal/sandbox/application.go                | 66 +++++++++++++++-------
 4 files changed, 49 insertions(+), 20 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index f68edb8..ace155d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,5 @@
 Changes in version 0.0.3 - UNRELEASED:
+ * Bug 21055: Fall back gracefully if the Adwaita theme is not present.
  * Bug 20791: Fetch install/update metadata using onions.
  * Bug 20979: runtime/cgo: pthread_create failed: Resource temporarily
    unavailable.
diff --git a/README.md b/README.md
index c054980..9e1ec83 100644
--- a/README.md
+++ b/README.md
@@ -20,6 +20,7 @@ Runtime dependencies:
  * bubblewrap >= 0.1.3 (https://github.com/projectatomic/bubblewrap).
  * Gtk+ >= 3.14.0
  * (Optional) PulseAudio
+ * (Optional) Adwaita Gtk+-2.0 theme
 
 Build time dependencies:
 
diff --git a/data/gtkrc-2.0-fallback b/data/gtkrc-2.0-fallback
new file mode 100644
index 0000000..e3f6a86
--- /dev/null
+++ b/data/gtkrc-2.0-fallback
@@ -0,0 +1 @@
+gtk-font-name = "Arimo 11"
diff --git a/src/cmd/sandboxed-tor-browser/internal/sandbox/application.go b/src/cmd/sandboxed-tor-browser/internal/sandbox/application.go
index 4cff1c7..122e714 100644
--- a/src/cmd/sandboxed-tor-browser/internal/sandbox/application.go
+++ b/src/cmd/sandboxed-tor-browser/internal/sandbox/application.go
@@ -76,13 +76,9 @@ func RunTorBrowser(cfg *config.Config, manif *config.Manifest, tor *tor.Tor) (cm
 	if err = h.enableX11(cfg.Sandbox.Display); err != nil {
 		return
 	}
-	h.roBind("/usr/share/themes/Adwaita/gtk-2.0", "/usr/share/themes/Adwaita/gtk-2.0", false)
-	h.roBind("/usr/share/icons/Adwaita", "/usr/share/icons/Adwaita", false)
+	hasAdwaita := h.appendGtk2Theme()
 	h.roBind("/usr/share/icons/hicolor", "/usr/share/icons/hicolor", true)
 	h.roBind("/usr/share/mime", "/usr/share/mime", false)
-	gtkRcPath := filepath.Join(h.homeDir, ".gtkrc-2.0")
-	h.setenv("GTK2_RC_FILES", gtkRcPath)
-	h.assetFile(gtkRcPath, "gtkrc-2.0")
 
 	pulseAudioWorks := false
 	if cfg.Sandbox.EnablePulseAudio {
@@ -261,7 +257,7 @@ func RunTorBrowser(cfg *config.Config, manif *config.Manifest, tor *tor.Tor) (cm
 
 		// Gtk uses plugin libraries and shit for theming, and expecting
 		// them to be in consistent locations, is too much to ask for.
-		gtkExtraLibs, gtkLibPaths, err := h.appendRestrictedGtk2()
+		gtkExtraLibs, gtkLibPaths, err := h.appendRestrictedGtk2(hasAdwaita)
 		if err != nil {
 			return nil, err
 		}
@@ -640,7 +636,34 @@ func (h *hugbox) appendRestrictedOpenGL() ([]string, string) {
 	return nil, ""
 }
 
-func (h *hugbox) appendRestrictedGtk2() ([]string, string, error) {
+func (h *hugbox) appendGtk2Theme() bool {
+	const (
+		themeDir          = "/usr/share/themes/Adwaita/gtk-2.0"
+		iconDir           = "/usr/share/themes/Adwaita"
+		adwaitaGtkrcAsset = "gtkrc-2.0"
+
+		fallbackGtkrcAsset = "gtkrc-2.0-fallback"
+	)
+
+	gtkRc := fallbackGtkrcAsset
+
+	hasAdwaita := DirExists(themeDir) && DirExists(iconDir)
+	if hasAdwaita {
+		h.roBind("/usr/share/themes/Adwaita/gtk-2.0", "/usr/share/themes/Adwaita/gtk-2.0", false)
+		h.roBind("/usr/share/icons/Adwaita", "/usr/share/icons/Adwaita", false)
+		gtkRc = adwaitaGtkrcAsset
+	} else {
+		log.Printf("sandbox: Failed to find Adwaita gtk-2.0 theme.")
+	}
+
+	gtkRcPath := filepath.Join(h.homeDir, ".gtkrc-2.0")
+	h.setenv("GTK2_RC_FILES", gtkRcPath)
+	h.assetFile(gtkRcPath, gtkRc)
+
+	return hasAdwaita
+}
+
+func (h *hugbox) appendRestrictedGtk2(hasAdwaita bool) ([]string, string, error) {
 	const (
 		libAdwaita   = "libadwaita.so"
 		libPixmap    = "libpixmap.so"
@@ -656,21 +679,24 @@ func (h *hugbox) appendRestrictedGtk2() ([]string, string, error) {
 	gtkLibPath := ""
 	setGtkPath := false
 
-	// Figure out where the system keeps the Gtk+-2.0 theme libraries,
-	// and bind mount in Adwaita and Pixmap.
 	normGtkDir := filepath.Join(restrictedLibDir, "gtk-2.0", "2.10.0")
-	adwaitaPath := findDistributionDependentLibs(nil, engineSubDir, libAdwaita)
-	if adwaitaPath != "" {
-		gtkEngineDir, _ := filepath.Split(adwaitaPath)
-		normGtkEngineDir := filepath.Join(normGtkDir, "engines")
-		h.roBind(adwaitaPath, filepath.Join(normGtkEngineDir, libAdwaita), false)
-		h.roBind(filepath.Join(gtkEngineDir, libPixmap), filepath.Join(normGtkEngineDir, libPixmap), true)
 
-		setGtkPath = true
-		gtkLibs = append(gtkLibs, libAdwaita)
-		gtkLibPath = gtkLibPath + ":" + gtkEngineDir
-	} else {
-		log.Printf("sandbox: Failed to find gtk-2.0 libadwaita.so.")
+	// Figure out where the system keeps the Gtk+-2.0 theme libraries,
+	// and bind mount in Adwaita and Pixmap.
+	if hasAdwaita {
+		adwaitaPath := findDistributionDependentLibs(nil, engineSubDir, libAdwaita)
+		if adwaitaPath != "" {
+			gtkEngineDir, _ := filepath.Split(adwaitaPath)
+			normGtkEngineDir := filepath.Join(normGtkDir, "engines")
+			h.roBind(adwaitaPath, filepath.Join(normGtkEngineDir, libAdwaita), false)
+			h.roBind(filepath.Join(gtkEngineDir, libPixmap), filepath.Join(normGtkEngineDir, libPixmap), true)
+
+			setGtkPath = true
+			gtkLibs = append(gtkLibs, libAdwaita)
+			gtkLibPath = gtkLibPath + ":" + gtkEngineDir
+		} else {
+			log.Printf("sandbox: Failed to find gtk-2.0 libadwaita.so.")
+		}
 	}
 
 	// Figure out where the system keeps the Gtk+-2.0 print backends,

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits