18
18
#include < algorithm>
19
19
#include < stdexcept>
20
20
21
-
22
21
// HELPER FUNCTIONS
23
22
24
23
bool verifyLaunchFile ()
@@ -79,9 +78,8 @@ static QMap<class QString, QSharedPointer<ValueHandler>>
79
78
OPTION (" allowMultipleGuiInstances" ,Bool ( false )),
80
79
OPTION (" showMagnifier" ,Bool ( false )),
81
80
OPTION (" squareMagnifier" ,Bool ( false )),
82
- # if !defined(Q_OS_WIN)
81
+
83
82
OPTION (" autoCloseIdleDaemon" ,Bool ( false )),
84
- #endif
85
83
OPTION (" startupLaunch" ,Bool ( false )),
86
84
OPTION (" showStartupLaunchMessage" ,Bool ( true )),
87
85
OPTION (" copyURLAfterUpload" ,Bool ( true )),
@@ -137,7 +135,7 @@ static QMap<QString, QSharedPointer<KeySequence>> recognizedShortcuts = {
137
135
SHORTCUT (" TYPE_ACCEPT" , " Return" ),
138
136
SHORTCUT (" TYPE_EXIT" , " Ctrl+Q" ),
139
137
SHORTCUT (" TYPE_IMAGEUPLOADER" , ),
140
-
138
+ SHORTCUT ( " TYPE_OPEN_APP " , " Ctrl+O " ),
141
139
SHORTCUT (" TYPE_PIXELATE" , " B" ),
142
140
SHORTCUT (" TYPE_INVERT" , " I" ),
143
141
SHORTCUT (" TYPE_REDO" , " Ctrl+Shift+Z" ),
@@ -159,7 +157,6 @@ static QMap<QString, QSharedPointer<KeySequence>> recognizedShortcuts = {
159
157
SHORTCUT (" TYPE_COMMIT_CURRENT_TOOL" , " Ctrl+Return" ),
160
158
161
159
SHORTCUT (" TYPE_DELETE_CURRENT_TOOL" , " Delete" ),
162
-
163
160
SHORTCUT (" TYPE_PIN" , ),
164
161
SHORTCUT (" TYPE_SELECTIONINDICATOR" , ),
165
162
SHORTCUT (" TYPE_SIZEINCREASE" , ),
@@ -229,8 +226,35 @@ void ConfigHandler::setStartupLaunch(const bool start)
229
226
return ;
230
227
}
231
228
setValue (QStringLiteral (" startupLaunch" ), start);
232
-
233
- #if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
229
+ #if defined(Q_OS_MACOS)
230
+ /* TODO - there should be more correct way via API, but didn't find it
231
+ without extra dependencies, there should be something like that:
232
+ https://stackoverflow.com/questions/3358410/programmatically-run-at-startup-on-mac-os-x
233
+ But files with this features differs on different MacOS versions and it
234
+ doesn't work not on a BigSur at lease.
235
+ */
236
+ QProcess process;
237
+ if (start) {
238
+ process.start (" osascript" ,
239
+ QStringList ()
240
+ << " -e"
241
+ << " tell application \" System Events\" to make login "
242
+ " item at end with properties {name: "
243
+ " \" Flameshot\" ,path:\" /Applications/"
244
+ " flameshot.app\" , hidden:false}" );
245
+ } else {
246
+ process.start (" osascript" ,
247
+ QStringList () << " -e"
248
+ << " tell application \" System Events\" to "
249
+ " delete login item \" Flameshot\" " );
250
+ }
251
+ if (!process.waitForFinished ()) {
252
+ qWarning () << " Login items is changed. " << process.errorString ();
253
+ } else {
254
+ qWarning () << " Unable to change login items, error:"
255
+ << process.readAll ();
256
+ }
257
+ #elif defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
234
258
QString path =
235
259
QStandardPaths::writableLocation (QStandardPaths::GenericConfigLocation) +
236
260
" /autostart/" ;
@@ -250,7 +274,7 @@ void ConfigHandler::setStartupLaunch(const bool start)
250
274
} else {
251
275
file.remove ();
252
276
}
253
- #elif
277
+ #elif defined(Q_OS_WIN)
254
278
QSettings bootUpSettings (
255
279
" HKEY_CURRENT_USER\\ SOFTWARE\\ Microsoft\\ Windows\\ CurrentVersion\\ Run" ,
256
280
QSettings::NativeFormat);
@@ -336,9 +360,13 @@ bool ConfigHandler::setShortcut(const QString& actionName,
336
360
{
337
361
qDebug () << actionName;
338
362
static QVector<QKeySequence> reservedShortcuts = {
339
-
363
+ #if defined(Q_OS_MACOS)
364
+ Qt::CTRL + Qt::Key_Backspace,
365
+ Qt::Key_Escape,
366
+ #else
340
367
Qt::Key_Backspace,
341
368
Qt::Key_Escape,
369
+ #endif
342
370
};
343
371
344
372
if (hasError ()) {
0 commit comments