From bee72bd854852b3e8be2af28913a34b6a41f293e Mon Sep 17 00:00:00 2001 From: True Zhuanjia Date: Wed, 11 Feb 2026 16:41:46 +0800 Subject: [PATCH] - better widget profile update strategy - feat: restore widget templates --- VoidLink/Base.lproj/iPad.storyboard | 18 +++++----- VoidLink/Base.lproj/iPhone.storyboard | 18 +++++----- VoidLink/Input/CustomOSC/OSCProfilesManager.h | 1 + VoidLink/Input/CustomOSC/OSCProfilesManager.m | 34 +++++++++++++++++-- .../LayoutOnScreenControlsViewController.m | 2 +- .../OSCProfilesTableViewController.m | 5 +-- VoidLink/mul.lproj/iPad.xcstrings | 10 +++--- VoidLink/mul.lproj/iPhone.xcstrings | 14 ++++---- 8 files changed, 66 insertions(+), 36 deletions(-) diff --git a/VoidLink/Base.lproj/iPad.storyboard b/VoidLink/Base.lproj/iPad.storyboard index bd7b6e40..fd661331 100644 --- a/VoidLink/Base.lproj/iPad.storyboard +++ b/VoidLink/Base.lproj/iPad.storyboard @@ -3126,11 +3126,6 @@ - - - - - @@ -3141,6 +3136,11 @@ + + + + + @@ -3196,19 +3196,19 @@ - + - + - + - + diff --git a/VoidLink/Base.lproj/iPhone.storyboard b/VoidLink/Base.lproj/iPhone.storyboard index 7ec60722..902b55b0 100644 --- a/VoidLink/Base.lproj/iPhone.storyboard +++ b/VoidLink/Base.lproj/iPhone.storyboard @@ -962,11 +962,6 @@ - - - - - @@ -977,6 +972,11 @@ + + + + + @@ -3086,16 +3086,16 @@ - + - + - + - + diff --git a/VoidLink/Input/CustomOSC/OSCProfilesManager.h b/VoidLink/Input/CustomOSC/OSCProfilesManager.h index 2178251b..cd9447c5 100644 --- a/VoidLink/Input/CustomOSC/OSCProfilesManager.h +++ b/VoidLink/Input/CustomOSC/OSCProfilesManager.h @@ -49,6 +49,7 @@ NS_ASSUME_NONNULL_BEGIN // - (NSData* )getSelectedEncodedProfile; - (void) importEncodedProfiles:(NSMutableArray* )profilesEncoded; - (OnScreenButtonState *)unarchiveButtonStateEncoded:(NSData *)data; +- (void) updateDefaultTemplates; - (void) importDefaultTemplates; #pragma mark - Setters diff --git a/VoidLink/Input/CustomOSC/OSCProfilesManager.m b/VoidLink/Input/CustomOSC/OSCProfilesManager.m index 89a5485d..6c6006d4 100644 --- a/VoidLink/Input/CustomOSC/OSCProfilesManager.m +++ b/VoidLink/Input/CustomOSC/OSCProfilesManager.m @@ -183,7 +183,6 @@ static CGRect layoutViewBounds; return ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone); } - - (void) importDefaultTemplates{ NSString *filePath = [[NSBundle mainBundle] pathForResource: [self isIPhone] ? @"widgetTemplatesIPhone": @"widgetTemplates" ofType:@"bin"]; if (filePath) { @@ -201,6 +200,34 @@ static CGRect layoutViewBounds; } } +- (void) updateDefaultTemplates{ + NSString *filePath = [[NSBundle mainBundle] pathForResource: [self isIPhone] ? @"widgetTemplatesIPhone": @"widgetTemplates" ofType:@"bin"]; + if (filePath) { + // 2. 读取二进制数据 + NSError *error; + NSData *fileData = [NSData dataWithContentsOfFile:filePath options:NSDataReadingMappedIfSafe error:&error]; + if (fileData && !error) { + NSSet *classes = [NSSet setWithObjects:[NSString class], [NSMutableData class], [NSMutableArray class], [OSCProfile class], [OnScreenButtonState class], nil]; + NSMutableArray *defaultProfilesEncoded = [NSKeyedUnarchiver unarchivedObjectOfClasses:classes fromData:fileData error:nil]; // Decode the encoded array itself, NOT the objects contained in the array + OSCProfile *defaultProfileDecoded; + NSMutableArray *targetProfilesDecoded = [self getAllProfiles]; + for (NSData *profileEncoded in defaultProfilesEncoded) { + defaultProfileDecoded = [NSKeyedUnarchiver unarchivedObjectOfClasses: classes fromData:profileEncoded error: nil]; + OSCProfile *targetProfile = [self findProfileByName:defaultProfileDecoded.name inProfileArray:targetProfilesDecoded]; + if(targetProfile){ + uint64_t targetIndex = [targetProfilesDecoded indexOfObject:targetProfile]; + targetProfilesDecoded[targetIndex] = defaultProfileDecoded; + } + } + NSMutableArray* targetPofilesEncoded = [self encodedProfilesFromArray:targetProfilesDecoded]; + NSData *data = [NSKeyedArchiver archivedDataWithRootObject:targetPofilesEncoded requiringSecureCoding:YES error:nil]; + [[NSUserDefaults standardUserDefaults] setObject:data forKey:@"OSCProfiles"]; + [[NSUserDefaults standardUserDefaults] synchronize]; + [self setProfileToSelected:0]; + } + } +} + #pragma mark - Globally Accessible Methods @@ -230,11 +257,12 @@ static CGRect layoutViewBounds; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; // NSString* persistedKey = @"widgetProfileUpdated-20251015"; - NSString* persistedKey = @"widgetProfileUpdated-20251229"; + NSString* persistedKey = @"widgetProfileUpdated-20260212"; BOOL needImportDefaultTemplates = [defaults objectForKey:persistedKey] == nil; if(profiles.count == 0 || needImportDefaultTemplates){ - [self importDefaultTemplates]; + if(profiles.count == 0) [self importDefaultTemplates]; + else [self updateDefaultTemplates]; [[NSUserDefaults standardUserDefaults] setBool:YES forKey:persistedKey]; [[NSUserDefaults standardUserDefaults] synchronize]; profiles = [self getAllProfiles]; diff --git a/VoidLink/ViewControllers/CustomOSCViewControl/LayoutOnScreenControlsViewController.m b/VoidLink/ViewControllers/CustomOSCViewControl/LayoutOnScreenControlsViewController.m index df8c8a19..d7cd7f23 100644 --- a/VoidLink/ViewControllers/CustomOSCViewControl/LayoutOnScreenControlsViewController.m +++ b/VoidLink/ViewControllers/CustomOSCViewControl/LayoutOnScreenControlsViewController.m @@ -269,7 +269,7 @@ typedef NS_ENUM(NSUInteger, DecelerationRateSliderMode) { [profilesManager importDefaultTemplates]; }*/ if (![profilesManager findProfileByName:DEFAULT_TEMPLATE_NAME1 inProfileArray:allProfiles]){ - [profilesManager importDefaultTemplates]; + // [profilesManager updateDefaultTemplates]; } /* This will animate the toolbar with a subtle up and down motion intended to telegraph to the user that they can hide the toolbar if they wish*/ diff --git a/VoidLink/ViewControllers/CustomOSCViewControl/OSCProfilesTableViewController.m b/VoidLink/ViewControllers/CustomOSCViewControl/OSCProfilesTableViewController.m index 28fd9b1c..8b186332 100644 --- a/VoidLink/ViewControllers/CustomOSCViewControl/OSCProfilesTableViewController.m +++ b/VoidLink/ViewControllers/CustomOSCViewControl/OSCProfilesTableViewController.m @@ -232,8 +232,9 @@ const double NAV_BAR_HEIGHT = 50; [self presentViewController:documentPicker animated:YES completion:nil]; } -- (IBAction) exitTapped:(id)sender { - [self dismissViewControllerAnimated:NO completion:nil]; +- (IBAction) restoreTapped:(id)sender { + [profilesManager importDefaultTemplates]; + [self profileViewRefresh]; } #pragma mark - UIDocumentPickerDelegate diff --git a/VoidLink/mul.lproj/iPad.xcstrings b/VoidLink/mul.lproj/iPad.xcstrings index 7b299f18..e25950d6 100644 --- a/VoidLink/mul.lproj/iPad.xcstrings +++ b/VoidLink/mul.lproj/iPad.xcstrings @@ -2138,31 +2138,31 @@ } }, "czn-mj-8d1.title" : { - "comment" : "Class = \"UIBarButtonItem\"; title = \"Exit\"; ObjectID = \"czn-mj-8d1\";", + "comment" : "Class = \"UIBarButtonItem\"; title = \"Restore\"; ObjectID = \"czn-mj-8d1\";", "extractionState" : "extracted_with_value", "localizations" : { "en" : { "stringUnit" : { "state" : "new", - "value" : "Exit" + "value" : "Restore" } }, "zh-Hans" : { "stringUnit" : { "state" : "translated", - "value" : "退出" + "value" : "恢复模板" } }, "zh-Hant" : { "stringUnit" : { "state" : "translated", - "value" : "退出" + "value" : "恢復範本" } }, "zh-HK" : { "stringUnit" : { "state" : "translated", - "value" : "退出" + "value" : "恢復範本" } } } diff --git a/VoidLink/mul.lproj/iPhone.xcstrings b/VoidLink/mul.lproj/iPhone.xcstrings index 642860d4..04cb6bb6 100644 --- a/VoidLink/mul.lproj/iPhone.xcstrings +++ b/VoidLink/mul.lproj/iPhone.xcstrings @@ -4838,31 +4838,31 @@ } }, "sUC-Ur-7eI.title" : { - "comment" : "Class = \"UIBarButtonItem\"; title = \"Exit\"; ObjectID = \"sUC-Ur-7eI\";", + "comment" : "Class = \"UIBarButtonItem\"; title = \"Restore\"; ObjectID = \"sUC-Ur-7eI\";", "extractionState" : "extracted_with_value", "localizations" : { "en" : { "stringUnit" : { "state" : "new", - "value" : "Exit" + "value" : "Restore" } }, "zh-Hans" : { "stringUnit" : { "state" : "translated", - "value" : "退出" + "value" : "恢复模板" } }, "zh-Hant" : { "stringUnit" : { - "state" : "translated", - "value" : "退出" + "state" : "needs_review", + "value" : "恢復範本" } }, "zh-HK" : { "stringUnit" : { - "state" : "translated", - "value" : "退出" + "state" : "needs_review", + "value" : "恢復範本" } } }