tweak widget templates
This commit is contained in:
1 parent
a7d7a7975f
commit
e987965765
3 files changed
+17
-8
No files matched your search
@@ -15,7 +15,7 @@ import UIKit
|
|||||||
class OSCProfilesManager: NSObject {
|
class OSCProfilesManager: NSObject {
|
||||||
private static let profilesDefaultsKey = "OSCProfiles"
|
private static let profilesDefaultsKey = "OSCProfiles"
|
||||||
// private static let widgetProfileUpdatedKey = "widgetProfileUpdated-20260606"
|
// private static let widgetProfileUpdatedKey = "widgetProfileUpdated-20260606"
|
||||||
private static let widgetProfileUpdatedKey = "widgetProfileUpdated-20260622"
|
private static let widgetProfileUpdatedKey = "widgetProfileUpdated-20260622-6"
|
||||||
|
|
||||||
private static var sharedInstance: OSCProfilesManager?
|
private static var sharedInstance: OSCProfilesManager?
|
||||||
private static var onScreenWidgetViews: NSMutableSet?
|
private static var onScreenWidgetViews: NSMutableSet?
|
||||||
@@ -216,7 +216,7 @@ class OSCProfilesManager: NSObject {
|
|||||||
UIDevice.current.userInterfaceIdiom == .phone
|
UIDevice.current.userInterfaceIdiom == .phone
|
||||||
}
|
}
|
||||||
|
|
||||||
func importDefaultTemplates() {
|
func importDefaultTemplates(selectedIndex: UInt32? = nil) {
|
||||||
guard let filePath = Bundle.main.path(forResource: isIPhone() ? "widgetTemplatesIPhone" : "widgetTemplates", ofType: "bin") else {
|
guard let filePath = Bundle.main.path(forResource: isIPhone() ? "widgetTemplatesIPhone" : "widgetTemplates", ofType: "bin") else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -225,7 +225,9 @@ class OSCProfilesManager: NSObject {
|
|||||||
let fileData = try Data(contentsOf: URL(fileURLWithPath: filePath), options: .mappedIfSafe)
|
let fileData = try Data(contentsOf: URL(fileURLWithPath: filePath), options: .mappedIfSafe)
|
||||||
if let profilesEncoded = try NSKeyedUnarchiver.unarchivedObject(ofClasses: [NSMutableData.self, NSMutableArray.self], from: fileData) as? NSMutableArray {
|
if let profilesEncoded = try NSKeyedUnarchiver.unarchivedObject(ofClasses: [NSMutableData.self, NSMutableArray.self], from: fileData) as? NSMutableArray {
|
||||||
importEncodedProfiles(profilesEncoded)
|
importEncodedProfiles(profilesEncoded)
|
||||||
setProfileToSelected(0)
|
if let selectedIndex = selectedIndex {
|
||||||
|
setProfileToSelected(selectedIndex)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
return
|
return
|
||||||
@@ -309,16 +311,23 @@ class OSCProfilesManager: NSObject {
|
|||||||
let defaults = UserDefaults.standard
|
let defaults = UserDefaults.standard
|
||||||
let needImportDefaultTemplates = defaults.object(forKey: Self.widgetProfileUpdatedKey) == nil
|
let needImportDefaultTemplates = defaults.object(forKey: Self.widgetProfileUpdatedKey) == nil
|
||||||
|
|
||||||
if (profiles.count == 0 || needImportDefaultTemplates) && !GenericUtils.pencilProPurchaseProcessedWithImportingWidgetTemplates {
|
var selectedIndex: UInt32 = 0
|
||||||
importDefaultTemplates()
|
for case let profile as OSCProfile in profiles where profile.isSelected {
|
||||||
|
selectedIndex = UInt32(profiles.index(of: profile))
|
||||||
|
}
|
||||||
|
|
||||||
|
let currentProfileCount = profiles.count
|
||||||
|
|
||||||
|
if (currentProfileCount == 0 || needImportDefaultTemplates) && !GenericUtils.pencilProPurchaseProcessedWithImportingWidgetTemplates {
|
||||||
|
selectedIndex = currentProfileCount == 0 ? 0 : selectedIndex
|
||||||
|
importDefaultTemplates(selectedIndex: selectedIndex)
|
||||||
defaults.set(true, forKey: Self.widgetProfileUpdatedKey)
|
defaults.set(true, forKey: Self.widgetProfileUpdatedKey)
|
||||||
defaults.synchronize()
|
defaults.synchronize()
|
||||||
profiles = getAllProfiles()
|
profiles = getAllProfiles()
|
||||||
}
|
}
|
||||||
|
|
||||||
for case let profile as OSCProfile in profiles where profile.isSelected {
|
|
||||||
return profile
|
return profiles[Int(selectedIndex)] as! OSCProfile
|
||||||
}
|
|
||||||
|
|
||||||
return (profiles.firstObject as? OSCProfile) ?? OSCProfile(name: "", buttonStates: NSMutableArray(), isSelected: false)
|
return (profiles.firstObject as? OSCProfile) ?? OSCProfile(name: "", buttonStates: NSMutableArray(), isSelected: false)
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Reference in new issue
Block a user