-
Notifications
You must be signed in to change notification settings - Fork 2
feat(plugins): masked credentials, a saved confirmation, and a notice when a sign-in is refused #727
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
Merged
Merged
feat(plugins): masked credentials, a saved confirmation, and a notice when a sign-in is refused #727
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6b22b0f
feat(plugins): masked credentials, a saved confirmation, and a toast …
InstaZDLL d2587c6
fix(plugins): two refused sign-ins are both announced, one after the …
InstaZDLL 33f525d
fix(plugins): the sign-in notice fades in only when motion is welcome
InstaZDLL c239b3d
fix(plugins): a notice raised before the toast listens is still shown…
InstaZDLL 89d0f4b
test(plugins): pin that a stored credential never reaches the webview
InstaZDLL d0b72ea
fix(plugins): a queued notice is keyed on its plugin id, not its disp…
InstaZDLL 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| //! A plugin telling the user something only they can fix. | ||
| //! | ||
| //! Plugins that sign in with a credential the user pasted (a cookie, a | ||
| //! token) can have it expire or be revoked. Until now that looked exactly | ||
| //! like "no result": the plugin logged a warning nobody reads, and the | ||
| //! Canvas or the lyrics simply stopped appearing. | ||
| //! | ||
| //! The contract is a prefix on the error string a plugin returns: | ||
| //! [`AUTH_REQUIRED_PREFIX`]. The host turns it into one toast, **once per | ||
| //! launch and per plugin** — the failure repeats on every track, the | ||
| //! notice must not. Every other error keeps its old meaning (logged, | ||
| //! skipped), and a host older than this contract logs the prefixed one | ||
| //! the same way, so a plugin can adopt it without dropping support for | ||
| //! older hosts. | ||
|
|
||
| use std::collections::HashSet; | ||
| use std::sync::{Mutex, OnceLock}; | ||
|
|
||
| use serde::Serialize; | ||
| use tauri::{AppHandle, Emitter}; | ||
| use waveflow_core::plugin::runtime::SourceError; | ||
|
|
||
| /// Start of a plugin error that means "the credential you gave me was | ||
| /// refused; paste a new one". | ||
| pub const AUTH_REQUIRED_PREFIX: &str = "auth-required:"; | ||
|
|
||
| const EVENT: &str = "plugin:attention"; | ||
|
|
||
| static APP: OnceLock<AppHandle> = OnceLock::new(); | ||
| static ANNOUNCED: Mutex<Option<HashSet<String>>> = Mutex::new(None); | ||
| /// The same notices, in order, for a window that starts listening after | ||
| /// they were emitted. Announced once per launch means an event nobody | ||
| /// heard is never sent again, and the first lookup at startup can race | ||
| /// the listener's registration. | ||
| static HISTORY: Mutex<Vec<String>> = Mutex::new(Vec::new()); | ||
|
|
||
| #[derive(Clone, Serialize)] | ||
| #[serde(rename_all = "camelCase")] | ||
| struct AttentionPayload<'a> { | ||
| plugin_id: &'a str, | ||
| kind: &'static str, | ||
| } | ||
|
|
||
| /// Called once at startup, so a plugin path without an `AppHandle` in | ||
| /// reach (the lyrics waterfall) can still announce. | ||
| pub fn init(app: AppHandle) { | ||
| let _ = APP.set(app); | ||
| } | ||
|
|
||
| /// Whether `err` is the plugin saying its credential was refused. | ||
| pub fn is_auth_required(err: &SourceError) -> bool { | ||
| matches!(err, SourceError::Plugin(msg) if msg.starts_with(AUTH_REQUIRED_PREFIX)) | ||
| } | ||
|
|
||
| /// Announce `err` to the user when it is an auth-required error, the first | ||
| /// time this plugin raises one in this launch. Returns whether it was one, | ||
| /// so the caller can skip its generic log line. | ||
| pub fn inspect(plugin_id: &str, err: &SourceError) -> bool { | ||
| if !is_auth_required(err) { | ||
| return false; | ||
| } | ||
| let first = { | ||
| let Ok(mut guard) = ANNOUNCED.lock() else { | ||
| return true; | ||
| }; | ||
| guard | ||
| .get_or_insert_with(HashSet::new) | ||
| .insert(plugin_id.to_string()) | ||
| }; | ||
| if first { | ||
| if let Ok(mut history) = HISTORY.lock() { | ||
| history.push(plugin_id.to_string()); | ||
| } | ||
| tracing::warn!( | ||
| plugin_id, | ||
| err = %err.detail(), | ||
| "plugin credential refused; asking the user for a new one" | ||
| ); | ||
| if let Some(app) = APP.get() { | ||
| let _ = app.emit( | ||
| EVENT, | ||
| AttentionPayload { | ||
| plugin_id, | ||
| kind: "auth-required", | ||
| }, | ||
| ); | ||
| } | ||
| } else { | ||
| tracing::debug!(plugin_id, "plugin credential still refused"); | ||
| } | ||
| true | ||
| } | ||
|
|
||
| /// The plugins whose credential was refused in this launch, in the order | ||
| /// they were announced. The notice reads this once it is listening, and | ||
| /// shows whichever it has not shown yet. | ||
| #[tauri::command] | ||
| pub fn plugin_attention_history() -> Vec<String> { | ||
| HISTORY.lock().map(|h| h.clone()).unwrap_or_default() | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn only_the_prefixed_plugin_error_asks_for_a_credential() { | ||
| assert!(is_auth_required(&SourceError::Plugin( | ||
| "auth-required: sp_dc refused".into() | ||
| ))); | ||
| assert!(!is_auth_required(&SourceError::Plugin( | ||
| "network timeout".into() | ||
| ))); | ||
| assert!(!is_auth_required(&SourceError::Trap( | ||
| "auth-required: not from a trap".into() | ||
| ))); | ||
| } | ||
| } | ||
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.
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.
Uh oh!
There was an error while loading. Please reload this page.