1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-09-01 16:19:47 +02:00

Hide app icon from dock on macOS

This commit is contained in:
Elias Steurer 2022-12-27 22:07:44 +01:00
parent 16557eb286
commit d2fc2bbc6d
8 changed files with 132 additions and 2 deletions

View File

@ -117,6 +117,7 @@ signals:
public slots:
QString version() const;
void showDockIcon(const bool show);
void exit();
QPointF cursorPos() { return QCursor::pos(); }

View File

@ -84,6 +84,7 @@ ApplicationWindow {
if(alwaysMinimize === "true"){
root.hide()
App.showDockIcon(false);
return
}
@ -105,8 +106,10 @@ ApplicationWindow {
stackView.push("qrc:/qml/ScreenPlayApp/qml/Installed/Installed.qml", {
"sidebar": sidebar
})
if (!App.settings.silentStart)
if (!App.settings.silentStart){
App.showDockIcon(true)
root.show()
}
}
Item {
@ -152,6 +155,7 @@ ApplicationWindow {
Connections {
function onRequestRaise() {
App.showDockIcon(true)
root.show()
}

View File

@ -76,6 +76,7 @@ Util.Popup {
text: qsTr("Minimize ScreenPlay")
onClicked: {
applicationWindow.hide()
App.showDockIcon(false)
root.close()
}
}
@ -85,6 +86,7 @@ Util.Popup {
onClicked: {
settings.setValue("alwaysMinimize", true)
settings.sync()
App.showDockIcon(false)
applicationWindow.hide()
root.close()
}

View File

@ -1,4 +1,7 @@
#include "ScreenPlay/app.h"
#if defined(Q_OS_OSX)
#include "ScreenPlayUtil/macutils.h"
#endif
#include "steam/steam_qt_enums_generated.h"
#include <QProcessEnvironment>
@ -332,4 +335,11 @@ bool App::setupKDE()
}
}
void App::showDockIcon(const bool show)
{
#if defined(Q_OS_OSX)
MacUtils::instance()->showDockIcon(show);
#endif
}
}

View File

@ -40,7 +40,7 @@ set(QML
qml/TrayIcon.qml)
set(SOURCES # cmake-format: sort
inc/public/ScreenPlayUtil/httpfileserver.cpp src/contenttypes.cpp src/util.cpp)
inc/public/ScreenPlayUtil/httpfileserver.cpp src/contenttypes.cpp src/util.cpp src/macutils.mm)
set(HEADER
# cmake-format: sort
@ -54,6 +54,7 @@ set(HEADER
inc/public/ScreenPlayUtil/PropertyHelpers.h
inc/public/ScreenPlayUtil/PtrPropertyHelpers.h
inc/public/ScreenPlayUtil/SingletonHelper.h
inc/public/ScreenPlayUtil/macutils.h
inc/public/ScreenPlayUtil/util.h)
set(RESOURCES # cmake-format: sort

View File

@ -0,0 +1,49 @@
/****************************************************************************
**
** Copyright (C) 2020 Elias Steurer (Kelteseth)
** Contact: https://screen-play.app
**
** This file is part of ScreenPlay. ScreenPlay is licensed under a dual license in
** order to ensure its sustainability. When you contribute to ScreenPlay
** you accept that your work will be available under the two following licenses:
**
** $SCREENPLAY_BEGIN_LICENSE$
**
** #### Affero General Public License Usage (AGPLv3)
** Alternatively, this file may be used under the terms of the GNU Affero
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file "ScreenPlay License.md" included in the
** packaging of this App. Please review the following information to
** ensure the GNU Affero Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/agpl-3.0.en.html.
**
** #### Commercial License
** This code is owned by Elias Steurer. By changing/adding to the code you agree to the
** terms written in:
** * Legal/corporate_contributor_license_agreement.md - For corporate contributors
** * Legal/individual_contributor_license_agreement.md - For individual contributors
**
** #### Additional Limitations to the AGPLv3 and Commercial Lincese
** This License does not grant any rights in the trademarks,
** service marks, or logos.
**
**
** $SCREENPLAY_END_LICENSE
**
****************************************************************************/
#pragma once
#include <QObject>
class MacUtils : public QObject {
Q_OBJECT
private:
static MacUtils* macUtils;
MacUtils();
public:
static MacUtils* instance();
static void showDockIcon(const bool show);
};

View File

@ -31,6 +31,7 @@ SystemTrayIcon {
MenuItem {
text: qsTr("Open ScreenPlay")
onTriggered: {
App.showDockIcon(true);
window.show()
}
}

View File

@ -0,0 +1,62 @@
/****************************************************************************
**
** Copyright (C) 2020 Elias Steurer (Kelteseth)
** Contact: https://screen-play.app
**
** This file is part of ScreenPlay. ScreenPlay is licensed under a dual license in
** order to ensure its sustainability. When you contribute to ScreenPlay
** you accept that your work will be available under the two following licenses:
**
** $SCREENPLAY_BEGIN_LICENSE$
**
** #### Affero General Public License Usage (AGPLv3)
** Alternatively, this file may be used under the terms of the GNU Affero
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file "ScreenPlay License.md" included in the
** packaging of this App. Please review the following information to
** ensure the GNU Affero Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/agpl-3.0.en.html.
**
** #### Commercial License
** This code is owned by Elias Steurer. By changing/adding to the code you agree to the
** terms written in:
** * Legal/corporate_contributor_license_agreement.md - For corporate contributors
** * Legal/individual_contributor_license_agreement.md - For individual contributors
**
** #### Additional Limitations to the AGPLv3 and Commercial Lincese
** This License does not grant any rights in the trademarks,
** service marks, or logos.
**
**
** $SCREENPLAY_END_LICENSE$
**
****************************************************************************/
#include "ScreenPlayUtil/macutils.h"
#import <Cocoa/Cocoa.h>
#import <MacTypes.h>
#import <objc/runtime.h>
MacUtils* MacUtils::macUtils = nullptr;
MacUtils::MacUtils()
{
}
MacUtils* MacUtils::instance()
{
if (!macUtils)
macUtils = new MacUtils;
return macUtils;
}
void MacUtils::showDockIcon(const bool show)
{
ProcessSerialNumber psn = { 0, kCurrentProcess };
if (show) {
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
} else {
TransformProcessType(&psn, kProcessTransformToUIElementApplication);
}
}