Skip to content

Commit ba61397

Browse files
添加误删除的代码
1 parent 8605162 commit ba61397

File tree

2 files changed

+38
-10
lines changed

2 files changed

+38
-10
lines changed

src/tools/toolfactory.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ CaptureTool* ToolFactory::CreateTool(CaptureTool::Type t, QObject* parent)
5050
if_TYPE_return_TOOL(TYPE_SAVE, SaveTool);
5151
if_TYPE_return_TOOL(TYPE_EXIT, ExitTool);
5252
if_TYPE_return_TOOL(TYPE_IMAGEUPLOADER, ImgUploaderTool);
53-
53+
if_TYPE_return_TOOL(TYPE_OPEN_APP, AppLauncher);
5454
if_TYPE_return_TOOL(TYPE_PIXELATE, PixelateTool);
5555
if_TYPE_return_TOOL(TYPE_REDO, RedoTool);
5656
if_TYPE_return_TOOL(TYPE_PIN, PinTool);

src/utils/confighandler.cpp

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include <algorithm>
1919
#include <stdexcept>
2020

21-
2221
// HELPER FUNCTIONS
2322

2423
bool verifyLaunchFile()
@@ -79,9 +78,8 @@ static QMap<class QString, QSharedPointer<ValueHandler>>
7978
OPTION("allowMultipleGuiInstances" ,Bool ( false )),
8079
OPTION("showMagnifier" ,Bool ( false )),
8180
OPTION("squareMagnifier" ,Bool ( false )),
82-
#if !defined(Q_OS_WIN)
81+
8382
OPTION("autoCloseIdleDaemon" ,Bool ( false )),
84-
#endif
8583
OPTION("startupLaunch" ,Bool ( false )),
8684
OPTION("showStartupLaunchMessage" ,Bool ( true )),
8785
OPTION("copyURLAfterUpload" ,Bool ( true )),
@@ -137,7 +135,7 @@ static QMap<QString, QSharedPointer<KeySequence>> recognizedShortcuts = {
137135
SHORTCUT("TYPE_ACCEPT" , "Return" ),
138136
SHORTCUT("TYPE_EXIT" , "Ctrl+Q" ),
139137
SHORTCUT("TYPE_IMAGEUPLOADER" , ),
140-
138+
SHORTCUT("TYPE_OPEN_APP" , "Ctrl+O" ),
141139
SHORTCUT("TYPE_PIXELATE" , "B" ),
142140
SHORTCUT("TYPE_INVERT" , "I" ),
143141
SHORTCUT("TYPE_REDO" , "Ctrl+Shift+Z" ),
@@ -159,7 +157,6 @@ static QMap<QString, QSharedPointer<KeySequence>> recognizedShortcuts = {
159157
SHORTCUT("TYPE_COMMIT_CURRENT_TOOL" , "Ctrl+Return" ),
160158

161159
SHORTCUT("TYPE_DELETE_CURRENT_TOOL" , "Delete" ),
162-
163160
SHORTCUT("TYPE_PIN" , ),
164161
SHORTCUT("TYPE_SELECTIONINDICATOR" , ),
165162
SHORTCUT("TYPE_SIZEINCREASE" , ),
@@ -229,8 +226,35 @@ void ConfigHandler::setStartupLaunch(const bool start)
229226
return;
230227
}
231228
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)
234258
QString path =
235259
QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) +
236260
"/autostart/";
@@ -250,7 +274,7 @@ void ConfigHandler::setStartupLaunch(const bool start)
250274
} else {
251275
file.remove();
252276
}
253-
#elif
277+
#elif defined(Q_OS_WIN)
254278
QSettings bootUpSettings(
255279
"HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
256280
QSettings::NativeFormat);
@@ -336,9 +360,13 @@ bool ConfigHandler::setShortcut(const QString& actionName,
336360
{
337361
qDebug() << actionName;
338362
static QVector<QKeySequence> reservedShortcuts = {
339-
363+
#if defined(Q_OS_MACOS)
364+
Qt::CTRL + Qt::Key_Backspace,
365+
Qt::Key_Escape,
366+
#else
340367
Qt::Key_Backspace,
341368
Qt::Key_Escape,
369+
#endif
342370
};
343371

344372
if (hasError()) {

0 commit comments

Comments
 (0)