1+ import Configs
12import Foundation
23import GitHubCopilotService
4+ import KeychainAccess
35import Preferences
46
57extension UserDefaultPreferenceKeys {
@@ -13,7 +15,7 @@ extension UserDefaultPreferenceKeys {
1315
1416public struct ServiceUpdateMigrator {
1517 public init ( ) { }
16-
18+
1719 public func migrate( ) async throws {
1820 let version = Bundle . main. object ( forInfoDictionaryKey: " CFBundleVersion " ) as? String ?? " 0 "
1921
@@ -24,7 +26,11 @@ public struct ServiceUpdateMigrator {
2426 func migrate( from oldVersion: String , to currentVersion: String ) async throws {
2527 guard let old = Int ( oldVersion) else { return }
2628 if old <= 135 {
27- try migrateFromLowerThanOrEqualToVersion135 ( )
29+ try migrateFromLowerThanOrEqualToVersion135 ( )
30+ }
31+
32+ if old <= 170 {
33+ try migrateFromLowerThanOrEqualToVersion170 ( )
2834 }
2935 }
3036}
@@ -73,3 +79,17 @@ func migrateFromLowerThanOrEqualToVersion135() throws {
7379 )
7480}
7581
82+ func migrateFromLowerThanOrEqualToVersion170( ) throws {
83+ let oldKeychain = Keychain ( service: keychainService, accessGroup: keychainAccessGroup)
84+ let newKeychain = oldKeychain. attributes ( [
85+ kSecUseDataProtectionKeychain as String : true ,
86+ ] )
87+
88+ if ( try ? oldKeychain. contains ( " codeiumKey " ) ) ?? false ,
89+ let key = try ? oldKeychain. getString ( " codeiumKey " )
90+ {
91+ try newKeychain. set ( key, key: " codeiumAuthKey " )
92+ try ? oldKeychain. set ( " " , key: " codeiumKey " )
93+ }
94+ }
95+
0 commit comments