11namespace Turntable {
2- public static bool is_flatpak = false ;
32 public static Mpris . Manager mpris_manager;
43 public const int PROGRESS_UPDATE_TIME = 1000 ; // it was 250ms, turns out it updates every second?
54 public static Application application;
65 public static bool debug_enabled = false ;
76 public static bool is_rtl = false ;
7+ #if SANDBOXED
8+ public static string []? desktop_file_dirs = null ;
9+ #endif
810
911 // public static Utils.Cache custom_color_cache;
1012 public static Utils . Settings settings;
@@ -13,6 +15,7 @@ namespace Turntable {
1315 public static Scrobbling . AccountManager account_manager;
1416 public static bool cli_list_clients = false ;
1517 public static string cli_client_id_scrobble;
18+ public static bool cli_mode = false ;
1619 #endif
1720 public class Application : Adw .Application {
1821 #if SCROBBLING
@@ -32,10 +35,14 @@ namespace Turntable {
3235 { " quit" , quit }
3336 };
3437
35- string troubleshooting = " os: %s %s\n prefix: %s\n flatpak : %s\n version: %s (%s )\n gtk: %u.%u.%u (%d.%d.%d )\n libadwaita: %u.%u.%u (%d.%d.%d )\n debug-logs: %s\n scrobbling: %s " . printf (
38+ string troubleshooting = " os: %s %s\n prefix: %s\n sandboxed : %s\n version: %s (%s )\n gtk: %u.%u.%u (%d.%d.%d )\n libadwaita: %u.%u.%u (%d.%d.%d )\n debug-logs: %s\n scrobbling: %s " . printf (
3639 GLib .Environment .get_os_info ("NAME "), GLib.Environment.get_os_info ("VERSION "),
3740 Build.PREFIX,
38- Turntable.is_flatpak.to_string (),
41+ #if SANDBOXED
42+ "true",
43+ #else
44+ "false",
45+ #endif
3946 Build.VERSION, Build.PROFILE,
4047 Gtk.get_major_version (), Gtk.get_minor_version (), Gtk.get_micro_version (),
4148 Gtk.MAJOR_VERSION, Gtk.MINOR_VERSION, Gtk.MICRO_VERSION,
@@ -48,7 +55,7 @@ namespace Turntable {
4855 Soup.MAJOR_VERSION, Soup.MINOR_VERSION, Soup.MICRO_VERSION,
4956 Json.MAJOR_VERSION, Json.MINOR_VERSION, Json.MICRO_VERSION,
5057 Secret.MAJOR_VERSION, Secret.MINOR_VERSION, Secret.MICRO_VERSION,
51- @"$(cli_list_clients || cli_client_id_scrobble != null)"
58+ cli_mode.to_string ()
5259 )
5360 #else
5461 "false"
@@ -81,6 +88,18 @@ namespace Turntable {
8188 this . add_action_entries (APP_ENTRIES , this );
8289 this . set_accels_for_action (" app.quit" , {" <primary>q" });
8390 this . set_accels_for_action (" app.new-window" , {" <primary>n" });
91+
92+ #if SANDBOXED
93+ var display = Gdk . Display . get_default ();
94+ if (display != null ) {
95+ string home = GLib . Environment . get_home_dir ();
96+ var theme = Gtk . IconTheme . get_for_display (display);
97+ theme. add_search_path (@" $home /.local/share/icons" );
98+ theme. add_search_path (@" $home /.local/share/flatpak/exports/share/icons" );
99+ theme. add_search_path (" /var/lib/snapd/desktop/icons" );
100+ theme. add_search_path (" /var/lib/flatpak/exports/share/icons" );
101+ }
102+ #endif
84103 }
85104
86105 public static int main (string [] args ) {
@@ -102,15 +121,44 @@ namespace Turntable {
102121 Intl . textdomain (Build . GETTEXT_PACKAGE );
103122
104123 debug_enabled = ! GLib . Log . writer_default_would_drop (GLib . LogLevelFlags . LEVEL_DEBUG , " Turntable" );
105- is_flatpak = GLib . Environment . get_variable (" FLATPAK_ID" ) != null || GLib . File . new_for_path (" /.flatpak-info" ). query_exists ();
106124 GLib . Environment . unset_variable (" GTK_THEME" );
125+
126+ #if SCROBBLING
127+ cli_mode = cli_list_clients || cli_client_id_scrobble != null ;
128+ #endif
129+
130+ #if SANDBOXED
131+ #if SCROBBLING
132+ if (! cli_mode)
133+ #endif
134+ {
135+ string [] temp_dirs = {};
136+ string home = GLib . Environment . get_home_dir ();
137+ string [] def_dirs = {
138+ " /usr/share/applications" ,
139+ @" $home /.local/share/applications" ,
140+ " /var/lib/flatpak/exports/share/applications" ,
141+ @" $home /.local/share/flatpak/exports/share/applications" ,
142+ " /var/lib/snapd/desktop/applications"
143+ };
144+
145+ foreach (string path in def_dirs) {
146+ if (GLib . FileUtils . test (path, GLib . FileTest . IS_DIR )) {
147+ temp_dirs + = path;
148+ }
149+ }
150+
151+ desktop_file_dirs = temp_dirs;
152+ }
153+ #endif
154+
107155 mpris_manager = new Mpris .Manager ();
108- application = new Application ();
109156
110157 #if SCROBBLING
111- if (cli_list_clients || cli_client_id_scrobble != null ) return (new Utils .CLI ()). run ();
158+ if (cli_mode ) return (new Utils .CLI ()). run ();
112159 #endif
113160
161+ application = new Application ();
114162 return application. run (args);
115163 }
116164
0 commit comments