本地展示load和show

This commit is contained in:
xsean 2025-11-18 11:49:58 +08:00
parent d0495f3a18
commit 437cdc5b1b
23 changed files with 2247 additions and 2141 deletions

View File

@ -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

View File

@ -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.

View File

@ -1 +1 @@
79
80

View File

@ -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)];

View File

@ -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");
}

View File

@ -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
View File

@ -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

Binary file not shown.

23
testudp.py Normal file
View 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)