GODT-2134: fix dock icon on macOS when launched with '--no-window'.

This commit is contained in:
Xavier Michelon 2022-11-22 09:50:20 +01:00
parent b97ffc16ea
commit c473e987f4
5 changed files with 48 additions and 4 deletions

22
dist/bridgeMacOS.svg vendored Normal file
View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="100%" height="100%" viewBox="0 0 260 260" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">
<g>
<g transform="matrix(1.27944,0,0,1.35453,-34.9539,-16.0513)">
<path d="M40,62.391C40,38.979 58.979,20 82.391,20L177.609,20C201.021,20 220,38.979 220,62.391L220,157.609C220,181.021 201.021,200 177.609,200L82.391,200C58.979,200 40,181.021 40,157.609L40,62.391Z" style="fill:white;fill-rule:nonzero;"/>
</g>
<g transform="matrix(1.41874,0,0,1.41874,-55.214,-18.9171)">
<path d="M129.748,48.657C101.923,48.657 79.369,71.21 79.369,99.035L79.369,149.747C79.369,155.139 83.74,159.509 89.131,159.509L171.407,159.509C176.22,159.509 180.126,155.604 180.126,150.79L180.126,99.035C180.126,71.214 157.572,48.657 129.748,48.657ZM158.746,98.755L136.726,117.305C132.752,120.655 126.939,120.655 122.965,117.305L100.945,98.755C100.945,83.014 113.708,70.251 129.45,70.251L130.242,70.251C145.983,70.251 158.746,83.014 158.746,98.755Z" style="fill:rgb(109,74,255);fill-rule:nonzero;"/>
</g>
<g transform="matrix(1.41874,0,0,1.41874,-55.214,-18.9171)">
<path d="M129.748,48.657C101.923,48.657 79.369,71.21 79.369,99.035L79.369,149.748C79.369,155.139 83.74,159.509 89.131,159.509L171.407,159.509C176.22,159.509 180.126,155.604 180.126,150.79L180.126,99.035C180.126,71.214 157.572,48.657 129.748,48.657ZM158.746,98.755L136.726,117.305C132.752,120.655 126.939,120.655 122.965,117.305L100.945,98.755C100.945,83.014 113.708,70.251 129.45,70.251L130.242,70.251C145.983,70.251 158.746,83.014 158.746,98.755Z" style="fill:url(#_Linear1);fill-rule:nonzero;"/>
</g>
<g transform="matrix(1.41874,0,0,1.41874,-55.214,-18.9171)">
<path d="M136.764,117.529C134.468,119.388 128.499,121.99 122.989,117.529C117.479,113.069 106.044,103.208 101.015,98.835L101.041,98.835L100.946,98.756C100.946,83.014 113.709,70.251 129.45,70.251L130.242,70.251C145.984,70.251 158.746,83.014 158.746,98.756L158.652,98.835L158.737,98.835L158.737,159.51L171.407,159.51C176.221,159.51 180.126,155.604 180.126,150.79L180.126,99.035C180.126,71.214 157.573,48.657 129.748,48.657C101.923,48.657 79.37,71.211 79.37,99.035L79.37,102.219L110.526,129.008C112.822,131.195 118.857,134.256 124.629,129.008C130.401,123.761 135.124,119.169 136.764,117.529Z" style="fill:url(#_Radial2);fill-rule:nonzero;"/>
</g>
</g>
<defs>
<linearGradient id="_Linear1" x1="0" y1="0" x2="1" y2="0" gradientUnits="userSpaceOnUse" gradientTransform="matrix(15.0864,-42.636,42.636,15.0864,82.9769,172.3)"><stop offset="0" style="stop-color:rgb(40,176,232);stop-opacity:1"/><stop offset="1" style="stop-color:rgb(197,183,255);stop-opacity:0"/></linearGradient>
<radialGradient id="_Radial2" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="matrix(-94.8157,-85.2706,69.7189,-77.5232,174.186,168.693)"><stop offset="0" style="stop-color:rgb(226,219,255);stop-opacity:1"/><stop offset="1" style="stop-color:rgb(109,74,255);stop-opacity:1"/></radialGradient>
</defs>
</svg>

After

Width:  |  Height:  |  Size: 3.3 KiB

View File

@ -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);

View File

@ -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

View File

@ -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>

View 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