FoxiGram/TMessagesProj/jni/tgnet/Timer.cpp
instant992 8e79f2ee9c FoxiGram: Telegram client with built-in Xray VLESS proxy
Based on Nekogram. Key additions:
- Rebrand to FoxiGram (app name, APK name, applicationId com.foxigram.app)
- Embedded Xray (VLESS+Reality) proxy client via JNI libxray.so
- Bundled hidden one-tap proxies (LTE + WiFi), read-only in UI
- Auto-restore proxy on restart, rebind to active network (LTE/WiFi)
- Server credentials externalized to git-ignored XrayServers.java (+ template)
- libxray Go source included; compiled .so, keystore, google-services.json ignored
2026-06-08 16:41:07 +04:00

62 lines
1.5 KiB
C++

/*
* This is the source code of tgnet library v. 1.1
* It is licensed under GNU GPL v. 2 or later.
* You should have received a copy of the license in this archive (see LICENSE).
*
* Copyright Nikolai Kudashov, 2015-2018.
*/
#include "Timer.h"
#include "FileLog.h"
#include "EventObject.h"
#include "ConnectionsManager.h"
Timer::Timer(int32_t instance, std::function<void()> function) {
eventObject = new EventObject(this, EventObjectTypeTimer);
instanceNum = instance;
callback = function;
}
Timer::~Timer() {
stop();
if (eventObject != nullptr) {
delete eventObject;
eventObject = nullptr;
}
}
void Timer::start() {
if (started || timeout == 0) {
return;
}
started = true;
ConnectionsManager::getInstance(instanceNum).scheduleEvent(eventObject, timeout);
}
void Timer::stop() {
if (!started) {
return;
}
started = false;
ConnectionsManager::getInstance(instanceNum).removeEvent(eventObject);
}
void Timer::setTimeout(uint32_t ms, bool repeat) {
if (ms == timeout) {
return;
}
repeatable = repeat;
timeout = ms;
if (started) {
ConnectionsManager::getInstance(instanceNum).removeEvent(eventObject);
ConnectionsManager::getInstance(instanceNum).scheduleEvent(eventObject, timeout);
}
}
void Timer::onEvent() {
callback();
if (LOGS_ENABLED) DEBUG_D("timer(%p) call", this);
if (started && repeatable && timeout != 0) {
ConnectionsManager::getInstance(instanceNum).scheduleEvent(eventObject, timeout);
}
}