- fix the issue of previous selected on-screen widget get deleted when deleting legacy osc button

- coding improvements for on-screen widget deletion
This commit is contained in:
TrueZhuangjia committed 2025-03-02 21:47:57 +08:00
1 parent ebec9877b0
commit 70e5b3520c
6 files changed
+39 -21

No files matched your search

@@ -190,6 +190,8 @@
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
/* Reset variables related to on screen controller button drag and drop routine. These variables should be reset in 'touchesCancelled' or 'touchesEnded' but these may not be called in unaccounted-for edge cases such as when the user opens various OS-level control center related views by dragging down from the top of the screen, or dragging up from the bottom of the screen. Since Apple likes to add new control centers and new ways of opening them (i.e. Dynamic Island on iPhone 14 Pro) it's best to reset these variables here when the user is beginning a new on screen controller button drag routine */
[[NSNotificationCenter defaultCenter] postNotificationName:@"LegacyOscCALayerSelectedNotification" object:self];
layerBeingDragged = nil;
horizontalGuideline.backgroundColor = [UIColor blueColor];
verticalGuideline.backgroundColor = [UIColor blueColor];
@@ -19,7 +19,7 @@ NS_ASSUME_NONNULL_BEGIN
+ (OSCProfilesManager *) sharedManager;
+ (void) setOnScreenWidgetViewsDict:(NSMutableDictionary* )dict;
+ (void) setOnScreenWidgetViewsSet:(NSMutableSet* )set;
#pragma mark - Getters
/**
+14 -6
View File
@@ -14,7 +14,7 @@
@implementation OSCProfilesManager
static NSMutableDictionary *OnScreenWidgetViewsDict;
static NSMutableSet *OnScreenWidgetViews;
#pragma mark - Initializer
@@ -32,8 +32,8 @@ static NSMutableDictionary *OnScreenWidgetViewsDict;
#pragma mark - Class Helper Methods
+ (void) setOnScreenWidgetViewsDict:(NSMutableDictionary* )dict{
OnScreenWidgetViewsDict = dict;
+ (void) setOnScreenWidgetViewsSet:(NSMutableSet* )set{
OnScreenWidgetViews = set;
}
/**
@@ -240,6 +240,14 @@ static NSMutableDictionary *OnScreenWidgetViewsDict;
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:profilesEncoded requiringSecureCoding:YES error:nil];
[[NSUserDefaults standardUserDefaults] setObject:data forKey:@"OSCProfiles"];
[[NSUserDefaults standardUserDefaults] synchronize];
// saving test:
/*
NSString *documentsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject;
NSString *path = [documentsPath stringByAppendingPathComponent:@"newDefault.bin"];
[newProfileEncoded writeToFile:path atomically:YES];
NSLog(@"默认 Profile 数据已保存到: %@", path);
*/
}
}
@@ -282,8 +290,7 @@ static NSMutableDictionary *OnScreenWidgetViewsDict;
}
// save on-screen widget views (keyboard & mouse command) as buttonstate:
[OnScreenWidgetViewsDict enumerateKeysAndObjectsUsingBlock:^(id key, id value, BOOL *stop) { // this dict is passed from the layout tool VC, as a static obj in this class.
OnScreenWidgetView *widgetView = value;
for(OnScreenWidgetView* widgetView in OnScreenWidgetViews){
OnScreenButtonState *buttonState = [[OnScreenButtonState alloc] initWithButtonName:widgetView.keyString buttonType:CustomOnScreenWidget andPosition:widgetView.center];
buttonState.alias = widgetView.keyLabel;
buttonState.timestamp = widgetView.timestamp;
@@ -296,7 +303,8 @@ static NSMutableDictionary *OnScreenWidgetViewsDict;
NSData *buttonStateEncoded = [NSKeyedArchiver archivedDataWithRootObject:buttonState requiringSecureCoding:YES error:nil];
[buttonStatesEncoded addObject: buttonStateEncoded];
}];
}
return buttonStatesEncoded;
}