@@ -84,7 +84,8 @@ extension RemoteConfigViewController {
8484 func showAdd( defaultUrl: String ? = nil ,
8585 defaultName: String ? = nil ,
8686 name: String ? = nil ,
87- allowAlt: Bool = false ) {
87+ allowAlt: Bool = false ,
88+ ageSecretKey: String ? = nil ) {
8889 let alertView = NSAlert ( )
8990 alertView. addButton ( withTitle: NSLocalizedString ( " OK " , comment: " " ) )
9091 alertView. addButton ( withTitle: NSLocalizedString ( " Cancel " , comment: " " ) )
@@ -108,19 +109,22 @@ extension RemoteConfigViewController {
108109 let configName = remoteConfigInputView. getConfigName ( ) . 0
109110 let isPlaceHolderName = remoteConfigInputView. getConfigName ( ) . 1
110111 let configUrl = remoteConfigInputView. getUrlString ( )
111-
112+ let ageSecretKey = remoteConfigInputView. getAgeSecretKey ( )
113+
112114 if let existed = RemoteConfigManager . shared. configs. first ( where: { $0. name == configName } ) {
113115 guard allowAlt else {
114116 NSAlert . alert ( with: NSLocalizedString ( " The remote config name is duplicated " , comment: " " ) )
115117 return
116118 }
117119 existed. url = configUrl
120+ existed. ageSecretKey = ageSecretKey
118121 latestAddedConfig = existed
119122 requestUpdate ( config: existed)
120123 } else {
121124 let remoteConfig = RemoteConfigModel ( url: configUrl,
122125 name: configName,
123- updateTime: nil )
126+ updateTime: nil ,
127+ ageSecretKey: ageSecretKey)
124128 remoteConfig. isPlaceHolderName = !isPlaceHolderName
125129 RemoteConfigManager . shared. configs. append ( remoteConfig)
126130 requestUpdate ( config: remoteConfig)
@@ -172,9 +176,17 @@ extension RemoteConfigViewController: NSTableViewDelegate {
172176 let row = tableView. clickedRow
173177 guard let config = RemoteConfigManager . shared. configs [ safe: row] else { return }
174178 if config. isPlaceHolderName {
175- showAdd ( defaultUrl: config. url, defaultName: config. name, name: nil , allowAlt: true )
179+ showAdd ( defaultUrl: config. url,
180+ defaultName: config. name,
181+ name: nil ,
182+ allowAlt: true ,
183+ ageSecretKey: config. ageSecretKey)
176184 } else {
177- showAdd ( defaultUrl: config. url, defaultName: nil , name: config. name, allowAlt: true )
185+ showAdd ( defaultUrl: config. url,
186+ defaultName: nil ,
187+ name: config. name,
188+ allowAlt: true ,
189+ ageSecretKey: config. ageSecretKey)
178190 }
179191 }
180192}
@@ -215,9 +227,18 @@ extension RemoteConfigViewController: NSTableViewDataSource {
215227class RemoteConfigAddView : NSView , NibLoadable {
216228 @IBOutlet private var urlTextField : NSTextField !
217229 @IBOutlet private var configNameTextField : NSTextField !
218-
230+ @IBOutlet var ageSecretTextField : NSTextField !
231+
219232 func getUrlString( ) -> String {
220- return urlTextField. stringValue
233+ urlTextField. stringValue
234+ }
235+
236+ func getAgeSecretKey( ) -> String ? {
237+ let str = ageSecretTextField. stringValue
238+ if str. isEmpty || !str. uppercased ( ) . starts ( with: " AGE-SECRET-KEY " ) {
239+ return nil
240+ }
241+ return str
221242 }
222243
223244 /// Get the config name
@@ -233,7 +254,10 @@ class RemoteConfigAddView: NSView, NibLoadable {
233254 return urlTextField. stringValue. isUrlVaild ( ) && !getConfigName( ) . 0 . isEmpty
234255 }
235256
236- func setUrl( string: String , name: String ? = nil , defaultName: String ? ) {
257+ func setUrl( string: String ,
258+ name: String ? = nil ,
259+ defaultName: String ? ,
260+ ageSecretKey: String ? = nil ) {
237261 urlTextField. stringValue = string
238262
239263 if let name = name, !name. isEmpty {
@@ -243,6 +267,10 @@ class RemoteConfigAddView: NSView, NibLoadable {
243267 if let defaultName = defaultName, !defaultName. isEmpty {
244268 configNameTextField. placeholderString = defaultName
245269 }
270+
271+ if let key = ageSecretKey, !key. isEmpty {
272+ ageSecretTextField. stringValue = key
273+ }
246274
247275 if name == nil && defaultName == nil {
248276 updateConfigName ( )
0 commit comments