-
Notifications
You must be signed in to change notification settings - Fork 776
Add Xiaomi MiMo token plan usage tracking #651
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
debpramanik
wants to merge
16
commits into
steipete:main
Choose a base branch
from
debpramanik:feature/mimo-token-plan
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 15 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
fcae5f3
Add Xiaomi MiMo balance support
7be116f
Document Xiaomi MiMo provider
ec7499a
Polish MiMo provider follow-up
145127b
Align MiMo web labeling
ab3cf93
improve MiMo icon
3e41ab3
reverting unintended default switch cases
b43d91b
Fix MiMo cookie matching
d6dfcdd
Fix MiMo cookie path matching
d7ece0d
Merge MiMo cookie stores
3f84020
Enforce MiMo manual cookies
005f186
Handle MiMo slash path cookies
f9451af
Resolve merge conflicts: accept both .perplexity (main) and .mimo (PR…
b9025c7
Fix MiMoProviderTests: add SwiftUI import and specify generic param f…
e636c7e
Add MiMo token plan usage tracking
ecfef95
Show MiMo token values in menu bar and menu card
cc35bac
Make MiMo token-plan requests best-effort and fix plan label
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
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
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
102 changes: 102 additions & 0 deletions
102
Sources/CodexBar/Providers/MiMo/MiMoProviderImplementation.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,102 @@ | ||
| import AppKit | ||
| import CodexBarCore | ||
| import CodexBarMacroSupport | ||
| import Foundation | ||
| import SwiftUI | ||
|
|
||
| @ProviderImplementationRegistration | ||
| struct MiMoProviderImplementation: ProviderImplementation { | ||
| let id: UsageProvider = .mimo | ||
| let supportsLoginFlow: Bool = true | ||
|
|
||
| @MainActor | ||
| func presentation(context _: ProviderPresentationContext) -> ProviderPresentation { | ||
| ProviderPresentation { _ in "web" } | ||
| } | ||
|
|
||
| @MainActor | ||
| func observeSettings(_ settings: SettingsStore) { | ||
| _ = settings.miMoCookieSource | ||
| _ = settings.miMoCookieHeader | ||
| } | ||
|
|
||
| @MainActor | ||
| func settingsSnapshot(context: ProviderSettingsSnapshotContext) -> ProviderSettingsSnapshotContribution? { | ||
| .mimo(context.settings.miMoSettingsSnapshot(tokenOverride: context.tokenOverride)) | ||
| } | ||
|
|
||
| @MainActor | ||
| func settingsPickers(context: ProviderSettingsContext) -> [ProviderSettingsPickerDescriptor] { | ||
| let cookieBinding = Binding( | ||
| get: { context.settings.miMoCookieSource.rawValue }, | ||
| set: { raw in | ||
| context.settings.miMoCookieSource = ProviderCookieSource(rawValue: raw) ?? .auto | ||
| }) | ||
| let cookieOptions = ProviderCookieSourceUI.options( | ||
| allowsOff: false, | ||
| keychainDisabled: context.settings.debugDisableKeychainAccess) | ||
| let cookieSubtitle: () -> String? = { | ||
| ProviderCookieSourceUI.subtitle( | ||
| source: context.settings.miMoCookieSource, | ||
| keychainDisabled: context.settings.debugDisableKeychainAccess, | ||
| auto: "Automatic imports Chrome browser cookies from Xiaomi MiMo.", | ||
| manual: "Paste a Cookie header from platform.xiaomimimo.com.", | ||
| off: "Xiaomi MiMo cookies are disabled.") | ||
| } | ||
|
|
||
| return [ | ||
| ProviderSettingsPickerDescriptor( | ||
| id: "mimo-cookie-source", | ||
| title: "Cookie source", | ||
| subtitle: "Automatic imports Chrome browser cookies from Xiaomi MiMo.", | ||
| dynamicSubtitle: cookieSubtitle, | ||
| binding: cookieBinding, | ||
| options: cookieOptions, | ||
| isVisible: nil, | ||
| onChange: nil, | ||
| trailingText: { | ||
| guard let entry = CookieHeaderCache.load(provider: .mimo) else { return nil } | ||
| let when = entry.storedAt.relativeDescription() | ||
| return "Cached: \(entry.sourceLabel) • \(when)" | ||
| }), | ||
| ] | ||
| } | ||
|
|
||
| @MainActor | ||
| func settingsFields(context: ProviderSettingsContext) -> [ProviderSettingsFieldDescriptor] { | ||
| [ | ||
| ProviderSettingsFieldDescriptor( | ||
| id: "mimo-cookie", | ||
| title: "", | ||
| subtitle: "", | ||
| kind: .secure, | ||
| placeholder: "Cookie: ...", | ||
| binding: context.stringBinding(\.miMoCookieHeader), | ||
| actions: [ | ||
| ProviderSettingsActionDescriptor( | ||
| id: "mimo-open-balance", | ||
| title: "Open MiMo Balance", | ||
| style: .link, | ||
| isVisible: nil, | ||
| perform: { | ||
| guard let url = URL(string: "https://platform.xiaomimimo.com/#/console/balance") else { | ||
| return | ||
| } | ||
| NSWorkspace.shared.open(url) | ||
| }), | ||
| ], | ||
| isVisible: { context.settings.miMoCookieSource == .manual }, | ||
| onActivate: { context.settings.ensureMiMoCookieLoaded() }), | ||
| ] | ||
| } | ||
|
|
||
| @MainActor | ||
| func runLoginFlow(context _: ProviderLoginContext) async -> Bool { | ||
| let loginURL = "https://platform.xiaomimimo.com/api/v1/genLoginUrl?currentPath=%2F%23%2Fconsole%2Fbalance" | ||
| guard let url = URL(string: loginURL) else { | ||
| return false | ||
| } | ||
| NSWorkspace.shared.open(url) | ||
| return false | ||
| } | ||
| } |
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,35 @@ | ||
| import CodexBarCore | ||
| import Foundation | ||
|
|
||
| extension SettingsStore { | ||
| var miMoCookieHeader: String { | ||
| get { self.configSnapshot.providerConfig(for: .mimo)?.sanitizedCookieHeader ?? "" } | ||
| set { | ||
| self.updateProviderConfig(provider: .mimo) { entry in | ||
| entry.cookieHeader = self.normalizedConfigValue(newValue) | ||
| } | ||
| self.logSecretUpdate(provider: .mimo, field: "cookieHeader", value: newValue) | ||
| } | ||
| } | ||
|
|
||
| var miMoCookieSource: ProviderCookieSource { | ||
| get { self.resolvedCookieSource(provider: .mimo, fallback: .auto) } | ||
| set { | ||
| self.updateProviderConfig(provider: .mimo) { entry in | ||
| entry.cookieSource = newValue | ||
| } | ||
| self.logProviderModeChange(provider: .mimo, field: "cookieSource", value: newValue.rawValue) | ||
| } | ||
| } | ||
|
|
||
| func ensureMiMoCookieLoaded() {} | ||
| } | ||
|
|
||
| extension SettingsStore { | ||
| func miMoSettingsSnapshot(tokenOverride: TokenAccountOverride?) -> ProviderSettingsSnapshot.MiMoProviderSettings { | ||
| _ = tokenOverride | ||
| return ProviderSettingsSnapshot.MiMoProviderSettings( | ||
| cookieSource: self.miMoCookieSource, | ||
| manualCookieHeader: self.miMoCookieHeader) | ||
| } | ||
| } |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
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.
This branch always renders
.mimoaccount text asBalance: ..., but MiMo now setsloginMethodto the plan name when a token plan exists (for example,Standard). In that case the menu shows misleading output likeBalance: Standardfor subscribed users. The MiMo path should only use a balance label when the value is actually a balance string, otherwise it should remain a plan label.Useful? React with 👍 / 👎.
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.
Fixed in commit cc35bac. The MiMo path now checks
localizedCaseInsensitiveContains("balance:")before applying the Balance label. WhenloginMethodis a plan name like "Standard", it renders asPlan: Standardinstead ofBalance: Standard.