Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Network
KDE Connect
Commits
06d81412
Commit
06d81412
authored
Oct 23, 2020
by
Piyush Aggarwal
🎮
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reliably kill dbus-daemon and kdeconnect-daemon using WinAPIs
parent
28b7ad0a
Pipeline
#39109
passed with stage
in 5 minutes and 55 seconds
Changes
3
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
99 additions
and
4 deletions
+99
-4
indicator/indicatorhelper.h
indicator/indicatorhelper.h
+18
-0
indicator/indicatorhelper_win.cpp
indicator/indicatorhelper_win.cpp
+70
-1
indicator/main.cpp
indicator/main.cpp
+11
-3
No files found.
indicator/indicatorhelper.h
View file @
06d81412
...
...
@@ -16,6 +16,14 @@
#include <KStatusNotifierItem>
#endif
#ifdef Q_OS_WIN
#include <QUrl>
namespace
processes
{
const
QString
dbus_daemon
=
QStringLiteral
(
"dbus-daemon.exe"
);
const
QString
kdeconnect_daemon
=
QStringLiteral
(
"kdeconnectd.exe"
);
};
#endif
class
IndicatorHelper
{
public:
...
...
@@ -35,6 +43,16 @@ public:
void
systrayIconHook
(
KStatusNotifierItem
&
systray
);
#endif
#ifdef Q_OS_WIN
/**
* Terminate processes of KDE Connect like kdeconnectd.exe and dbus-daemon.exe
*
* @return True if termination was successful, false otherwise
*/
bool
terminateProcess
(
const
QString
&
processName
,
const
QUrl
&
indicatorUrl
)
const
;
#endif
private:
#ifdef Q_OS_MAC
QSplashScreen
*
m_splashScreen
;
...
...
indicator/indicatorhelper_win.cpp
View file @
06d81412
...
...
@@ -7,8 +7,15 @@
#include <QFile>
#include <QIcon>
#include <QStandardPaths>
#include <QDebug>
#include <iostream>
#include <Windows.h>
#include <tlhelp32.h>
#include "indicatorhelper.h"
#include "indicator_debug.h"
IndicatorHelper
::
IndicatorHelper
()
{}
IndicatorHelper
::~
IndicatorHelper
()
{}
...
...
@@ -21,7 +28,7 @@ void IndicatorHelper::iconPathHook() {}
int
IndicatorHelper
::
daemonHook
(
QProcess
&
kdeconnectd
)
{
kdeconnectd
.
start
(
QStringLiteral
(
"
kdeconnect
d.exe"
)
);
kdeconnectd
.
start
(
processes
::
kdeconnect
_daemon
);
return
0
;
}
...
...
@@ -36,3 +43,65 @@ void IndicatorHelper::systrayIconHook(KStatusNotifierItem &systray)
Q_UNUSED
(
systray
);
}
#endif
bool
IndicatorHelper
::
terminateProcess
(
const
QString
&
processName
,
const
QUrl
&
indicatorUrl
)
const
{
HANDLE
hProcessSnap
;
HANDLE
hProcess
;
hProcessSnap
=
CreateToolhelp32Snapshot
(
TH32CS_SNAPPROCESS
,
0
);
if
(
hProcessSnap
==
INVALID_HANDLE_VALUE
)
{
qCWarning
(
KDECONNECT_INDICATOR
)
<<
"Failed to get snapshot of processes."
;
return
FALSE
;
}
PROCESSENTRY32
pe32
;
pe32
.
dwSize
=
sizeof
(
PROCESSENTRY32
);
if
(
!
Process32First
(
hProcessSnap
,
&
pe32
))
{
qCWarning
(
KDECONNECT_INDICATOR
)
<<
"Failed to get handle for the first process."
;
CloseHandle
(
hProcessSnap
);
return
FALSE
;
}
do
{
if
(
QString
::
fromWCharArray
(
pe32
.
szExeFile
)
==
processName
)
{
hProcess
=
OpenProcess
(
PROCESS_ALL_ACCESS
,
FALSE
,
pe32
.
th32ProcessID
);
if
(
hProcess
==
NULL
)
{
qCWarning
(
KDECONNECT_INDICATOR
)
<<
"Failed to get handle for the process:"
<<
processName
;
return
FALSE
;
}
else
{
const
DWORD
processPathSize
=
4096
;
CHAR
processPathString
[
processPathSize
];
BOOL
gotProcessPath
=
QueryFullProcessImageNameA
(
hProcess
,
0
,
(
LPSTR
)
processPathString
,
(
PDWORD
)
&
processPathSize
);
if
(
gotProcessPath
)
{
const
QUrl
processUrl
=
QUrl
::
fromLocalFile
(
QString
::
fromStdString
(
processPathString
));
// to replace \\ with /
if
(
indicatorUrl
.
isParentOf
(
processUrl
))
{
BOOL
terminateSuccess
=
TerminateProcess
(
hProcess
,
0
);
if
(
!
terminateSuccess
)
{
qCWarning
(
KDECONNECT_INDICATOR
)
<<
"Failed to terminate process:"
<<
processName
;
return
FALSE
;
}
}
}
}
}
}
while
(
Process32Next
(
hProcessSnap
,
&
pe32
));
CloseHandle
(
hProcessSnap
);
return
TRUE
;
}
indicator/main.cpp
View file @
06d81412
...
...
@@ -56,7 +56,7 @@ int main(int argc, char** argv)
QMenu
*
menu
=
new
QMenu
;
DaemonDbusInterface
iface
;
auto
refreshMenu
=
[
&
iface
,
&
model
,
&
menu
]()
{
auto
refreshMenu
=
[
&
iface
,
&
model
,
&
menu
,
&
helper
]()
{
menu
->
clear
();
auto
configure
=
menu
->
addAction
(
QIcon
::
fromTheme
(
QStringLiteral
(
"configure"
)),
i18n
(
"Configure..."
));
QObject
::
connect
(
configure
,
&
QAction
::
triggered
,
configure
,
[](){
...
...
@@ -83,9 +83,9 @@ int main(int argc, char** argv)
pairMenu
->
addAction
(
i18n
(
"Reject"
),
dev
,
&
DeviceDbusInterface
::
rejectPairing
);
}
}
#if (defined Q_OS_MAC || defined Q_OS_WIN)
// Add quit menu
#if defined Q_OS_MAC
menu
->
addAction
(
i18n
(
"Quit"
),
[](){
auto
message
=
QDBusMessage
::
createMethodCall
(
QStringLiteral
(
"org.kde.kdeconnect.daemon"
),
QStringLiteral
(
"/MainApplication"
),
...
...
@@ -98,6 +98,14 @@ int main(int argc, char** argv)
QStringLiteral
(
"quit"
));
DBusHelper
::
sessionBus
().
call
(
message
,
QDBus
::
NoBlock
);
// Close our indicator
});
#elif defined Q_OS_WIN
menu
->
addAction
(
i18n
(
"Quit"
),
[
&
helper
](){
const
QUrl
indicatorUrl
=
QUrl
::
fromLocalFile
(
qApp
->
applicationDirPath
());
helper
.
terminateProcess
(
processes
::
dbus_daemon
,
indicatorUrl
);
helper
.
terminateProcess
(
processes
::
kdeconnect_daemon
,
indicatorUrl
);
qApp
->
quit
();
});
#endif
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment