Merge pull request #89 from majestrate/implement-hide-to-tray-2020-11-25
hide to tray
This commit is contained in:
commit
1f8ec6f133
|
@ -1 +1 @@
|
|||
Subproject commit e7487fd0c8ee843b3a3df16563ee42dad2fde050
|
||||
Subproject commit 53481cdfa9b0dc8d6dbbf04803401298754d7f44
|
|
@ -262,12 +262,16 @@ ColumnLayout {
|
|||
pathRatio = Math.ceil(ratio * 100) + "%";
|
||||
if(exitBusy)
|
||||
return;
|
||||
if(exit.exitSetByDaemon)
|
||||
return;
|
||||
if (lokiExit !== newLokiExit)
|
||||
{
|
||||
if(newLokiExit.length > 0)
|
||||
{
|
||||
lokiExit = newLokiExit;
|
||||
exitStatus = "Exit Obtained";
|
||||
exit.exitSetByDaemon = true;
|
||||
exit.hasExit = true;
|
||||
}
|
||||
}
|
||||
// set auth code
|
||||
|
|
|
@ -11,6 +11,8 @@ Container {
|
|||
property var status: ""
|
||||
property var busy: false
|
||||
property var hasExit: false
|
||||
property var exitSetByDaemon: false
|
||||
|
||||
Layout.preferredHeight: 167
|
||||
Layout.preferredWidth: Style.appWidth
|
||||
|
||||
|
@ -90,9 +92,9 @@ Container {
|
|||
Switch {
|
||||
id: exitButton
|
||||
// palette.dark: Style.lokiDarkGreen;
|
||||
text: address.length > 0 ? "Exit On" : "Exit off"
|
||||
checkable: true
|
||||
checked: address.length > 0
|
||||
text: hasExit > 0 ? "Exit On" : "Exit off"
|
||||
checkable: !busy
|
||||
checked: hasExit
|
||||
background: Rectangle{
|
||||
color: Style.panelBackgroundColor
|
||||
opacity: exitButton.checked ? 1 : 0.3
|
||||
|
@ -125,19 +127,16 @@ Container {
|
|||
}
|
||||
var exitAddr = exitTextInput.text;
|
||||
var exitAuth = authTextInput.text;
|
||||
if(hasExit)
|
||||
console.log("hasExit="+hasExit+" checked="+checked);
|
||||
if(hasExit || !checked)
|
||||
{
|
||||
busy = true;
|
||||
console.log("remove exit");
|
||||
apiClient.llarpDelExit(function(result, error) {
|
||||
status = "Exit Off";
|
||||
busy = false;
|
||||
exitButton.text = "Enable Exit";
|
||||
stautsLabelText.color = Style.weakTextColor;
|
||||
console.log(hasExit, " has exit?");
|
||||
checked = false;
|
||||
});
|
||||
apiClient.llarpDelExit(function(result, error) { });
|
||||
statusLabelText.text = "Exit Off";
|
||||
exitButton.text = "Enable Exit";
|
||||
statusLabelText.color = Style.weakTextColor;
|
||||
hasExit = false;
|
||||
checked = false;
|
||||
return;
|
||||
}
|
||||
statusLabelText.color = Style.weakTextColor;
|
||||
|
@ -150,6 +149,7 @@ Container {
|
|||
status = "Error: " +error;
|
||||
statusLabelText.color = Style.errorRed;
|
||||
checked = false;
|
||||
hasExit = false;
|
||||
return;
|
||||
}
|
||||
var j = JSON.parse(result);
|
||||
|
@ -157,6 +157,7 @@ Container {
|
|||
{
|
||||
status = "Error: " + j.error;
|
||||
checked = false;
|
||||
hasExit = false;
|
||||
statusLabelText.color = Style.errorRed;
|
||||
return;
|
||||
}
|
||||
|
@ -164,6 +165,8 @@ Container {
|
|||
{
|
||||
console.log("exit result: ",j.result);
|
||||
statusLabelText.color = Style.weakTextColor;
|
||||
statusLabelText.text = "Exit enabled";
|
||||
exitButton.text = "Disable Exit";
|
||||
hasExit = true;
|
||||
if(exitAuth.length > 0)
|
||||
{
|
||||
|
|
|
@ -11,7 +11,7 @@ import "."
|
|||
ApplicationWindow {
|
||||
id: window
|
||||
title: qsTr("Lokinet Control Panel")
|
||||
visible: nohide
|
||||
visible: true
|
||||
flags: nohide ? Qt.Window : Qt.FramelessWindowHint
|
||||
maximumHeight: minimumHeight
|
||||
maximumWidth: minimumWidth
|
||||
|
@ -27,12 +27,15 @@ ApplicationWindow {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
onClosing: {
|
||||
if (notray) {
|
||||
window.exitApp();
|
||||
}
|
||||
if(platformDetails.isLinux())
|
||||
{
|
||||
window.exitApp();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
ControlPanel {
|
||||
id: controlPanel
|
||||
}
|
||||
|
@ -49,8 +52,7 @@ ApplicationWindow {
|
|||
Qt.quit();
|
||||
}
|
||||
|
||||
function display() {
|
||||
|
||||
function openSysTray() {
|
||||
var rect = platformDetails.getAbsoluteCursorPosition();
|
||||
console.log("mouse cursor at: "+ rect.x +", "+ rect.y);
|
||||
|
||||
|
@ -80,11 +82,12 @@ ApplicationWindow {
|
|||
var winX = (right ? (rect.x - window.width) : rect.x);
|
||||
var winY = (bottom ? (rect.y - window.height) : rect.y);
|
||||
|
||||
window.x = winX;
|
||||
window.y = winY;
|
||||
|
||||
console.log("updated window popup position: "+ window.x + ", "+ window.y);
|
||||
|
||||
// systrayMenu.x = winX;
|
||||
// systrayMenu.y = winY;
|
||||
systrayMenu.visible = true;
|
||||
}
|
||||
|
||||
function display() {
|
||||
window.show();
|
||||
window.raise();
|
||||
window.requestActivate();
|
||||
|
@ -94,12 +97,12 @@ ApplicationWindow {
|
|||
SystemTrayIcon {
|
||||
id: systray
|
||||
tooltip: qsTr("Loki Network")
|
||||
visible: !notray
|
||||
visible: platformDetails.hasSysTray();
|
||||
iconSource: "qrc:/res/images/icon.svg"
|
||||
|
||||
menu: Menu {
|
||||
id: systrayMenu
|
||||
enabled: true
|
||||
enabled: platformDetails.hasSysTray();
|
||||
|
||||
MenuItem {
|
||||
text: qsTr("Show")
|
||||
|
@ -109,7 +112,7 @@ ApplicationWindow {
|
|||
}
|
||||
MenuItem {
|
||||
text: qsTr("Hide")
|
||||
visible: (platformDetails.isDebug() || platformDetails.isLinux())
|
||||
// visible: (platformDetails.isDebug() || platformDetails.isLinux())
|
||||
onTriggered: {
|
||||
window.visible = false;
|
||||
}
|
||||
|
@ -161,11 +164,12 @@ ApplicationWindow {
|
|||
|
||||
// right click
|
||||
case SystemTrayIcon.Context:
|
||||
systrayMenu.open();
|
||||
window.openSysTray();
|
||||
break;
|
||||
|
||||
// left click
|
||||
case SystemTrayIcon.Trigger:
|
||||
window.display();
|
||||
break;
|
||||
case SystemTrayIcon.DoubleClick:
|
||||
|
||||
// Qt on MacOS only gives us one event to work with, namely
|
||||
|
|
|
@ -26,6 +26,39 @@ Q_INVOKABLE bool PlatformDetails::isLinux() {
|
|||
#endif
|
||||
}
|
||||
|
||||
// PlatformDetails::hasSysTray
|
||||
Q_INVOKABLE bool PlatformDetails::hasSysTray() {
|
||||
if(isWindows())
|
||||
return true;
|
||||
if(isMacOS())
|
||||
return true;
|
||||
if(isGayland())
|
||||
{
|
||||
// pretty much every sane environment has a systray but not gayland (GNOME WAYLAND) because $reasons.
|
||||
return false;
|
||||
}
|
||||
if(isLinux())
|
||||
return true;
|
||||
// we don't know what we are runnning on let's assume we dont have a tray
|
||||
return false;
|
||||
}
|
||||
|
||||
// PlatformDetails::isGayland
|
||||
Q_INVOKABLE bool PlatformDetails::isGayland() {
|
||||
#if defined(Q_OS_LINUX)
|
||||
if(const auto wayland = ::getenv("WAYLAND_DISPLAY"); wayland)
|
||||
{
|
||||
if(const auto desktop = ::getenv("XDG_CURRENT_DESKTOP"); desktop)
|
||||
{
|
||||
return std::string{desktop} == "GNOME";
|
||||
}
|
||||
}
|
||||
return false;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
// PlatformDetails::isMacOS
|
||||
Q_INVOKABLE bool PlatformDetails::isMacOS() {
|
||||
#if defined(Q_OS_MACOS)
|
||||
|
|
|
@ -16,9 +16,16 @@ class PlatformDetails : public QObject
|
|||
|
||||
public:
|
||||
|
||||
/// return if we are on windows
|
||||
Q_INVOKABLE static bool isWindows();
|
||||
/// return if we are on linux
|
||||
Q_INVOKABLE static bool isLinux();
|
||||
/// return if we are on gnome wayland
|
||||
Q_INVOKABLE static bool isGayland();
|
||||
/// return if we are on macos
|
||||
Q_INVOKABLE static bool isMacOS();
|
||||
/// return if we have a system tray or not
|
||||
Q_INVOKABLE static bool hasSysTray();
|
||||
|
||||
Q_INVOKABLE static bool isDebug();
|
||||
|
||||
|
|
|
@ -30,11 +30,11 @@ int32_t main(int32_t argc, char *argv[])
|
|||
qDebug() << "Run-time Qt Version:" << qVersion();
|
||||
|
||||
// crude CLI option parsing
|
||||
bool nohide = false;
|
||||
bool nohide = true;
|
||||
bool notray = true;
|
||||
for (int i=0; argv[i] != nullptr; ++i) {
|
||||
std::string arg = argv[i];
|
||||
if (arg == "--nohide" || arg == "--no-hide") nohide = true;
|
||||
if (arg == "--hide") nohide = false;
|
||||
if (arg == "--tray") notray = false;
|
||||
if (arg == "--rpc" and argv[i+1] != nullptr)
|
||||
{
|
||||
|
@ -42,10 +42,6 @@ int32_t main(int32_t argc, char *argv[])
|
|||
}
|
||||
}
|
||||
|
||||
// notray implies nohide
|
||||
if (notray)
|
||||
nohide = true;
|
||||
|
||||
qDebug() << "nohide: " << (nohide ? "T":"F");
|
||||
qDebug() << "notray: " << (notray ? "T":"F");
|
||||
qRegisterMetaType<QJSValueList>("QJSValueList");
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
#include <sstream>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
#include <future>
|
||||
|
||||
using namespace std::literals::chrono_literals;
|
||||
|
||||
constexpr auto MANAGED_KILL_WAIT = 5s;
|
||||
|
@ -81,8 +82,11 @@ bool LokinetProcessManager::stopLokinetProcess()
|
|||
|
||||
bool LokinetProcessManager::doStopLokinetProcess()
|
||||
{
|
||||
bool success = m_apiClient.llarpAdminDie([](auto) {
|
||||
std::promise<void> waiter;
|
||||
const auto success = m_apiClient.llarpAdminDie([&waiter](auto) {
|
||||
waiter.set_value();
|
||||
});
|
||||
waiter.get_future().get();
|
||||
if (!success)
|
||||
{
|
||||
qDebug("Failed to stop lokinet process with llarp.admin.die API call");
|
||||
|
|
Loading…
Reference in New Issue