refactor(engine): audit and rationalize platform cfg gates (closes #49)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -23,6 +23,7 @@ use crate::events::{
|
||||
WinStreakMilestoneEvent,
|
||||
};
|
||||
use crate::game_plugin::GameMutation;
|
||||
use crate::platform::ClipboardBackendResource;
|
||||
use crate::progress_plugin::ProgressResource;
|
||||
use crate::font_plugin::FontResource;
|
||||
use crate::resources::GameStateResource;
|
||||
@@ -77,8 +78,8 @@ pub struct ReplayHistoryResource(pub ReplayHistory);
|
||||
|
||||
/// Marker on the "Copy share link" button inside the Stats modal.
|
||||
/// Click reads the share URL from the currently-selected replay
|
||||
/// (`history.0.replays[selected.0].share_url`) and writes it to the
|
||||
/// OS clipboard via `arboard`, surfacing a confirmation toast. The
|
||||
/// (`history.0.replays[selected.0].share_url`) and writes it through the
|
||||
/// active platform clipboard backend, surfacing a confirmation toast. The
|
||||
/// share URL is populated by `sync_plugin::poll_replay_upload_result`
|
||||
/// when the corresponding win's upload completes and is persisted to
|
||||
/// `replays.json` so it survives a restart.
|
||||
@@ -309,19 +310,19 @@ fn refresh_replay_history_on_win(
|
||||
/// resets the live game to the recorded deal and ticks through the
|
||||
/// move list via [`crate::replay_playback`]; the
|
||||
/// [`crate::replay_overlay`] banner surfaces while playback runs.
|
||||
/// Copies the currently-selected replay's `share_url` to the OS
|
||||
/// clipboard via `arboard` and surfaces a confirmation toast. When no
|
||||
/// URL is in hand on the selected entry (replay never uploaded — the
|
||||
/// player won on a local-only backend, the upload failed, or the
|
||||
/// Copies the currently-selected replay's `share_url` through the
|
||||
/// active platform clipboard backend and surfaces a confirmation toast.
|
||||
/// When no URL is in hand on the selected entry (replay never uploaded
|
||||
/// — the player won on a local-only backend, the upload failed, or the
|
||||
/// replay pre-dates v0.19.0 share-link persistence) the button still
|
||||
/// acknowledges the click but explains why the clipboard wasn't
|
||||
/// written. `arboard::Clipboard::new()` failures are logged + surfaced
|
||||
/// as a generic "couldn't reach the clipboard" toast rather than
|
||||
/// swallowed — they're rare but worth diagnosing.
|
||||
/// written. Backend failures are logged and fall back to surfacing the
|
||||
/// share URL directly in a toast.
|
||||
fn handle_copy_share_link_button(
|
||||
buttons: Query<&Interaction, (With<CopyShareLinkButton>, Changed<Interaction>)>,
|
||||
history: Res<ReplayHistoryResource>,
|
||||
selected: Res<SelectedReplayIndex>,
|
||||
clipboard: Option<Res<ClipboardBackendResource>>,
|
||||
mut toast: MessageWriter<InfoToastEvent>,
|
||||
) {
|
||||
if !buttons.iter().any(|i| *i == Interaction::Pressed) {
|
||||
@@ -339,42 +340,18 @@ fn handle_copy_share_link_button(
|
||||
return;
|
||||
};
|
||||
|
||||
// Desktop: `arboard` writes the URL to the OS clipboard.
|
||||
// Android: `arboard` has no platform backend (would fail to
|
||||
// compile, so the dependency is target-gated in
|
||||
// solitaire_engine/Cargo.toml). The button still spawns and
|
||||
// resolves to a meaningful toast instead — when we wire the
|
||||
// Android Phase, this becomes a JNI call into ClipboardManager.
|
||||
#[cfg(not(target_os = "android"))]
|
||||
{
|
||||
match arboard::Clipboard::new() {
|
||||
Ok(mut cb) => match cb.set_text(url.clone()) {
|
||||
Ok(()) => {
|
||||
toast.write(InfoToastEvent(format!("Copied: {url}")));
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("clipboard write failed: {e}");
|
||||
toast.write(InfoToastEvent(
|
||||
"Couldn't write to clipboard \u{2014} share link wasn't copied.".to_string(),
|
||||
));
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
warn!("clipboard init failed: {e}");
|
||||
toast.write(InfoToastEvent(
|
||||
"Couldn't reach the clipboard \u{2014} share link wasn't copied.".to_string(),
|
||||
));
|
||||
}
|
||||
let Some(clipboard) = clipboard else {
|
||||
toast.write(InfoToastEvent(format!("Share link: {url}")));
|
||||
return;
|
||||
};
|
||||
|
||||
match clipboard.0.set_text(url) {
|
||||
Ok(()) => {
|
||||
toast.write(InfoToastEvent(format!("Copied: {url}")));
|
||||
}
|
||||
}
|
||||
#[cfg(target_os = "android")]
|
||||
{
|
||||
match crate::android_clipboard::set_text(&url) {
|
||||
Ok(()) => { toast.write(InfoToastEvent(format!("Copied: {url}"))); }
|
||||
Err(e) => {
|
||||
warn!("android clipboard failed: {e}");
|
||||
toast.write(InfoToastEvent(format!("Share link: {url}")));
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("clipboard write failed: {e}");
|
||||
toast.write(InfoToastEvent(format!("Share link: {url}")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user