mirror of
https://gitlab.com/kelteseth/ScreenPlay.git
synced 2024-11-07 03:22:33 +01:00
Add autostart for MacOS
This commit is contained in:
parent
2416a7074c
commit
3efbda68ee
@ -129,5 +129,6 @@
|
||||
<file>assets/icons/icon_sort-down-solid.svg</file>
|
||||
<file>assets/icons/brand_reddit.svg</file>
|
||||
<file>assets/icons/steam_default_avatar.png</file>
|
||||
<file>assets/macos/app.screenplay.plist</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
18
ScreenPlay/assets/macos/app.screenplay.plist
Normal file
18
ScreenPlay/assets/macos/app.screenplay.plist
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>Label</key>
|
||||
<string>app.screenplay</string>
|
||||
<key>ProgramArguments</key>
|
||||
<array>
|
||||
<string>{{SCREENPLAY_PATH}}</string>
|
||||
</array>
|
||||
<key>ProcessType</key>
|
||||
<string>Interactive</string>
|
||||
<key>RunAtLoad</key>
|
||||
<{{SCREENPLAY_AUTOSTART}}/>
|
||||
<key>KeepAlive</key>
|
||||
<false/>
|
||||
</dict>
|
||||
</plist>
|
@ -39,6 +39,16 @@ Settings::Settings(const std::shared_ptr<GlobalVariables>& globalVariables,
|
||||
: QObject(parent)
|
||||
, m_globalVariables { globalVariables }
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
setDesktopEnvironment(DesktopEnvironment::Windows);
|
||||
#endif
|
||||
#ifdef Q_OS_OSX
|
||||
setDesktopEnvironment(DesktopEnvironment::OSX);
|
||||
#endif
|
||||
#ifdef Q_OS_LINUX
|
||||
// We only support KDE for now
|
||||
setDesktopEnvironment(DesktopEnvironment::KDE);
|
||||
#endif
|
||||
|
||||
qRegisterMetaType<Settings::Language>("Settings::Language");
|
||||
qRegisterMetaType<Settings::Theme>("Settings::Theme");
|
||||
@ -47,15 +57,15 @@ Settings::Settings(const std::shared_ptr<GlobalVariables>& globalVariables,
|
||||
qmlRegisterUncreatableType<Settings>("Settings", 1, 0, "Settings", "Error only for enums");
|
||||
|
||||
if (!m_qSettings.contains("Autostart")) {
|
||||
#ifdef Q_OS_WIN
|
||||
QSettings settings("HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat);
|
||||
if (!m_qSettings.value("Autostart").toBool()) {
|
||||
if (!settings.contains("ScreenPlay")) {
|
||||
if (desktopEnvironment() == DesktopEnvironment::Windows) {
|
||||
QSettings settings("HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat);
|
||||
if (!m_qSettings.value("Autostart").toBool()) {
|
||||
if (!settings.contains("ScreenPlay")) {
|
||||
}
|
||||
}
|
||||
settings.setValue("ScreenPlay", QDir::toNativeSeparators(QCoreApplication::applicationFilePath()) + " -silent");
|
||||
settings.sync();
|
||||
}
|
||||
settings.setValue("ScreenPlay", QDir::toNativeSeparators(QCoreApplication::applicationFilePath()) + " -silent");
|
||||
settings.sync();
|
||||
#endif
|
||||
m_qSettings.setValue("Autostart", true);
|
||||
m_qSettings.sync();
|
||||
} else {
|
||||
@ -87,54 +97,10 @@ Settings::Settings(const std::shared_ptr<GlobalVariables>& globalVariables,
|
||||
writeJsonFileFromResource("profiles");
|
||||
}
|
||||
|
||||
//If empty use steam workshop location
|
||||
if (QString(m_qSettings.value("ScreenPlayContentPath").toString()).isEmpty()) {
|
||||
|
||||
/*
|
||||
* ! We must use this (ugly) method, because to stay FOSS we cannot call the steamAPI here !
|
||||
*
|
||||
* We start with the assumption that when we go up 2 folder.
|
||||
* So that there must be at least a common folder:
|
||||
* Windows example:
|
||||
* From -> C:\Program Files (x86)\Steam\steamapps\common\ScreenPlay
|
||||
* To -> C:\Program Files (x86)\Steam\steamapps\
|
||||
* Dest.-> C:\Program Files (x86)\Steam\steamapps\workshop\content\672870
|
||||
*
|
||||
* When we reach the folder it _can_ contain a workshop folder when the user
|
||||
* previously installed any workshop content. If the folder does not exsist we
|
||||
* need to create it by hand. Normally Steam will create this folder but we need to
|
||||
* set it here at this point so that the QFileSystemWatcher in InstalledListModel does
|
||||
* not generate warnings.
|
||||
*/
|
||||
QDir dir;
|
||||
QString path = QApplication::instance()->applicationDirPath() + "/../../workshop/content/672870";
|
||||
if (!dir.mkpath(path)) {
|
||||
qWarning() << "Could not create steam workshop path for path: " << path;
|
||||
} else {
|
||||
m_globalVariables->setLocalStoragePath(QUrl::fromUserInput(path));
|
||||
m_qSettings.setValue("ScreenPlayContentPath", dir.cleanPath(path));
|
||||
m_qSettings.sync();
|
||||
}
|
||||
|
||||
} else {
|
||||
m_globalVariables->setLocalStoragePath(QUrl::fromUserInput(m_qSettings.value("ScreenPlayContentPath").toString()));
|
||||
}
|
||||
initInstalledPath();
|
||||
|
||||
setupWidgetAndWindowPaths();
|
||||
setGitBuildHash(COMPILE_INFO);
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
setDesktopEnvironment(DesktopEnvironment::Windows);
|
||||
#endif
|
||||
|
||||
#ifdef Q_OS_OSX
|
||||
setDesktopEnvironment(DesktopEnvironment::OSX);
|
||||
#endif
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
// We only support KDE for now
|
||||
setDesktopEnvironment(DesktopEnvironment::KDE);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -204,6 +170,53 @@ void Settings::restoreDefault(const QString& appConfigLocation, const QString& s
|
||||
writeJsonFileFromResource(settingsFileType);
|
||||
}
|
||||
|
||||
void Settings::initInstalledPath()
|
||||
{
|
||||
//If empty use steam workshop location
|
||||
qInfo() << m_qSettings.value("ScreenPlayContentPath").toString();
|
||||
if (QString(m_qSettings.value("ScreenPlayContentPath").toString()).isEmpty()) {
|
||||
|
||||
/*
|
||||
* ! We must use this (ugly) method, because to stay FOSS we cannot call the steamAPI here !
|
||||
*
|
||||
* We start with the assumption that when we go up 2 folder.
|
||||
* So that there must be at least a common folder:
|
||||
* Windows example:
|
||||
* From -> C:\Program Files (x86)\Steam\steamapps\common\ScreenPlay
|
||||
* To -> C:\Program Files (x86)\Steam\steamapps\
|
||||
* Dest.-> C:\Program Files (x86)\Steam\steamapps\workshop\content\672870
|
||||
*
|
||||
* When we reach the folder it _can_ contain a workshop folder when the user
|
||||
* previously installed any workshop content. If the folder does not exsist we
|
||||
* need to create it by hand. Normally Steam will create this folder but we need to
|
||||
* set it here at this point so that the QFileSystemWatcher in InstalledListModel does
|
||||
* not generate warnings.
|
||||
*/
|
||||
QDir dir;
|
||||
QString appBasePath = QApplication::instance()->applicationDirPath();
|
||||
if (desktopEnvironment() == DesktopEnvironment::OSX) {
|
||||
appBasePath += "/../../..";
|
||||
}
|
||||
QString path = appBasePath + "/../../workshop/content/672870";
|
||||
qInfo() << path;
|
||||
|
||||
if (!dir.mkpath(path)) {
|
||||
qWarning() << "Could not create steam workshop path for path: " << path;
|
||||
}
|
||||
|
||||
if (QDir(path).exists()) {
|
||||
m_globalVariables->setLocalStoragePath(QUrl::fromUserInput(path));
|
||||
m_qSettings.setValue("ScreenPlayContentPath", dir.cleanPath(path));
|
||||
m_qSettings.sync();
|
||||
} else {
|
||||
qWarning() << "The following path could not be resolved to search for workshop content: " << path;
|
||||
}
|
||||
|
||||
} else {
|
||||
m_globalVariables->setLocalStoragePath(QUrl::fromUserInput(m_qSettings.value("ScreenPlayContentPath").toString()));
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Checks if there is already a saved language. If not we try to use the system langauge.
|
||||
If we do not support the system language we use english.
|
||||
|
@ -39,6 +39,7 @@
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QFontDatabase>
|
||||
#include <QIODevice>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
@ -185,19 +186,48 @@ public slots:
|
||||
|
||||
void setAutostart(bool autostart)
|
||||
{
|
||||
if (m_autostart == autostart)
|
||||
return;
|
||||
if (desktopEnvironment() == DesktopEnvironment::Windows) {
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
QSettings settings("HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat);
|
||||
if (autostart) {
|
||||
settings.setValue("ScreenPlay", QDir::toNativeSeparators(QCoreApplication::applicationFilePath()) + " -silent");
|
||||
settings.sync();
|
||||
} else {
|
||||
settings.remove("ScreenPlay");
|
||||
QSettings settings("HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat);
|
||||
if (autostart) {
|
||||
settings.setValue("ScreenPlay", QDir::toNativeSeparators(QCoreApplication::applicationFilePath()) + " -silent");
|
||||
settings.sync();
|
||||
} else {
|
||||
settings.remove("ScreenPlay");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (desktopEnvironment() == DesktopEnvironment::OSX) {
|
||||
const QString plistFileName = "app.screenplay.plist";
|
||||
QFile defaultPListFile(":/assets/macos/" + plistFileName);
|
||||
defaultPListFile.open(QIODevice::ReadOnly);
|
||||
QString settingsPlistContent = defaultPListFile.readAll();
|
||||
if(!settingsPlistContent.contains("{{SCREENPLAY_PATH}}")){
|
||||
qCritical() << "Unable to load plist settings template from qrc to set autostart!";
|
||||
}
|
||||
|
||||
QDir workingDir(QGuiApplication::applicationDirPath());
|
||||
workingDir.cdUp();
|
||||
workingDir.cdUp();
|
||||
workingDir.cdUp();
|
||||
const QString screenPlayPath = QUrl::fromUserInput(workingDir.path() + "/ScreenPlay.app/Contents/MacOS/ScreenPlay").toLocalFile();
|
||||
settingsPlistContent.replace("{{SCREENPLAY_PATH}}", screenPlayPath);
|
||||
settingsPlistContent.replace("{{SCREENPLAY_AUTOSTART}}", autostart ? "true":"false");
|
||||
|
||||
const QString homePath = QDir::homePath();
|
||||
QFile settingsPlist(homePath + "/Library/LaunchAgents/" + plistFileName);
|
||||
if (settingsPlist.exists()) {
|
||||
if(!settingsPlist.remove()){
|
||||
qCritical() << "Unable to remove: " << settingsPlist;
|
||||
}
|
||||
}
|
||||
|
||||
settingsPlist.open(QIODevice::WriteOnly | QIODevice::Truncate);
|
||||
QTextStream out(&settingsPlist);
|
||||
out.setCodec("UTF-8");
|
||||
out << settingsPlistContent;
|
||||
settingsPlist.flush();
|
||||
settingsPlist.close();
|
||||
}
|
||||
setqSetting("Autostart", autostart);
|
||||
|
||||
m_autostart = autostart;
|
||||
@ -371,6 +401,7 @@ public slots:
|
||||
|
||||
private:
|
||||
void restoreDefault(const QString& appConfigLocation, const QString& settingsFileType);
|
||||
void initInstalledPath();
|
||||
|
||||
private:
|
||||
QSettings m_qSettings;
|
||||
|
Loading…
Reference in New Issue
Block a user