File tree Expand file tree Collapse file tree 3 files changed +37
-7
lines changed
Expand file tree Collapse file tree 3 files changed +37
-7
lines changed Original file line number Diff line number Diff line change @@ -159,8 +159,7 @@ int main() {
159159 std::cout << " Display removed: " << event.GetDisplay ().id << std::endl;
160160 });
161161
162- AppRunner runner;
163- runner.Run (window_ptr);
162+ RunApp (window_ptr);
164163
165164 return 0 ;
166165}
Original file line number Diff line number Diff line change 11#include " app_runner.h"
22
3- namespace nativeapi {} // namespace nativeapi
3+ namespace nativeapi {
4+
5+ AppRunner& AppRunner::GetInstance () {
6+ static AppRunner instance;
7+ return instance;
8+ }
9+
10+ int RunApp (std::shared_ptr<Window> window) {
11+ return AppRunner::GetInstance ().Run (window);
12+ }
13+
14+ } // namespace nativeapi
Original file line number Diff line number Diff line change 88namespace nativeapi {
99
1010/* *
11- * AppRunner is a class that manages the application lifecycle and runs the main
11+ * AppRunner is a singleton class that manages the application lifecycle and runs the main
1212 * event loop. It provides a way to run an application with a given window and
1313 * handle application events.
1414 */
1515class AppRunner {
1616 public:
17- AppRunner ();
18- virtual ~AppRunner ();
17+ /* *
18+ * Gets the singleton instance of AppRunner.
19+ * @return Reference to the singleton AppRunner instance
20+ */
21+ static AppRunner& GetInstance ();
22+
23+ // Delete copy constructor and assignment operator
24+ AppRunner (const AppRunner&) = delete ;
25+ AppRunner& operator =(const AppRunner&) = delete ;
1926
2027 /* *
2128 * Runs the application with the specified window.
@@ -27,9 +34,22 @@ class AppRunner {
2734 */
2835 int Run (std::shared_ptr<Window> window);
2936
37+
3038 private:
39+ AppRunner ();
40+ virtual ~AppRunner ();
41+
3142 class Impl ;
3243 std::unique_ptr<Impl> pimpl_;
3344};
3445
35- } // namespace nativeapi
46+ /* *
47+ * Convenience function to run the application with the specified window.
48+ * This is equivalent to calling AppRunner::GetInstance().Run(window).
49+ *
50+ * @param window The window to run the application with
51+ * @return Exit code of the application (0 for success)
52+ */
53+ int RunApp (std::shared_ptr<Window> window);
54+
55+ } // namespace nativeapi
You can’t perform that action at this time.
0 commit comments