Skip to content

Commit

Permalink
fix bug #117
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonwang committed Dec 19, 2023
1 parent ab0ab88 commit dc89244
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 36 deletions.
13 changes: 11 additions & 2 deletions src/Launchy/PluginHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,19 @@ void PluginHandler::getCatalogs(Catalog* pCatalog, INotifyProgressStep* progress
}

int PluginHandler::launchItem(QList<InputData>* inputData, CatItem* result) {
if (!m_plugins.contains(result->pluginName) || !m_plugins[result->pluginName].loaded) {
assert(inputData);
assert(result);

auto it = m_plugins.find(result->pluginName);
if (it == m_plugins.end()) {
return MSG_CONTROL_LAUNCHITEM;
}
return m_plugins[result->pluginName].sendMsg(MSG_LAUNCH_ITEM, inputData, result);

if (!it->loaded) {
return MSG_CONTROL_LAUNCHITEM;
}

return it->sendMsg(MSG_LAUNCH_ITEM, inputData, result);
}

QWidget* PluginHandler::doDialog(QWidget* parent, const QString& name) {
Expand Down
2 changes: 1 addition & 1 deletion src/LaunchyLib/InputData.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class LAUNCHY_EXPORT InputData {
/** Set the text of the query segment */
void setText(const QString& t);

/** Get the text of the query segment */
/** Check if the text is empty */
bool hasText() const;

/** Get a pointer to the best catalog match for this segment of the query */
Expand Down
9 changes: 6 additions & 3 deletions src/LaunchyLib/PluginInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QDebug>

#include "PluginInterface.h"
#include "PluginMsg.h"

namespace launchy {

Expand All @@ -38,20 +39,22 @@ bool PluginInfo::isValid() const {
return obj && !name.isEmpty();
}

bool PluginInfo::sendMsg(int msgId, void* wParam, void* lParam) {
int PluginInfo::sendMsg(int msgId, void* wParam, void* lParam) {
// This should have some kind of exception guard to prevent
// Launchy from crashing when a plugin is misbehaving.
// This would consist of a try/catch block to handle C++ exceptions
// and on Windows would also include a structured exception handler

int ret = 0;
int ret = MSG_CONTROL_LAUNCHITEM;

try {
ret = obj->msg(msgId, wParam, lParam);
}
catch (const std::exception& e) {
qWarning() << "PluginInfo::sendMsg, exception catched:" << e.what();
}
return ret != 0;

return ret;
}

} // namespace launchy
2 changes: 1 addition & 1 deletion src/LaunchyLib/PluginInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct LAUNCHY_EXPORT PluginInfo {
public:
bool isValid() const;

bool sendMsg(int msgId, void* wParam = nullptr, void* lParam = nullptr);
int sendMsg(int msgId, void* wParam = nullptr, void* lParam = nullptr);
};

} // namespace launchy
56 changes: 27 additions & 29 deletions src/Plugins/Verby/Verby.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,27 +172,7 @@ int Verby::launchItem(QList<InputData>* inputData, CatItem* item) {
QString verb = verbItem.shortName;

qDebug() << "verby::launchItem:" << noun << verb;
if (verb == "Run") {
runProgram(noun, "");
}
else if (verb == "Open containing folder") {
QFileInfo info(noun);
if (info.isSymLink()) {
info.setFile(info.symLinkTarget());
}

#ifdef Q_OS_WIN
runProgram("explorer.exe", "\"" + QDir::toNativeSeparators(info.absolutePath()) + "\"");
#endif
}
else if (verb == "Open shortcut folder") {
QFileInfo info(noun);

#ifdef Q_OS_WIN
runProgram("explorer.exe", "\"" + QDir::toNativeSeparators(info.absolutePath()) + "\"");
#endif
}
else if (verb == "Run as admin") {
if (verb == "Run as admin") {
#ifdef Q_OS_WIN
SHELLEXECUTEINFOW shellExecInfo;

Expand All @@ -215,6 +195,31 @@ int Verby::launchItem(QList<InputData>* inputData, CatItem* item) {
ShellExecuteExW(&shellExecInfo);
#endif
}
else if (verb == "Open containing folder") {
QFileInfo info(noun);
if (info.isSymLink()) {
info.setFile(info.symLinkTarget());
}

#ifdef Q_OS_WIN
runProgram("explorer.exe", "\"" + QDir::toNativeSeparators(info.absolutePath()) + "\"");
#endif
}
else if (verb == "Open shortcut folder") {
QFileInfo info(noun);

#ifdef Q_OS_WIN
runProgram("explorer.exe", "\"" + QDir::toNativeSeparators(info.absolutePath()) + "\"");
#endif
}
else if (verb == "Copy path to clipboard") {
QFileInfo info(noun);
if (info.isSymLink()) {
info.setFile(info.symLinkTarget());
}
QClipboard* clipboard = QApplication::clipboard();
clipboard->setText(QDir::toNativeSeparators(info.canonicalFilePath()));
}
else if (verb == "File properties") {
#ifdef Q_OS_WIN
SHELLEXECUTEINFOW shellExecInfo;
Expand All @@ -234,16 +239,9 @@ int Verby::launchItem(QList<InputData>* inputData, CatItem* item) {
ShellExecuteExW(&shellExecInfo);
#endif
}
else if (verb == "Copy path to clipboard") {
QFileInfo info(noun);
if (info.isSymLink()) {
info.setFile(info.symLinkTarget());
}
QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(QDir::toNativeSeparators(info.canonicalFilePath()));
}
else {
// Tell Launchy to handle the command
qDebug() << "verby::launchItem, launchy should handle the item";
return MSG_CONTROL_LAUNCHITEM;
}

Expand Down

0 comments on commit dc89244

Please sign in to comment.