Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015-2020 by Savoir-faire Linux |
| 3 | * Author: Edric Ladent Milaret <edric.ladent-milaret@savoirfairelinux.com> |
| 4 | * Author: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com> |
| 5 | * Author: Mingrui Zhang <mingrui.zhang@savoirfairelinux.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 3 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 19 | */ |
| 20 | |
| 21 | #include "mainapplication.h" |
| 22 | #include "runguard.h" |
| 23 | |
| 24 | #include <clocale> |
| 25 | #include <QCryptographicHash> |
| 26 | |
| 27 | #include <clocale> |
| 28 | |
| 29 | int |
| 30 | main(int argc, char *argv[]) |
| 31 | { |
| 32 | setlocale(LC_ALL, "en_US.utf8"); |
| 33 | #ifdef Q_OS_LINUX |
| 34 | setenv("QT_QPA_PLATFORMTHEME", "gtk3", true); |
| 35 | #endif |
| 36 | |
| 37 | MainApplication::applicationInitialization(); |
| 38 | |
| 39 | char ARG_DISABLE_WEB_SECURITY[] = "--disable-web-security"; |
| 40 | auto newArgv = MainApplication::parseInputArgument(argc, argv, ARG_DISABLE_WEB_SECURITY); |
| 41 | |
| 42 | MainApplication a(argc, newArgv); |
| 43 | |
| 44 | /* |
| 45 | * Runguard to make sure that only one instance runs at a time. |
| 46 | * Note: needs to be after the creation of the application |
| 47 | */ |
| 48 | QCryptographicHash appData(QCryptographicHash::Sha256); |
| 49 | appData.addData(QApplication::applicationName().toUtf8()); |
| 50 | appData.addData(QApplication::organizationDomain().toUtf8()); |
| 51 | RunGuard guard(appData.result()); |
| 52 | if (!guard.tryToRun()) { |
| 53 | /* |
| 54 | * No need to exitApp since app is not set up. |
| 55 | */ |
| 56 | return 0; |
| 57 | } |
| 58 | |
| 59 | if (!a.applicationSetup()) { |
| 60 | guard.release(); |
| 61 | a.exitApp(); |
| 62 | return 0; |
| 63 | } |
| 64 | |
| 65 | /* |
| 66 | * Exec the application. |
| 67 | */ |
| 68 | auto ret = a.exec(); |
| 69 | |
| 70 | guard.release(); |
| 71 | return ret; |
| 72 | } |