- better widget profile update strategy

- feat: restore widget templates
This commit is contained in:
True Zhuanjia
2026-02-11 16:41:46 +08:00
parent 8ec8f32935
commit bee72bd854
8 changed files with 66 additions and 36 deletions
+9 -9
View File
@@ -3126,11 +3126,6 @@
<items>
<navigationItem title="Widget Profiles" id="Q2V-XF-4jq">
<leftBarButtonItems>
<barButtonItem title="Exit" width="45" style="plain" id="czn-mj-8d1">
<connections>
<action selector="exitTapped:" destination="Atv-Nj-0qv" id="IvQ-c3-bmW"/>
</connections>
</barButtonItem>
<barButtonItem title="ExportAll" width="70" style="plain" id="Bhn-IO-Wlt" userLabel="Export Data">
<connections>
<action selector="exportDataTapped:" destination="Atv-Nj-0qv" id="pwG-sO-9he"/>
@@ -3141,6 +3136,11 @@
<action selector="importDataTapped:" destination="Atv-Nj-0qv" id="Uq0-Ct-LbS"/>
</connections>
</barButtonItem>
<barButtonItem title="Restore" width="45" style="plain" id="czn-mj-8d1">
<connections>
<action selector="restoreTapped:" destination="Atv-Nj-0qv" id="IvQ-c3-bmW"/>
</connections>
</barButtonItem>
</leftBarButtonItems>
<rightBarButtonItems>
<barButtonItem title="Duplicate" width="80" style="plain" id="P34-hO-6cX">
@@ -3196,19 +3196,19 @@
<image name="tray.full.fill" catalog="system" width="128" height="88"/>
<image name="video.and.waveform" catalog="system" width="128" height="94"/>
<systemColor name="linkColor">
<color red="0.0" green="0.47843137250000001" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color red="0.0" green="0.47843137254901963" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
<systemColor name="systemBrownColor">
<color red="0.63529411759999999" green="0.51764705879999995" blue="0.36862745099999999" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color red="0.67450980392156867" green="0.49803921568627452" blue="0.36862745098039218" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
<systemColor name="systemGray3Color">
<color red="0.78039215689999997" green="0.78039215689999997" blue="0.80000000000000004" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color red="0.7803921568627451" green="0.7803921568627451" blue="0.80000000000000004" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
<systemColor name="systemTealColor">
<color red="0.18823529410000001" green="0.69019607839999997" blue="0.78039215689999997" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color red="0.0" green="0.76470588235294112" blue="0.81568627450980391" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
</resources>
</document>
+9 -9
View File
@@ -962,11 +962,6 @@
<items>
<navigationItem title="Controller &amp; Widget Profiles" id="5pN-Sn-SCN">
<leftBarButtonItems>
<barButtonItem title="Exit" id="sUC-Ur-7eI">
<connections>
<action selector="exitTapped:" destination="0K8-kQ-xlN" id="lAJ-eO-ez7"/>
</connections>
</barButtonItem>
<barButtonItem title="ExportAll" id="D9X-7p-9oc">
<connections>
<action selector="exportDataTapped:" destination="0K8-kQ-xlN" id="Sam-Ct-kqC"/>
@@ -977,6 +972,11 @@
<action selector="importDataTapped:" destination="0K8-kQ-xlN" id="OaF-8j-7Wy"/>
</connections>
</barButtonItem>
<barButtonItem title="Restore" id="sUC-Ur-7eI">
<connections>
<action selector="restoreTapped:" destination="0K8-kQ-xlN" id="lAJ-eO-ez7"/>
</connections>
</barButtonItem>
</leftBarButtonItems>
<rightBarButtonItems>
<barButtonItem title="Duplicate" width="80" style="plain" id="bue-hp-CWD">
@@ -3086,16 +3086,16 @@
<image name="trash.fill" catalog="system" width="117" height="128"/>
<image name="tray.full.fill" catalog="system" width="128" height="88"/>
<systemColor name="linkColor">
<color red="0.0" green="0.47843137250000001" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color red="0.0" green="0.47843137254901963" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
<systemColor name="systemBrownColor">
<color red="0.63529411759999999" green="0.51764705879999995" blue="0.36862745099999999" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color red="0.67450980392156867" green="0.49803921568627452" blue="0.36862745098039218" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
<systemColor name="systemGray2Color">
<color red="0.68235294120000001" green="0.68235294120000001" blue="0.69803921570000005" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color red="0.68235294117647061" green="0.68235294117647061" blue="0.69803921568627447" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
<systemColor name="systemTealColor">
<color red="0.18823529410000001" green="0.69019607839999997" blue="0.78039215689999997" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color red="0.0" green="0.76470588235294112" blue="0.81568627450980391" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</systemColor>
</resources>
</document>
@@ -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
+31 -3
View File
@@ -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];
@@ -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*/
@@ -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
+5 -5
View File
@@ -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" : "恢復範本"
}
}
}
+7 -7
View File
@@ -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" : "恢復範本"
}
}
}