本地展示load和show
This commit is contained in:
parent
d0495f3a18
commit
437cdc5b1b
@ -6,5 +6,5 @@ Author: XYZShell
|
||||
Section: Utilities
|
||||
Tag: role::developer
|
||||
Architecture: iphoneos-arm
|
||||
Version: 0.0.7-10-79+debug
|
||||
Version: 0.0.7-10-80+debug
|
||||
Installed-Size: 1696
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@ -1 +1 @@
|
||||
./packages/com.xyzshell.ioscontrol_0.0.7-10-79+debug_iphoneos-arm.deb
|
||||
./packages/com.xyzshell.ioscontrol_0.0.7-10-80+debug_iphoneos-arm.deb
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
@ -1 +1 @@
|
||||
79
|
||||
80
|
||||
@ -16,6 +16,8 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface FloatingWindow () {
|
||||
NSMutableArray *loadTimestamps;
|
||||
NSMutableArray *showTimestamps;
|
||||
}
|
||||
|
||||
@end
|
||||
@ -46,6 +48,10 @@
|
||||
[self updateInfo];
|
||||
self.http = [[XSHttpHelper alloc] init];
|
||||
[[MyEventBus sharedInstance] registerSubscriber:self];
|
||||
|
||||
loadTimestamps = [[NSMutableArray alloc] init];
|
||||
showTimestamps = [[NSMutableArray alloc] init];
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@ -54,6 +60,79 @@
|
||||
[[MyEventBus sharedInstance] unregisterSubscriber:self];
|
||||
}
|
||||
|
||||
// 添加清理过期数据的辅助方法
|
||||
- (void)cleanExpiredTimestamps:(NSMutableArray *)timestamps {
|
||||
NSDate *now = [NSDate date];
|
||||
NSTimeInterval oneHourAgo = [now timeIntervalSince1970] - 3600; // 3600秒 = 1小时
|
||||
|
||||
NSPredicate *predicate = [NSPredicate predicateWithBlock:^BOOL(NSDate *timestamp, NSDictionary *bindings) {
|
||||
return [timestamp timeIntervalSince1970] > oneHourAgo;
|
||||
}];
|
||||
|
||||
NSArray *validTimestamps = [timestamps filteredArrayUsingPredicate:predicate];
|
||||
[timestamps removeAllObjects];
|
||||
[timestamps addObjectsFromArray:validTimestamps];
|
||||
}
|
||||
// 更新背景颜色
|
||||
- (void)updateBackgroundColorByShowCount:(NSInteger)showCount {
|
||||
UIColor *color;
|
||||
|
||||
if (showCount < 80) {
|
||||
// 蓝色 #07A6E4
|
||||
color = [UIColor colorWithRed:7/255.0 green:166/255.0 blue:228/255.0 alpha:1.0];
|
||||
} else if (showCount < 160) {
|
||||
// 红色 #D92727
|
||||
color = [UIColor colorWithRed:217/255.0 green:39/255.0 blue:39/255.0 alpha:1.0];
|
||||
} else if (showCount < 240) {
|
||||
// 橙黄 #EF811C
|
||||
color = [UIColor colorWithRed:239/255.0 green:129/255.0 blue:28/255.0 alpha:1.0];
|
||||
} else {
|
||||
// 绿色 #08C951
|
||||
color = [UIColor colorWithRed:8/255.0 green:201/255.0 blue:81/255.0 alpha:1.0];
|
||||
}
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self.backgroundColor = color;
|
||||
});
|
||||
}
|
||||
|
||||
// 添加 onEventLoad 方法
|
||||
- (void)onEventLoad:(id)data {
|
||||
@synchronized(loadTimestamps) {
|
||||
[loadTimestamps addObject:[NSDate date]];
|
||||
[self cleanExpiredTimestamps:loadTimestamps];
|
||||
|
||||
NSInteger loadCount = loadTimestamps.count;
|
||||
NSInteger showCount = showTimestamps.count;
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self.infoLabel.text = [NSString stringWithFormat:@"S:%@ / L:%@", @(showCount), @(loadCount)];
|
||||
});
|
||||
|
||||
NSLog(@"Load event: total in last hour = %ld", (long)loadCount);
|
||||
}
|
||||
}
|
||||
|
||||
// 添加 onEventShow 方法
|
||||
- (void)onEventShow:(id)data {
|
||||
@synchronized(showTimestamps) {
|
||||
[showTimestamps addObject:[NSDate date]];
|
||||
[self cleanExpiredTimestamps:showTimestamps];
|
||||
|
||||
NSInteger showCount = showTimestamps.count;
|
||||
NSInteger loadCount = loadTimestamps.count;
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self.infoLabel.text = [NSString stringWithFormat:@"S:%@ / L:%@", @(showCount), @(loadCount)];
|
||||
});
|
||||
|
||||
// 根据 show 数量更新背景颜色
|
||||
[self updateBackgroundColorByShowCount:showCount];
|
||||
|
||||
NSLog(@"Show event: total in last hour = %ld", (long)showCount);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setupUI {
|
||||
// Name Label
|
||||
self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 180, 18)];
|
||||
|
||||
@ -158,7 +158,7 @@
|
||||
self.ip = [[XSPhoneInfo sharedInstance] IPAddress];
|
||||
self.remoteIp = [[XSPhoneInfo sharedInstance] remoteIp];
|
||||
self.diskSize = [[XSPhoneInfo sharedInstance] IPhoneStatus];
|
||||
self.message = @"251114-nt-newapi";
|
||||
self.message = @"251118-nt-newapi";
|
||||
// 构建请求数据
|
||||
NSDictionary *heartbeatData = [self constructHeartbeatData];
|
||||
if (!heartbeatData) {
|
||||
@ -203,7 +203,7 @@
|
||||
NSLog(@"Heartbeat success: %@", json);
|
||||
NSDictionary *dic = [XSHelper json2Dictionary:json];
|
||||
NSDictionary *json_data = dic[@"data"];
|
||||
[[MyEventBus sharedInstance] postEvent:@"UpdateInfo" withObject:json_data];
|
||||
// [[MyEventBus sharedInstance] postEvent:@"UpdateInfo" withObject:json_data];
|
||||
} else {
|
||||
NSLog(@"Empty heartbeat response");
|
||||
}
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
#import "XSHelper.h"
|
||||
#import "XSHackIos.h"
|
||||
#import "MyAdTask2.h"
|
||||
#import "MyEventBus.h"
|
||||
|
||||
#import "UDPHandler.h"
|
||||
|
||||
@ -68,10 +69,12 @@
|
||||
return [XSHelper dic2Json:resData];
|
||||
}
|
||||
else if([XSHelper isMatch:@"^/adtask/show" test:path]) {
|
||||
MyAdTask2Mangger *ad = [MyAdTask2Mangger sharedInstance];
|
||||
NSDictionary *rq = dic[@"body"];
|
||||
int close = [ad onShow:rq];
|
||||
[resData setValue:@(close) forKey:@"close"];
|
||||
|
||||
[[MyEventBus sharedInstance] postEvent:@"Show" withObject:nil];
|
||||
return [XSHelper dic2Json:resData];
|
||||
}
|
||||
else if([XSHelper isMatch:@"^/adtask/load" test:path]) {
|
||||
[[MyEventBus sharedInstance] postEvent:@"Load" withObject:nil];
|
||||
return [XSHelper dic2Json:resData];
|
||||
}
|
||||
else if([XSHelper isMatch:@"^/adtask/end" test:path]) {
|
||||
|
||||
17
ips.txt
17
ips.txt
@ -1,16 +1 @@
|
||||
172.29.119.30
|
||||
172.29.119.25
|
||||
172.29.119.14
|
||||
172.29.119.19
|
||||
172.29.119.21
|
||||
172.29.119.20
|
||||
172.29.119.12
|
||||
172.29.119.10
|
||||
172.29.119.23
|
||||
172.29.119.13
|
||||
172.29.119.22
|
||||
172.29.119.15
|
||||
172.29.119.18
|
||||
172.29.119.17
|
||||
172.29.119.16
|
||||
172.29.119.26
|
||||
192.168.31.103
|
||||
BIN
packages/20251118-nt-newapi.deb
Normal file
BIN
packages/20251118-nt-newapi.deb
Normal file
Binary file not shown.
23
testudp.py
Normal file
23
testudp.py
Normal file
@ -0,0 +1,23 @@
|
||||
import socket
|
||||
|
||||
|
||||
data = """
|
||||
{
|
||||
"url": "/adtask/show"
|
||||
}
|
||||
""".encode('utf-8')
|
||||
|
||||
with open('./ips.txt', 'r') as f:
|
||||
for ip in f.readlines():
|
||||
print(ip.strip())
|
||||
try:
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
s.settimeout(5)
|
||||
# 发送数据:
|
||||
s.sendto(data, (ip.strip(), 6001))
|
||||
# 接收数据:
|
||||
print(s.recv(1024).decode('utf-8'))
|
||||
s.close()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user