Skip to content
This repository was archived by the owner on Aug 18, 2021. It is now read-only.

Commit 85f864d

Browse files
Qv2ray-devQv2ray-dev
authored andcommitted
add: added start detached option
1 parent f2e02d4 commit 85f864d

File tree

2 files changed

+44
-10
lines changed

2 files changed

+44
-10
lines changed

core/EventHandler.cpp

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,19 @@ QvPlugin_EventHandler(SimpleEventHandler, Connectivity)
4949
{
5050
_command.replace("$$INBOUND_" + protocol, QString::number(pluginEvent.inboundPorts[protocol]));
5151
}
52-
auto returnvalue = QProcess::execute(_command);
53-
if (returnvalue != 0)
52+
bool detached = _command.contains("$$CALL");
53+
_command.replace("$$CALL", "");
54+
if (detached)
5455
{
55-
CommandPlugin::instance->PluginLog("Failed to execute command : \"" + action + "\"");
56+
auto returnvalue = QProcess::execute(_command);
57+
if (returnvalue != 0)
58+
{
59+
CommandPlugin::instance->PluginLog("Failed to execute command : \"" + action + "\"");
60+
}
61+
}
62+
else
63+
{
64+
QProcess::startDetached(_command);
5665
}
5766
}
5867
}
@@ -83,10 +92,19 @@ QvPlugin_EventHandler(SimpleEventHandler, SystemProxy)
8392
auto _command = action;
8493
_command.replace("$$HTTP", QString::number(pluginEvent.systemProxyPortSettings[Events::SystemProxy::SystemProxy_HTTP]));
8594
_command.replace("$$SOCKS", QString::number(pluginEvent.systemProxyPortSettings[Events::SystemProxy::SystemProxy_SOCKS]));
86-
auto returnvalue = QProcess::execute(_command);
87-
if (returnvalue != 0)
95+
bool detached = _command.contains("$$CALL");
96+
_command.replace("$$CALL", "");
97+
if (detached)
98+
{
99+
auto returnvalue = QProcess::execute(_command);
100+
if (returnvalue != 0)
101+
{
102+
CommandPlugin::instance->PluginLog("Failed to execute command : \"" + action + "\"");
103+
}
104+
}
105+
else
88106
{
89-
CommandPlugin::instance->PluginLog("Failed to execute command : \"" + action + "\"");
107+
QProcess::startDetached(_command);
90108
}
91109
}
92110
}
@@ -127,10 +145,19 @@ QvPlugin_EventHandler(SimpleEventHandler, ConnectionEntry)
127145
auto _command = action;
128146
_command.replace("$$DISPLAYNAME", pluginEvent.displayName);
129147
_command.replace("$$ORIGINAL_NAME", pluginEvent.originalDisplayName);
130-
auto returnvalue = QProcess::execute(_command);
131-
if (returnvalue != 0)
148+
bool detached = _command.contains("$$CALL");
149+
_command.replace("$$CALL", "");
150+
if (detached)
151+
{
152+
auto returnvalue = QProcess::execute(_command);
153+
if (returnvalue != 0)
154+
{
155+
CommandPlugin::instance->PluginLog("Failed to execute command : \"" + action + "\"");
156+
}
157+
}
158+
else
132159
{
133-
CommandPlugin::instance->PluginLog("Failed to execute command : \"" + action + "\"");
160+
QProcess::startDetached(_command);
134161
}
135162
}
136163
}

ui/CommandPluginSettings.ui

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<string>Form</string>
1515
</property>
1616
<layout class="QGridLayout" name="gridLayout_4">
17-
<item row="0" column="0">
17+
<item row="1" column="0">
1818
<widget class="QTabWidget" name="tabWidget">
1919
<property name="currentIndex">
2020
<number>0</number>
@@ -201,6 +201,13 @@ $$SOCKS: SOCKS port (could be 0)</string>
201201
</widget>
202202
</widget>
203203
</item>
204+
<item row="0" column="0">
205+
<widget class="QLabel" name="label_14">
206+
<property name="text">
207+
<string>Commands start with &quot;$$CALL&quot; will make program start detached.</string>
208+
</property>
209+
</widget>
210+
</item>
204211
</layout>
205212
</widget>
206213
<resources/>

0 commit comments

Comments
 (0)