forked from Silverfish/proton-bridge
GODT-2134: fix dock icon on macOS when launched with '--no-window'.
This commit is contained in:
@ -28,6 +28,7 @@ namespace
|
||||
|
||||
|
||||
QString const launcherFlag = "--launcher"; ///< launcher flag parameter used for bridge.
|
||||
QString const noWindowFlag = "--no-window"; ///< The no-window command-line flag.
|
||||
|
||||
|
||||
//****************************************************************************************************************************************************
|
||||
@ -89,9 +90,12 @@ Log::Level parseLogLevel(int argc, char *argv[])
|
||||
/// \param[out] launcher launcher used in argument, forced to self application if not specify.
|
||||
/// \param[out] outAttach The value for the 'attach' command-line parameter.
|
||||
/// \param[out] outLogLevel The parsed log level. If not found, the default log level is returned.
|
||||
/// \param[out] outNoWindow True if the '--no-window' flag was found on the command-line.
|
||||
//****************************************************************************************************************************************************
|
||||
void parseCommandLineArguments(int argc, char *argv[], QStringList& args, QString& launcher, bool &outAttach, Log::Level& outLogLevel) {
|
||||
void parseCommandLineArguments(int argc, char *argv[], QStringList& args, QString& launcher, bool &outAttach, Log::Level& outLogLevel,
|
||||
bool &outNoWindow) {
|
||||
bool flagFound = false;
|
||||
outNoWindow = false;
|
||||
launcher = QString::fromLocal8Bit(argv[0]);
|
||||
// for unknown reasons, on Windows QCoreApplication::arguments() frequently returns an empty list, which is incorrect, so we rebuild the argument
|
||||
// list from the original argc and argv values.
|
||||
@ -99,6 +103,10 @@ void parseCommandLineArguments(int argc, char *argv[], QStringList& args, QStrin
|
||||
QString const &arg = QString::fromLocal8Bit(argv[i]);
|
||||
// we can't use QCommandLineParser here since it will fail on unknown options.
|
||||
// Arguments may contain some bridge flags.
|
||||
|
||||
if (arg == noWindowFlag)
|
||||
outNoWindow = true;
|
||||
|
||||
if (arg == launcherFlag)
|
||||
{
|
||||
args.append(arg);
|
||||
|
||||
@ -23,7 +23,8 @@
|
||||
#include <bridgepp/Log/Log.h>
|
||||
|
||||
|
||||
void parseCommandLineArguments(int argc, char *argv[], QStringList& args, QString& launcher, bool &outAttach, bridgepp::Log::Level& outLogLevel); ///< Parse the command-line arguments
|
||||
void parseCommandLineArguments(int argc, char *argv[], QStringList& args, QString& launcher, bool &outAttach, bridgepp::Log::Level& outLogLevel,
|
||||
bool &outNoWindow); ///< Parse the command-line arguments
|
||||
|
||||
|
||||
#endif //BRIDGE_GUI_COMMAND_LINE_H
|
||||
|
||||
@ -67,6 +67,7 @@
|
||||
<file>qml/icons/systray-mono-warn.png</file>
|
||||
<file>qml/icons/systray.svg</file>
|
||||
<file alias="bridge.svg">../../../../dist/bridge.svg</file>
|
||||
<file alias="bridgeMacOS.svg">../../../../dist/bridgeMacOS.svg</file>
|
||||
<file>qml/KeychainSettings.qml</file>
|
||||
<file>qml/LocalCacheSettings.qml</file>
|
||||
<file>qml/MainWindow.qml</file>
|
||||
|
||||
@ -72,7 +72,16 @@ void initQtApplication()
|
||||
QGuiApplication::setOrganizationName(PROJECT_VENDOR);
|
||||
QGuiApplication::setOrganizationDomain("proton.ch");
|
||||
QGuiApplication::setQuitOnLastWindowClosed(false);
|
||||
#ifdef Q_OS_MACOS
|
||||
// on macOS, the app icon as it appears in the dock and file system is defined by in the app bundle plist, not here.
|
||||
// We still use this copy (lock icon in white rectangle), so that devs that use the bridge-gui exe directly get a decent looking icon in the dock.
|
||||
// Qt does not support the native .icns format, so we use a PNG file.
|
||||
QGuiApplication::setWindowIcon(QIcon(":bridgeMacOS.svg"));
|
||||
#else
|
||||
// On non macOS platform, this icon (without the white rectangle background, is used in the OS decoration elements (title bar, task bar, etc...)
|
||||
// It's not use as the executable icon.
|
||||
QGuiApplication::setWindowIcon(QIcon(":bridge.svg"));
|
||||
#endif // #ifdef Q_OS_MACOS
|
||||
}
|
||||
|
||||
|
||||
@ -113,7 +122,6 @@ Log &initLog()
|
||||
QQmlComponent *createRootQmlComponent(QQmlApplicationEngine &engine)
|
||||
{
|
||||
QString const qrcQmlDir = "qrc:/qml";
|
||||
|
||||
qmlRegisterSingletonInstance("Proton", 1, 0, "Backend", &app().backend());
|
||||
qmlRegisterType<UserList>("Proton", 1, 0, "UserList");
|
||||
qmlRegisterType<bridgepp::User>("Proton", 1, 0, "User");
|
||||
@ -302,8 +310,12 @@ int main(int argc, char *argv[])
|
||||
QStringList args;
|
||||
QString launcher;
|
||||
bool attach = false;
|
||||
bool noWindow;
|
||||
Log::Level logLevel = Log::defaultLevel;
|
||||
parseCommandLineArguments(argc, argv, args, launcher, attach, logLevel);
|
||||
parseCommandLineArguments(argc, argv, args, launcher, attach, logLevel, noWindow);
|
||||
#ifdef Q_OS_MACOS
|
||||
setDockIconVisibleState(!noWindow);
|
||||
#endif
|
||||
|
||||
// In attached mode, we do not intercept stderr and stdout of bridge, as we did not launch it ourselves, so we output the log to the console.
|
||||
// When not in attached mode, log entries are forwarded to bridge, which output it on stdout/stderr. bridge-gui's process monitor intercept
|
||||
|
||||
Reference in New Issue
Block a user