Skip to content

Commit

Permalink
Fix Xray status update mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
aiamnezia committed Feb 26, 2025
1 parent 7f28f2e commit 554761a
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
5 changes: 1 addition & 4 deletions proxyserver/src/proxyserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ ProxyServer::ProxyServer(QObject *parent)
connect(&m_trayIcon, &TrayIcon::quitRequested, this, &ProxyServer::quit);
connect(&m_trayIcon, &TrayIcon::configSelected, this, &ProxyServer::onConfigSelected);
connect(m_service.data(), &ProxyService::configsChanged, this, &ProxyServer::updateTrayConfigsMenu);
connect(m_service.data(), &ProxyService::xrayStatusChanged, &m_trayIcon, &TrayIcon::updateStatus);
}

ProxyServer::~ProxyServer()
Expand Down Expand Up @@ -55,16 +56,12 @@ void ProxyServer::stop()
bool ProxyServer::startXrayProcess()
{
bool success = m_service->startXray();
if (success) {
m_trayIcon.updateStatus(true);
}
return success;
}

void ProxyServer::stopXrayProcess()
{
m_service->stopXray();
m_trayIcon.updateStatus(false);
}

void ProxyServer::quit()
Expand Down
2 changes: 2 additions & 0 deletions proxyserver/src/proxyservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ bool ProxyService::startXray()
bool success = m_xrayController->start(m_configManager->getActiveConfigPath());
if (success) {
Logger::getInstance().info("Xray started successfully");
emit xrayStatusChanged(true);
} else {
Logger::getInstance().error("Failed to start Xray");
}
Expand All @@ -45,6 +46,7 @@ bool ProxyService::stopXray()
Logger::getInstance().info("Stopping Xray");
m_xrayController->stop();
Logger::getInstance().info("Xray stopped");
emit xrayStatusChanged(false);
return true;
}

Expand Down
1 change: 1 addition & 0 deletions proxyserver/src/proxyservice.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class ProxyService : public QObject, public IProxyService {

signals:
void configsChanged();
void xrayStatusChanged(bool running);

private:
QScopedPointer<ConfigManager> m_configManager;
Expand Down
4 changes: 3 additions & 1 deletion proxyserver/src/trayicon.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ class TrayIcon : public QObject
explicit TrayIcon(QObject *parent = nullptr);
~TrayIcon() = default;

void updateStatus(bool isActive);
void updateConfigsMenu(const QMap<QString, QJsonObject>& configs, const QString& activeConfigUuid);
void updatePorts(quint16 proxyPort, quint16 httpPort);
void updateError(const QString &errorMessage);

public slots:
void updateStatus(bool isActive);

signals:
void quitRequested();
void configSelected(const QString& uuid);
Expand Down

0 comments on commit 554761a

Please sign in to comment.