-
Notifications
You must be signed in to change notification settings - Fork 903
feat: 添加中国厂商支持 + MiMo provider + KimiK2 余额 API #838
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Meteorkid
wants to merge
1
commit into
steipete:main
Choose a base branch
from
Meteorkid:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
Sources/CodexBar/Providers/Doubao/DoubaoProviderImplementation.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| import AppKit | ||
| import CodexBarCore | ||
| import CodexBarMacroSupport | ||
| import Foundation | ||
| import SwiftUI | ||
|
|
||
| @ProviderImplementationRegistration | ||
| struct DoubaoProviderImplementation: ProviderImplementation { | ||
| let id: UsageProvider = .doubao | ||
|
|
||
| @MainActor | ||
| func presentation(context _: ProviderPresentationContext) -> ProviderPresentation { | ||
| ProviderPresentation { _ in "web" } | ||
| } | ||
|
|
||
| @MainActor | ||
| func observeSettings(_ settings: SettingsStore) { | ||
| _ = settings.doubaoCookieSource | ||
| _ = settings.doubaoManualCookieHeader | ||
| } | ||
|
|
||
| @MainActor | ||
| func settingsSnapshot(context: ProviderSettingsSnapshotContext) -> ProviderSettingsSnapshotContribution? { | ||
| .doubao(context.settings.doubaoSettingsSnapshot(tokenOverride: context.tokenOverride)) | ||
| } | ||
|
|
||
| @MainActor | ||
| func isAvailable(context: ProviderAvailabilityContext) -> Bool { | ||
| if DoubaoSettingsReader.apiKey(environment: context.environment) != nil { | ||
| return true | ||
| } | ||
| return !context.settings.tokenAccounts(for: .doubao).isEmpty | ||
| } | ||
|
|
||
| @MainActor | ||
| func settingsPickers(context: ProviderSettingsContext) -> [ProviderSettingsPickerDescriptor] { | ||
| let cookieBinding = Binding( | ||
| get: { context.settings.doubaoCookieSource.rawValue }, | ||
| set: { raw in | ||
| context.settings.doubaoCookieSource = ProviderCookieSource(rawValue: raw) ?? .auto | ||
| }) | ||
| let options = ProviderCookieSourceUI.options( | ||
| allowsOff: true, | ||
| keychainDisabled: context.settings.debugDisableKeychainAccess) | ||
|
|
||
| let subtitle: () -> String? = { | ||
| ProviderCookieSourceUI.subtitle( | ||
| source: context.settings.doubaoCookieSource, | ||
| keychainDisabled: context.settings.debugDisableKeychainAccess, | ||
| auto: "Automatic imports browser cookies.", | ||
| manual: "Paste the full Cookie header value.", | ||
| off: "Doubao cookies are disabled.") | ||
| } | ||
|
|
||
| return [ | ||
| ProviderSettingsPickerDescriptor( | ||
| id: "doubao-cookie-source", | ||
| title: "Cookie source", | ||
| subtitle: "Automatic imports browser cookies.", | ||
| dynamicSubtitle: subtitle, | ||
| binding: cookieBinding, | ||
| options: options, | ||
| isVisible: nil, | ||
| onChange: nil), | ||
| ] | ||
| } | ||
|
|
||
| @MainActor | ||
| func settingsFields(context: ProviderSettingsContext) -> [ProviderSettingsFieldDescriptor] { | ||
| [ | ||
| ProviderSettingsFieldDescriptor( | ||
| id: "doubao-cookie", | ||
| title: "", | ||
| subtitle: "", | ||
| kind: .secure, | ||
| placeholder: "Cookie: \u{2026}\n\nPaste the full Cookie header from console.volcengine.com", | ||
| binding: context.stringBinding(\.doubaoManualCookieHeader), | ||
| actions: [ | ||
| ProviderSettingsActionDescriptor( | ||
| id: "doubao-open-console", | ||
| title: "Open Console", | ||
| style: .link, | ||
| isVisible: nil, | ||
| perform: { | ||
| if let url = URL(string: "https://console.volcengine.com/ark") { | ||
| NSWorkspace.shared.open(url) | ||
| } | ||
| }), | ||
| ], | ||
| isVisible: { context.settings.doubaoCookieSource == .manual }, | ||
| onActivate: nil), | ||
| ] | ||
| } | ||
| } |
33 changes: 33 additions & 0 deletions
33
Sources/CodexBar/Providers/Doubao/DoubaoSettingsStore.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import CodexBarCore | ||
| import Foundation | ||
|
|
||
| extension SettingsStore { | ||
| var doubaoManualCookieHeader: String { | ||
| get { self.configSnapshot.providerConfig(for: .doubao)?.sanitizedCookieHeader ?? "" } | ||
| set { | ||
| self.updateProviderConfig(provider: .doubao) { entry in | ||
| entry.cookieHeader = self.normalizedConfigValue(newValue) | ||
| } | ||
| self.logSecretUpdate(provider: .doubao, field: "cookieHeader", value: newValue) | ||
| } | ||
| } | ||
|
|
||
| var doubaoCookieSource: ProviderCookieSource { | ||
| get { self.resolvedCookieSource(provider: .doubao, fallback: .auto) } | ||
| set { | ||
| self.updateProviderConfig(provider: .doubao) { entry in | ||
| entry.cookieSource = newValue | ||
| } | ||
| self.logProviderModeChange(provider: .doubao, field: "cookieSource", value: newValue.rawValue) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| extension SettingsStore { | ||
| func doubaoSettingsSnapshot(tokenOverride: TokenAccountOverride?) -> ProviderSettingsSnapshot.DoubaoProviderSettings { | ||
| _ = tokenOverride | ||
| return ProviderSettingsSnapshot.DoubaoProviderSettings( | ||
| cookieSource: self.doubaoCookieSource, | ||
| manualCookieHeader: self.doubaoManualCookieHeader) | ||
| } | ||
| } |
94 changes: 94 additions & 0 deletions
94
Sources/CodexBar/Providers/Ernie/ErnieProviderImplementation.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| import AppKit | ||
| import CodexBarCore | ||
| import CodexBarMacroSupport | ||
| import Foundation | ||
| import SwiftUI | ||
|
|
||
| @ProviderImplementationRegistration | ||
| struct ErnieProviderImplementation: ProviderImplementation { | ||
| let id: UsageProvider = .ernie | ||
|
|
||
| @MainActor | ||
| func presentation(context _: ProviderPresentationContext) -> ProviderPresentation { | ||
| ProviderPresentation { _ in "web" } | ||
| } | ||
|
|
||
| @MainActor | ||
| func observeSettings(_ settings: SettingsStore) { | ||
| _ = settings.ernieCookieSource | ||
| _ = settings.ernieManualCookieHeader | ||
| } | ||
|
|
||
| @MainActor | ||
| func settingsSnapshot(context: ProviderSettingsSnapshotContext) -> ProviderSettingsSnapshotContribution? { | ||
| .ernie(context.settings.ernieSettingsSnapshot(tokenOverride: context.tokenOverride)) | ||
| } | ||
|
|
||
| @MainActor | ||
| func isAvailable(context: ProviderAvailabilityContext) -> Bool { | ||
| if ErnieSettingsReader.apiKey(environment: context.environment) != nil { | ||
| return true | ||
| } | ||
| return !context.settings.tokenAccounts(for: .ernie).isEmpty | ||
| } | ||
|
|
||
| @MainActor | ||
| func settingsPickers(context: ProviderSettingsContext) -> [ProviderSettingsPickerDescriptor] { | ||
| let cookieBinding = Binding( | ||
| get: { context.settings.ernieCookieSource.rawValue }, | ||
| set: { raw in | ||
| context.settings.ernieCookieSource = ProviderCookieSource(rawValue: raw) ?? .auto | ||
| }) | ||
| let options = ProviderCookieSourceUI.options( | ||
| allowsOff: true, | ||
| keychainDisabled: context.settings.debugDisableKeychainAccess) | ||
|
|
||
| let subtitle: () -> String? = { | ||
| ProviderCookieSourceUI.subtitle( | ||
| source: context.settings.ernieCookieSource, | ||
| keychainDisabled: context.settings.debugDisableKeychainAccess, | ||
| auto: "Automatic imports browser cookies.", | ||
| manual: "Paste the full Cookie header value.", | ||
| off: "ERNIE cookies are disabled.") | ||
| } | ||
|
|
||
| return [ | ||
| ProviderSettingsPickerDescriptor( | ||
| id: "ernie-cookie-source", | ||
| title: "Cookie source", | ||
| subtitle: "Automatic imports browser cookies.", | ||
| dynamicSubtitle: subtitle, | ||
| binding: cookieBinding, | ||
| options: options, | ||
| isVisible: nil, | ||
| onChange: nil), | ||
| ] | ||
| } | ||
|
|
||
| @MainActor | ||
| func settingsFields(context: ProviderSettingsContext) -> [ProviderSettingsFieldDescriptor] { | ||
| [ | ||
| ProviderSettingsFieldDescriptor( | ||
| id: "ernie-cookie", | ||
| title: "", | ||
| subtitle: "", | ||
| kind: .secure, | ||
| placeholder: "Cookie: \u{2026}\n\nPaste the full Cookie header from console.bce.baidu.com", | ||
| binding: context.stringBinding(\.ernieManualCookieHeader), | ||
| actions: [ | ||
| ProviderSettingsActionDescriptor( | ||
| id: "ernie-open-console", | ||
| title: "Open Console", | ||
| style: .link, | ||
| isVisible: nil, | ||
| perform: { | ||
| if let url = URL(string: "https://console.bce.baidu.com/qianfan/overview") { | ||
| NSWorkspace.shared.open(url) | ||
| } | ||
| }), | ||
| ], | ||
| isVisible: { context.settings.ernieCookieSource == .manual }, | ||
| onActivate: nil), | ||
| ] | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import CodexBarCore | ||
| import Foundation | ||
|
|
||
| extension SettingsStore { | ||
| var ernieManualCookieHeader: String { | ||
| get { self.configSnapshot.providerConfig(for: .ernie)?.sanitizedCookieHeader ?? "" } | ||
| set { | ||
| self.updateProviderConfig(provider: .ernie) { entry in | ||
| entry.cookieHeader = self.normalizedConfigValue(newValue) | ||
| } | ||
| self.logSecretUpdate(provider: .ernie, field: "cookieHeader", value: newValue) | ||
| } | ||
| } | ||
|
|
||
| var ernieCookieSource: ProviderCookieSource { | ||
| get { self.resolvedCookieSource(provider: .ernie, fallback: .auto) } | ||
| set { | ||
| self.updateProviderConfig(provider: .ernie) { entry in | ||
| entry.cookieSource = newValue | ||
| } | ||
| self.logProviderModeChange(provider: .ernie, field: "cookieSource", value: newValue.rawValue) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| extension SettingsStore { | ||
| func ernieSettingsSnapshot(tokenOverride: TokenAccountOverride?) -> ProviderSettingsSnapshot.ErnieProviderSettings { | ||
| _ = tokenOverride | ||
| return ProviderSettingsSnapshot.ErnieProviderSettings( | ||
| cookieSource: self.ernieCookieSource, | ||
| manualCookieHeader: self.ernieManualCookieHeader) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The proxy is only started inside the toggle setter. When
proxyEnabledis alreadytruefrom saved defaults (e.g., app relaunch), this setter is never invoked, so the UI can show the feature enabled while no proxy is running until the user toggles it again. Add an initialization path (e.g., on appear/app startup) that starts the proxy when persisted state is enabled.Useful? React with 👍 / 👎.