| | | 1 | | // SPDX-FileCopyrightText: 2026 Alper Çelik |
| | | 2 | | // SPDX-License-Identifier: MIT OR Apache-2.0 |
| | | 3 | | |
| | | 4 | | #include "qt_app.hpp" |
| | | 5 | | #include "qt_scheme.hpp" |
| | | 6 | | |
| | | 7 | | #include <QtCore/QCoreApplication> |
| | | 8 | | #include <QtCore/QString> |
| | | 9 | | #include <QtWidgets/QApplication> |
| | | 10 | | |
| | | 11 | | namespace { |
| | | 12 | | QApplication* g_app = nullptr; |
| | | 13 | | } |
| | | 14 | | |
| | 21 | 15 | | int qt_init(int argc) { |
| | 21 | 16 | | if (g_app != nullptr || QCoreApplication::instance() != nullptr) { |
| | 0 | 17 | | return 1; |
| | 0 | 18 | | } |
| | 21 | 19 | | QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts); |
| | | 20 | | |
| | | 21 | | // Tauri's URL schemes must be registered before any GUI object exists. |
| | 21 | 22 | | qt_scheme_register_schemes(); |
| | | 23 | | |
| | 21 | 24 | | static int argc_storage = argc > 0 ? argc : 1; |
| | 21 | 25 | | static char argv0[] = "tauri-runtime-qt"; |
| | 21 | 26 | | static char* argv[] = {argv0, nullptr}; |
| | 21 | 27 | | g_app = new QApplication(argc_storage, argv); |
| | | 28 | | |
| | 21 | 29 | | return 0; |
| | 21 | 30 | | } |
| | | 31 | | |
| | 21 | 32 | | int qt_run() { |
| | 21 | 33 | | if (g_app == nullptr) { |
| | 0 | 34 | | return 1; |
| | 0 | 35 | | } |
| | 21 | 36 | | return QApplication::exec(); |
| | 21 | 37 | | } |
| | | 38 | | |
| | 0 | 39 | | rust::String qt_version() { |
| | 0 | 40 | | return rust::String(qVersion()); |
| | 0 | 41 | | } |