2121
2222#include < gtk/gtk.h>
2323
24+ #include " ../os/app.h"
25+
2426#ifdef OS_WINDOWS
2527#include < windows.h>
2628#endif
@@ -43,12 +45,8 @@ GtkApplication *Application::application = nullptr;
4345base::map<string, string> Application::_properties_;
4446
4547Flags Application::flags = Flags::NONE;
46- Path Application::filename;
47- Path Application::directory;
48- Path Application::directory_static;
49- Path Application::initial_working_directory;
50- bool Application::installed;
5148bool Application::adwaita_started = false ;
49+ bool Application::allowed = true ;
5250
5351Array<string> Application::_args;
5452
@@ -87,46 +85,51 @@ void _init_global_css_classes_() {
8785#endif
8886}
8987
88+ void init_low_level () {
89+ _InitInput_ ();
90+ new (&Application::_properties_) base::map<string, string>();
91+
92+ separator = " \\ " ;
93+ _using_language_ = false ;
94+ }
95+
9096Application::Application (const string &app_name, const string &def_lang, Flags _flags) {
97+ init_low_level ();
9198 flags = _flags;
9299
93100#ifdef HUI_API_GTK
94101 g_set_prgname (app_name.c_str ());
95102#endif
96103
97- guess_directories (_args, app_name);
104+ os::app::detect (_args, app_name);
98105
99106
100- _InitInput_ ();
101-
102- separator = " \\ " ;
103- _using_language_ = false ;
104107 if ((flags & Flags::NO_ERROR_HANDLER) == 0 )
105108 SetDefaultErrorHandler (nullptr );
106109
107- if (os::fs::exists (directory | " config.txt" ))
108- config.load (directory | " config.txt" );
110+ if (os::fs::exists (os::app::directory_dynamic | " config.txt" ))
111+ config.load (os::app::directory_dynamic | " config.txt" );
109112
110113
111114 if ((flags & Flags::DONT_LOAD_RESOURCE) == 0 )
112- load_resource (directory_static | " hui_resources.txt" );
115+ load_resource (os::app:: directory_static | " hui_resources.txt" );
113116
114117 if (def_lang.num > 0 )
115118 set_language (config.get_str (" Language" , def_lang));
116119
117120
118121 // default "logo" used for "about" dialog (full path)
119122#if defined(OS_LINUX) || defined(OS_MAC)
120- if (os::fs::exists (directory_static | " icons" | " hicolor" | " scalable" | " apps" | (app_name + " .svg" )))
121- set_property (" logo" , str (directory_static | " icons" | " hicolor" | " scalable" | " apps" | (app_name + " .svg" )));
122- else if (os::fs::exists (directory_static | " icon.svg" ))
123- set_property (" logo" , str (directory_static | " icon.svg" ));
123+ if (os::fs::exists (os::app:: directory_static | " icons" | " hicolor" | " scalable" | " apps" | (app_name + " .svg" )))
124+ set_property (" logo" , str (os::app:: directory_static | " icons" | " hicolor" | " scalable" | " apps" | (app_name + " .svg" )));
125+ else if (os::fs::exists (os::app:: directory_static | " icon.svg" ))
126+ set_property (" logo" , str (os::app:: directory_static | " icon.svg" ));
124127 else
125128#endif
126- if (os::fs::exists (directory_static | " icon.png" ))
127- set_property (" logo" , str (directory_static | " icon.png" ));
128- else if (os::fs::exists (directory_static | " icon.ico" ))
129- set_property (" logo" , str (directory_static | " icon.ico" ));
129+ if (os::fs::exists (os::app:: directory_static | " icon.png" ))
130+ set_property (" logo" , str (os::app:: directory_static | " icon.png" ));
131+ else if (os::fs::exists (os::app:: directory_static | " icon.ico" ))
132+ set_property (" logo" , str (os::app:: directory_static | " icon.ico" ));
130133
131134 // default "icon" used for windows (just name)
132135 set_property (" icon" , app_name);
@@ -136,7 +139,7 @@ Application::~Application() {
136139 // foreachb(Window *w, _all_windows_)
137140 // delete(w);
138141 if (config.changed )
139- config.save (directory | " config.txt" );
142+ config.save (os::app::directory_dynamic | " config.txt" );
140143 if ((msg_inited) /* && (HuiMainLevel == 0)*/ )
141144 msg_end ();
142145
@@ -160,67 +163,6 @@ Path strip_dev_dirs(const Path &p) {
160163 return p;
161164}
162165
163- // filename -> executable file
164- // directory ->
165- // NONINSTALLED: binary dir
166- // INSTALLED: ~/.MY_APP/ <<< now always this
167- // directory_static ->
168- // NONINSTALLED: binary dir/static/
169- // INSTALLED: /usr/local/share/MY_APP/
170- // initial_working_directory -> working dir before running this program
171- void Application::guess_directories (const Array<string> &arg, const string &app_name) {
172-
173- initial_working_directory = os::fs::current_directory ();
174- installed = false ;
175-
176-
177- // executable file
178- #if defined(OS_LINUX) || defined(OS_MAC) || defined(OS_MINGW) // defined(__GNUC__) || defined(OS_LINUX)
179- if (arg.num > 0 )
180- filename = arg[0 ];
181- #else // OS_WINDOWS
182- char *ttt = nullptr ;
183- int r = _get_pgmptr (&ttt);
184- filename = ttt;
185- hui_win_instance = (void *)GetModuleHandle (nullptr );
186- #endif
187-
188-
189- // first, assume a local/non-installed version
190- directory = initial_working_directory; // strip_dev_dirs(filename.parent());
191- directory_static = directory | " static" ;
192-
193- #ifdef INSTALL_PREFIX
194- // our build system should define this:
195- Path prefix = INSTALL_PREFIX;
196- #else
197- // oh no... fall-back
198- Path prefix = " /usr/local" ;
199- #endif
200-
201- #if defined(OS_LINUX) || defined(OS_MAC) || defined(OS_MINGW) // defined(__GNUC__) || defined(OS_LINUX)
202- // installed version?
203- if (filename.is_in (prefix) or (filename.str ().find (" /" ) < 0 )) {
204- installed = true ;
205- directory_static = prefix | " share" | app_name;
206- }
207-
208- // inside an AppImage?
209- if (getenv (" APPIMAGE" )) {
210- installed = true ;
211- directory_static = Path (getenv (" APPDIR" )) | " usr" | " share" | app_name;
212- }
213-
214- // inside MacOS bundle?
215- if (str (filename).find (" .app/Contents/MacOS/" ) >= 0 ) {
216- installed = true ;
217- directory_static = filename.parent ().parent () | " Resources" ;
218- }
219-
220- directory = format (" %s/.%s/" , getenv (" HOME" ), app_name);
221- os::fs::create_directory (directory);
222- #endif
223- }
224166
225167#if GTK_CHECK_VERSION(4,0,0)
226168static bool keep_running = true ;
@@ -246,7 +188,7 @@ static void on_gtk_application_activate(GApplication *_g_app, gpointer user_data
246188
247189 // add local icon theme
248190 auto icon_theme = gtk_icon_theme_get_for_display (gdk_display_get_default ());
249- gtk_icon_theme_add_search_path (icon_theme, str (Application ::directory_static | " icons" ).c_str ());
191+ gtk_icon_theme_add_search_path (icon_theme, str (os::app ::directory_static | " icons" ).c_str ());
250192
251193 if (_run_after_gui_init_func_)
252194 _run_after_gui_init_func_ ();
@@ -324,6 +266,8 @@ void Application::set_property(const string &name, const string &value) {
324266}
325267
326268string Application::get_property (const string &name) {
269+ if (!_properties_.contains (name))
270+ return " " ;
327271 try {
328272 return _properties_[name];
329273 } catch (...) {
0 commit comments