| 1 |
|
- |
//! Sync settings panel: egui Window overlay with 4 states matching the SyncKit flow.
|
| 2 |
|
- |
|
| 3 |
|
- |
use egui;
|
| 4 |
|
- |
use makeover_immediate;
|
| 5 |
|
- |
use makeover_layout;
|
| 6 |
|
- |
use tracing::{error, warn};
|
| 7 |
|
- |
|
| 8 |
|
- |
use audiofiles_sync::{AppPricing, BillingInterval, SyncManager, SyncState, SyncStatus};
|
| 9 |
|
- |
|
| 10 |
|
- |
use crate::state::{BrowserState, ConfirmAction};
|
| 11 |
|
- |
use crate::storage_cap;
|
| 12 |
|
- |
use crate::ui::theme;
|
| 13 |
|
- |
use crate::ui::widgets;
|
| 14 |
|
- |
|
| 15 |
|
- |
const GIB: i64 = 1024 * 1024 * 1024;
|
| 16 |
|
- |
|
| 17 |
|
- |
fn format_cents(cents: i64) -> String {
|
| 18 |
|
- |
let dollars = cents / 100;
|
| 19 |
|
- |
let pennies = cents % 100;
|
| 20 |
|
- |
if pennies == 0 {
|
| 21 |
|
- |
format!("${dollars}")
|
| 22 |
|
- |
} else {
|
| 23 |
|
- |
format!("${dollars}.{pennies:02}")
|
| 24 |
|
- |
}
|
| 25 |
|
- |
}
|
| 26 |
|
- |
|
| 27 |
|
- |
fn format_cap(cap_bytes: i64) -> String {
|
| 28 |
|
- |
let gib = cap_bytes / GIB;
|
| 29 |
|
- |
if gib >= 1024 {
|
| 30 |
|
- |
format!("{:.1} TiB", gib as f64 / 1024.0)
|
| 31 |
|
- |
} else {
|
| 32 |
|
- |
format!("{gib} GiB")
|
| 33 |
|
- |
}
|
| 34 |
|
- |
}
|
| 35 |
|
- |
|
| 36 |
|
- |
/// Whether the encryption form can submit, and what is wrong with which field.
|
| 37 |
|
- |
///
|
| 38 |
|
- |
/// The two messages are held apart rather than returned as one hint because
|
| 39 |
|
- |
/// they belong to different questions: a password too short is wrong with the
|
| 40 |
|
- |
/// password, and a mismatch is only ever wrong with the confirmation. A
|
| 41 |
|
- |
/// described field carries its own error, so a single message would have to be
|
| 42 |
|
- |
/// drawn detached from both fields to stay truthful — which is what this form
|
| 43 |
|
- |
/// did before it was described.
|
| 44 |
|
- |
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
| 45 |
|
- |
struct EncryptionForm {
|
| 46 |
|
- |
can_submit: bool,
|
| 47 |
|
- |
password_error: Option<&'static str>,
|
| 48 |
|
- |
confirm_error: Option<&'static str>,
|
| 49 |
|
- |
}
|
| 50 |
|
- |
|
| 51 |
|
- |
impl EncryptionForm {
|
| 52 |
|
- |
const SILENT: Self = Self {
|
| 53 |
|
- |
can_submit: false,
|
| 54 |
|
- |
password_error: None,
|
| 55 |
|
- |
confirm_error: None,
|
| 56 |
|
- |
};
|
| 57 |
|
- |
}
|
| 58 |
|
- |
|
| 59 |
|
- |
/// Decide whether the encryption form can submit, and which field is wrong.
|
| 60 |
|
- |
/// Unlock (`has_server_key`) only needs a non-empty password. First-time setup
|
| 61 |
|
- |
/// requires a >=8-char password confirmed by a matching second entry; both
|
| 62 |
|
- |
/// errors stay `None` while the user is still mid-entry (so no error flashes
|
| 63 |
|
- |
/// prematurely).
|
| 64 |
|
- |
fn encryption_submit_state(has_server_key: bool, pw: &str, confirm: &str) -> EncryptionForm {
|
| 65 |
|
- |
if has_server_key {
|
| 66 |
|
- |
return EncryptionForm {
|
| 67 |
|
- |
can_submit: !pw.is_empty(),
|
| 68 |
|
- |
..EncryptionForm::SILENT
|
| 69 |
|
- |
};
|
| 70 |
|
- |
}
|
| 71 |
|
- |
if pw.is_empty() {
|
| 72 |
|
- |
EncryptionForm::SILENT
|
| 73 |
|
- |
} else if pw.len() < 8 {
|
| 74 |
|
- |
EncryptionForm {
|
| 75 |
|
- |
password_error: Some("Password must be at least 8 characters."),
|
| 76 |
|
- |
..EncryptionForm::SILENT
|
| 77 |
|
- |
}
|
| 78 |
|
- |
} else if confirm.is_empty() {
|
| 79 |
|
- |
EncryptionForm::SILENT
|
| 80 |
|
- |
} else if pw != confirm {
|
| 81 |
|
- |
EncryptionForm {
|
| 82 |
|
- |
confirm_error: Some("Passwords don't match."),
|
| 83 |
|
- |
..EncryptionForm::SILENT
|
| 84 |
|
- |
}
|
| 85 |
|
- |
} else {
|
| 86 |
|
- |
EncryptionForm {
|
| 87 |
|
- |
can_submit: true,
|
| 88 |
|
- |
..EncryptionForm::SILENT
|
| 89 |
|
- |
}
|
| 90 |
|
- |
}
|
| 91 |
|
- |
}
|
| 92 |
|
- |
|
| 93 |
|
- |
/// Draw the sync settings panel as a floating window.
|
| 94 |
|
- |
pub fn draw_sync_panel(ctx: &egui::Context, state: &mut BrowserState, sync: &SyncManager) {
|
| 95 |
|
- |
// Consume any pending disconnect set by execute_confirmed_action last frame.
|
| 96 |
|
- |
// The confirm dispatcher in bulk_ops.rs runs without a SyncManager handle,
|
| 97 |
|
- |
// so the actual sync.disconnect() lands here.
|
| 98 |
|
- |
if state.sync.pending_disconnect {
|
| 99 |
|
- |
state.sync.pending_disconnect = false;
|
| 100 |
|
- |
sync.disconnect();
|
| 101 |
|
- |
state.status = "Disconnected from cloud sync.".to_string();
|
| 102 |
|
- |
}
|
| 103 |
|
- |
|
| 104 |
|
- |
// Drop the cached auth URL once we've left the Authenticating state. It's
|
| 105 |
|
- |
// only meaningful while the Copy URL fallback is on screen, and lingering
|
| 106 |
|
- |
// would leak the PKCE state into a stale display if the user reopens the
|
| 107 |
|
- |
// panel later.
|
| 108 |
|
- |
if !matches!(sync.status().state, SyncState::Authenticating) && state.sync.auth_url.is_some() {
|
| 109 |
|
- |
state.sync.auth_url = None;
|
| 110 |
|
- |
}
|
| 111 |
|
- |
|
| 112 |
|
- |
// Drop the per-VFS storage cache when the panel closes so reopening fetches
|
| 113 |
|
- |
// fresh numbers (the user may have imported/deleted between sessions).
|
| 114 |
|
- |
if !state.sync.show_panel {
|
| 115 |
|
- |
state.sync.vfs_storage_fetched = false;
|
| 116 |
|
- |
state.sync.vfs_storage_cache.clear();
|
| 117 |
|
- |
state.sync.synced_bytes = None;
|
| 118 |
|
- |
state.sync.cap_picker_gib = None;
|
| 119 |
|
- |
}
|
| 120 |
|
- |
|
| 121 |
|
- |
let mut open = state.sync.show_panel;
|
| 122 |
|
- |
widgets::modal_window_with_open(
|
| 123 |
|
- |
ctx,
|
| 124 |
|
- |
"Cloud Sync",
|
| 125 |
|
- |
Some(&mut open),
|
| 126 |
|
- |
false,
|
| 127 |
|
- |
Some(360.0),
|
| 128 |
|
- |
|ui| {
|
| 129 |
|
- |
let status = sync.status();
|
| 130 |
|
- |
|
| 131 |
|
- |
match &status.state {
|
| 132 |
|
- |
SyncState::Disconnected => {
|
| 133 |
|
- |
draw_disconnected(ui, state, sync);
|
| 134 |
|
- |
}
|
| 135 |
|
- |
SyncState::Authenticating => {
|
| 136 |
|
- |
draw_authenticating(ui, state, sync);
|
| 137 |
|
- |
}
|
| 138 |
|
- |
SyncState::NeedsEncryption { has_server_key } => {
|
| 139 |
|
- |
draw_needs_encryption(ui, state, sync, *has_server_key);
|
| 140 |
|
- |
}
|
| 141 |
|
- |
SyncState::Ready | SyncState::Syncing => {
|
| 142 |
|
- |
draw_ready(ui, state, sync, &status);
|
| 143 |
|
- |
}
|
| 144 |
|
- |
}
|
| 145 |
|
- |
|
| 146 |
|
- |
// Error banner with Retry + Dismiss. Retry is only meaningful in
|
| 147 |
|
- |
// Ready/Syncing state (calls sync_now); in other states the user's
|
| 148 |
|
- |
// primary action is already on screen (Connect, Set Password), so
|
| 149 |
|
- |
// Retry hides itself and Dismiss is the only escape.
|
| 150 |
|
- |
if let Some(err) = status.last_error.clone() {
|
| 151 |
|
- |
ui.add_space(theme::space::bound());
|
| 152 |
|
- |
ui.separator();
|
| 153 |
|
- |
ui.add_space(theme::space::bound());
|
| 154 |
|
- |
widgets::raised_frame(ui, |ui| {
|
| 155 |
|
- |
ui.label(egui::RichText::new(err).color(theme::danger()));
|
| 156 |
|
- |
ui.add_space(theme::space::bound());
|
| 157 |
|
- |
ui.horizontal(|ui| {
|
| 158 |
|
- |
let retryable =
|
| 159 |
|
- |
matches!(status.state, SyncState::Ready | SyncState::Syncing,);
|
| 160 |
|
- |
if retryable && widgets::secondary_button(ui, "Retry").clicked() {
|
| 161 |
|
- |
sync.clear_last_error();
|
| 162 |
|
- |
sync.sync_now();
|
| 163 |
|
- |
}
|
| 164 |
|
- |
if widgets::secondary_button(ui, "Dismiss").clicked() {
|
| 165 |
|
- |
sync.clear_last_error();
|
| 166 |
|
- |
}
|
| 167 |
|
- |
});
|
| 168 |
|
- |
});
|
| 169 |
|
- |
}
|
| 170 |
|
- |
},
|
| 171 |
|
- |
);
|
| 172 |
|
- |
state.sync.show_panel = open;
|
| 173 |
|
- |
}
|
| 174 |
|
- |
|
| 175 |
|
- |
/// Draw the subscription status/purchase section for blob sync.
|
| 176 |
|
- |
fn draw_subscription_section(ui: &mut egui::Ui, state: &mut BrowserState, sync: &SyncManager) {
|
| 177 |
|
- |
let sync_status = sync.status();
|
| 178 |
|
- |
|
| 179 |
|
- |
// Loading-flag timeout: if a fetch or checkout never resolves, the panel
|
| 180 |
|
- |
// would otherwise spin "Checking subscription..." (or grey out every
|
| 181 |
|
- |
// Subscribe button) forever. After 30s without a response, clear the flag
|
| 182 |
|
- |
// so the user can retry. The status message is the only feedback channel
|
| 183 |
|
- |
// for this surface, see C-3's wiring of the same pattern.
|
| 184 |
|
- |
const LOADING_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(30);
|
| 185 |
|
- |
if let Some(at) = state.sync.subscription_loading_at
|
| 186 |
|
- |
&& at.elapsed() >= LOADING_TIMEOUT
|
| 187 |
|
- |
&& sync_status.subscription.is_none()
|
| 188 |
|
- |
{
|
| 189 |
|
- |
state.sync.subscription_loading = false;
|
| 190 |
|
- |
state.sync.subscription_loading_at = None;
|
| 191 |
|
- |
state.status = "Subscription check timed out. Click Retry to try again.".to_string();
|
| 192 |
|
- |
}
|
| 193 |
|
- |
if let Some(at) = state.sync.checkout_loading_at
|
| 194 |
|
- |
&& at.elapsed() >= LOADING_TIMEOUT
|
| 195 |
|
- |
{
|
| 196 |
|
- |
state.sync.checkout_loading = false;
|
| 197 |
|
- |
state.sync.checkout_loading_at = None;
|
| 198 |
|
- |
state.status =
|
| 199 |
|
- |
"Checkout timed out. The browser tab may have closed; try again.".to_string();
|
| 200 |
|
- |
}
|
| 201 |
|
- |
// If the checkout / cap-change call reported an error, the sync manager surfaces
|
| 202 |
|
- |
// it in `last_error` (shown by the error banner above). Clear the checkout
|
| 203 |
|
- |
// loading flag immediately so the Subscribe / cap-change button re-enables for a
|
| 204 |
|
- |
// retry, rather than staying greyed out until the 30s timeout above. (Only the
|
| 205 |
|
- |
// checkout flag, subscription fetch failures don't set `last_error`, so a
|
| 206 |
|
- |
// general sync error must not interrupt the "Checking subscription..." spinner.)
|
| 207 |
|
- |
if sync_status.last_error.is_some() && state.sync.checkout_loading {
|
| 208 |
|
- |
state.sync.checkout_loading = false;
|
| 209 |
|
- |
state.sync.checkout_loading_at = None;
|
| 210 |
|
- |
}
|
| 211 |
|
- |
|
| 212 |
|
- |
// Trigger initial fetch if not yet loaded
|
| 213 |
|
- |
if sync_status.subscription.is_none() && !state.sync.subscription_loading {
|
| 214 |
|
- |
state.sync.subscription_loading = true;
|
| 215 |
|
- |
state.sync.subscription_loading_at = Some(std::time::Instant::now());
|
| 216 |
|
- |
sync.fetch_subscription_status();
|
| 217 |
|
- |
}
|
| 218 |
|
- |
|
| 219 |
|
- |
if state.sync.subscription_loading && sync_status.subscription.is_none() {
|
| 220 |
|
- |
ui.horizontal(|ui| {
|
| 221 |
|
- |
ui.label(egui::RichText::new("Checking subscription...").weak());
|
| 222 |
|
- |
if ui.small_button("Retry").clicked() {
|
| 223 |
|
- |
state.sync.subscription_loading_at = Some(std::time::Instant::now());
|
| 224 |
|
- |
sync.fetch_subscription_status();
|
| 225 |
|
- |
}
|
| 226 |
|
- |
});
|
| 227 |
|
- |
return;
|
| 228 |
|
- |
}
|
| 229 |
|
- |
|
| 230 |
|
- |
// Once loaded, clear loading flags
|
| 231 |
|
- |
if sync_status.subscription.is_some() {
|
| 232 |
|
- |
state.sync.subscription_loading = false;
|
| 233 |
|
- |
state.sync.subscription_loading_at = None;
|
| 234 |
|
- |
state.sync.checkout_loading = false;
|
| 235 |
|
- |
state.sync.checkout_loading_at = None;
|
| 236 |
|
- |
}
|
| 237 |
|
- |
|
| 238 |
|
- |
match &sync_status.subscription {
|
| 239 |
|
- |
Some(sub) if sub.active => {
|
| 240 |
|
- |
let limit = sub.storage_limit_bytes.unwrap_or(0);
|
| 241 |
|
- |
let used = sub.storage_used_bytes.unwrap_or(0);
|
| 242 |
|
- |
let interval = sub
|
| 243 |
|
- |
.interval
|
| 244 |
|
- |
.map_or("monthly", audiofiles_sync::BillingInterval::as_str);
|
| 245 |
|
- |
|
| 246 |
|
- |
ui.label(format!("Subscribed: {} ({})", format_cap(limit), interval));
|
| 247 |
|
- |
|
| 248 |
|
- |
if limit > 0 {
|
| 249 |
|
- |
let used_gb = used as f64 / GIB as f64;
|
| 250 |
|
- |
let limit_gb = limit as f64 / GIB as f64;
|
| 251 |
|
- |
let fraction = (used as f32) / (limit as f32);
|
| 252 |
|
- |
ui.add(
|
| 253 |
|
- |
egui::ProgressBar::new(fraction)
|
| 254 |
|
- |
.text(format!("{used_gb:.1} / {limit_gb:.0} GiB")),
|
| 255 |
|
- |
);
|
| 256 |
|
- |
}
|
| 257 |
|
- |
|
| 258 |
|
- |
if let Some(pending) = sub.pending_storage_limit_bytes {
|
| 259 |
|
- |
ui.add_space(theme::space::hair());
|
| 260 |
|
- |
ui.label(
|
| 261 |
|
- |
egui::RichText::new(format!(
|
| 262 |
|
- |
"Pending: cap changes to {} at next renewal.",
|
| 263 |
|
- |
format_cap(pending)
|
| 264 |
|
- |
))
|
| 265 |
|
- |
.weak(),
|
| 266 |
|
- |
);
|
| 267 |
|
- |
}
|
| 268 |
|
- |
|
| 269 |
|
- |
// Say what a filling cap means before the upload that fails says it.
|
| 270 |
|
- |
// Without this the first news is a 402 from the blob route, which the
|
| 271 |
|
- |
// user meets as a sync that broke rather than a cap that filled.
|
| 272 |
|
- |
if storage_cap::nearly_full(used, limit) {
|
| 273 |
|
- |
ui.add_space(theme::space::hair());
|
| 274 |
|
- |
let full = used >= limit;
|
| 275 |
|
- |
let text = if full {
|
| 276 |
|
- |
"Your storage cap is full. New sample files are not uploading; \
|
| 277 |
|
- |
everything else still syncs."
|
| 278 |
|
- |
} else {
|
| 279 |
|
- |
"You are close to your storage cap. When it fills, new sample \
|
| 280 |
|
- |
files stop uploading and everything else keeps syncing."
|
| 281 |
|
- |
};
|
| 282 |
|
- |
ui.label(egui::RichText::new(text).color(if full {
|
| 283 |
|
- |
theme::danger()
|
| 284 |
|
- |
} else {
|
| 285 |
|
- |
theme::warning()
|
| 286 |
|
- |
}));
|
| 287 |
|
- |
}
|
| 288 |
|
- |
|
| 289 |
|
- |
// Cap change for subscribed users.
|
| 290 |
|
- |
if let Some(pricing) = &sync_status.pricing {
|
| 291 |
|
- |
let pricing = pricing.clone();
|
| 292 |
|
- |
let interval_enum = BillingInterval::from_wire(interval);
|
| 293 |
|
- |
ui.add_space(theme::space::peer());
|
| 294 |
|
- |
ui.label(egui::RichText::new("Adjust cap:").weak());
|
| 295 |
|
- |
ui.label(
|
| 296 |
|
- |
egui::RichText::new(
|
| 297 |
|
- |
"An increase applies now. A decrease takes effect next cycle.",
|
| 298 |
|
- |
)
|
| 299 |
|
- |
.small()
|
| 300 |
|
- |
.color(theme::content_muted()),
|
| 301 |
|
- |
);
|
| 302 |
|
- |
|
| 303 |
|
- |
// A cap that no longer covers the library is the one case where
|
| 304 |
|
- |
// re-proposing over the user's own answer is the point.
|
| 305 |
|
- |
if storage_cap::nearly_full(used, limit) {
|
| 306 |
|
- |
let need = synced_need(state);
|
| 307 |
|
- |
let proposed =
|
| 308 |
|
- |
storage_cap::proposed(need, pricing.min_cap_bytes, pricing.max_cap_bytes);
|
| 309 |
|
- |
if proposed > limit {
|
| 310 |
|
- |
ui.label(
|
| 311 |
|
- |
egui::RichText::new(format!(
|
| 312 |
|
- |
"{} would hold it, at {}/{}.",
|
| 313 |
|
- |
format_cap(proposed),
|
| 314 |
|
- |
format_cents(pricing.quote_cents(proposed, interval_enum).0),
|
| 315 |
|
- |
match interval_enum {
|
| 316 |
|
- |
BillingInterval::Monthly => "mo",
|
| 317 |
|
- |
BillingInterval::Annual => "yr",
|
| 318 |
|
- |
}
|
| 319 |
|
- |
))
|
| 320 |
|
- |
.color(theme::content_muted()),
|
| 321 |
|
- |
);
|
| 322 |
|
- |
}
|
| 323 |
|
- |
}
|
| 324 |
|
- |
|
| 325 |
|
- |
ui.add_space(theme::space::hair());
|
| 326 |
|
- |
let cap = draw_cap_choice(ui, state, &pricing, interval_enum);
|
| 327 |
|
- |
ui.add_space(theme::space::hair());
|
| 328 |
|
- |
let loading = state.sync.checkout_loading;
|
| 329 |
|
- |
if ui
|
| 330 |
|
- |
.add_enabled_ui(!loading, |ui| widgets::primary_button(ui, "Update cap"))
|
| 331 |
|
- |
.inner
|
| 332 |
|
- |
.clicked()
|
| 333 |
|
- |
{
|
| 334 |
|
- |
sync.queue_cap_change(cap);
|
| 335 |
|
- |
}
|
| 336 |
|
- |
}
|
| 337 |
|
- |
}
|
| 338 |
|
- |
_ => {
|
| 339 |
|
- |
if let Some(pricing) = &sync_status.pricing {
|
| 340 |
|
- |
let pricing = pricing.clone();
|
| 341 |
|
- |
// State the need first: it is why the cap below it says what it
|
| 342 |
|
- |
// says, and the app knows it exactly.
|
| 343 |
|
- |
let need = synced_need(state);
|
| 344 |
|
- |
draw_need(ui, need);
|
| 345 |
|
- |
ui.add_space(theme::space::hair());
|
| 346 |
|
- |
ui.label(
|
| 347 |
|
- |
egui::RichText::new(
|
| 348 |
|
- |
"Annual is 2 months free, so fewer Stripe fees, and we pass the savings on.",
|
| 349 |
|
- |
)
|
| 350 |
|
- |
.weak()
|
| 351 |
|
- |
.size(11.0),
|
| 352 |
|
- |
);
|
| 353 |
|
- |
ui.add_space(theme::space::bound());
|
| 354 |
|
- |
|
| 355 |
|
- |
// Named sizes, each carrying its price at the annual rate, since
|
| 356 |
|
- |
// annual is the recommendation; the monthly figure is on the
|
| 357 |
|
- |
// button below. Replaces a logarithmic slider that asked the user
|
| 358 |
|
- |
// to sweep three orders of magnitude to reach a number the app
|
| 359 |
|
- |
// could already compute.
|
| 360 |
|
- |
let cap_bytes = draw_cap_choice(ui, state, &pricing, BillingInterval::Annual);
|
| 361 |
|
- |
ui.add_space(theme::space::bound());
|
| 362 |
|
- |
|
| 363 |
|
- |
if state.sync.checkout_loading {
|
| 364 |
|
- |
ui.horizontal(|ui| {
|
| 365 |
|
- |
ui.spinner();
|
| 366 |
|
- |
ui.label(egui::RichText::new("Opening browser...").weak());
|
| 367 |
|
- |
});
|
| 368 |
|
- |
} else {
|
| 369 |
|
- |
let annual =
|
| 370 |
|
- |
format_cents(pricing.quote_cents(cap_bytes, BillingInterval::Annual).0);
|
| 371 |
|
- |
let monthly =
|
| 372 |
|
- |
format_cents(pricing.quote_cents(cap_bytes, BillingInterval::Monthly).0);
|
| 373 |
|
- |
ui.horizontal(|ui| {
|
| 374 |
|
- |
if widgets::primary_button(
|
| 375 |
|
- |
ui,
|
| 376 |
|
- |
&format!("Subscribe annual \u{2014} {annual}/yr"),
|
| 377 |
|
- |
)
|
| 378 |
|
- |
.clicked()
|
| 379 |
|
- |
{
|
| 380 |
|
- |
state.sync.checkout_loading = true;
|
| 381 |
|
- |
state.sync.checkout_loading_at = Some(std::time::Instant::now());
|
| 382 |
|
- |
sync.subscribe(cap_bytes, BillingInterval::Annual);
|
| 383 |
|
- |
}
|
| 384 |
|
- |
if widgets::secondary_button(ui, &format!("Monthly \u{2014} {monthly}/mo"))
|
| 385 |
|
- |
.clicked()
|
| 386 |
|
- |
{
|
| 387 |
|
- |
state.sync.checkout_loading = true;
|
| 388 |
|
- |
state.sync.checkout_loading_at = Some(std::time::Instant::now());
|
| 389 |
|
- |
sync.subscribe(cap_bytes, BillingInterval::Monthly);
|
| 390 |
|
- |
}
|
| 391 |
|
- |
});
|
| 392 |
|
- |
}
|
| 393 |
|
- |
} else {
|
| 394 |
|
- |
ui.label(egui::RichText::new("Loading pricing...").weak());
|
| 395 |
|
- |
}
|
| 396 |
|
- |
}
|
| 397 |
|
- |
}
|
| 398 |
|
- |
}
|
| 399 |
|
- |
|
| 400 |
|
- |
/// Draw a fallback panel when no SyncManager is available (no embedded API key in dev builds).
|
| 401 |
|
- |
pub fn draw_sync_not_configured(ctx: &egui::Context, state: &mut BrowserState) {
|
| 402 |
|
- |
let mut open = state.sync.show_panel;
|
| 403 |
|
- |
widgets::modal_window_with_open(
|
| 404 |
|
- |
ctx,
|
| 405 |
|
- |
"Cloud Sync",
|
| 406 |
|
- |
Some(&mut open),
|
| 407 |
|
- |
false,
|
| 408 |
|
- |
Some(380.0),
|
| 409 |
|
- |
|ui| {
|
| 410 |
|
- |
ui.label("Cloud sync is unavailable.");
|
| 411 |
|
- |
ui.add_space(theme::space::peer());
|
| 412 |
|
- |
ui.label(
|
| 413 |
|
- |
egui::RichText::new("Open a vault to enable sync.")
|
| 414 |
|
- |
.small()
|
| 415 |
|
- |
.weak(),
|
| 416 |
|
- |
);
|
| 417 |
|
- |
},
|
| 418 |
|
- |
);
|
| 419 |
|
- |
state.sync.show_panel = open;
|
| 420 |
|
- |
}
|
| 421 |
|
- |
|
| 422 |
|
- |
/// Disconnected state: invite user to connect.
|
| 423 |
|
- |
fn draw_disconnected(ui: &mut egui::Ui, state: &mut BrowserState, sync: &SyncManager) {
|
| 424 |
|
- |
ui.label("Connect your audiofiles vault to Makenot.work for cross-device sync.");
|
| 425 |
|
- |
ui.add_space(theme::space::peer());
|
| 426 |
|
- |
ui.label(
|
| 427 |
|
- |
egui::RichText::new("Metadata (tags, vault structure, analysis) syncs automatically. Audio file sync is per-vault opt-in.")
|
| 428 |
|
- |
.small()
|
| 429 |
|
- |
.weak(),
|
| 430 |
|
- |
);
|
| 431 |
|
- |
ui.add_space(theme::space::group());
|
| 432 |
|
- |
if ui.button("Connect").clicked() {
|
| 433 |
|
- |
match sync.start_auth() {
|
| 434 |
|
- |
Ok(auth_url) => {
|
| 435 |
|
- |
#[cfg(target_os = "macos")]
|
| 436 |
|
- |
let _ = std::process::Command::new("open").arg(&auth_url).spawn();
|
| 437 |
|
- |
#[cfg(target_os = "linux")]
|
| 438 |
|
- |
let _ = std::process::Command::new("xdg-open")
|
| 439 |
|
- |
.arg(&auth_url)
|
| 440 |
|
- |
.spawn();
|
| 441 |
|
- |
#[cfg(target_os = "windows")]
|
| 442 |
|
- |
let _ = std::process::Command::new("cmd")
|
| 443 |
|
- |
.args(["/c", "start", &auth_url])
|
| 444 |
|
- |
.spawn();
|
| 445 |
|
- |
state.sync.auth_code_input.clear();
|
| 446 |
|
- |
// Cache for the Authenticating screen's "Copy URL" fallback,
|
| 447 |
|
- |
// the browser may have failed to open silently.
|
| 448 |
|
- |
state.sync.auth_url = Some(auth_url);
|
| 449 |
|
- |
}
|
| 450 |
|
- |
Err(e) => {
|
| 451 |
|
- |
error!("Failed to start auth: {e}");
|
| 452 |
|
- |
state.status = format!("Sync connect failed: {e}");
|
| 453 |
|
- |
}
|
| 454 |
|
- |
}
|
| 455 |
|
- |
}
|
| 456 |
|
- |
}
|
| 457 |
|
- |
|
| 458 |
|
- |
/// Authenticating state: waiting for OAuth callback, with Cancel + Copy URL
|
| 459 |
|
- |
/// escape hatches. Without these the user could be trapped here indefinitely
|
| 460 |
|
- |
/// when the browser doesn't open, OAuth fails server-side, or they change
|
| 461 |
|
- |
/// their mind, closing the window doesn't move the underlying state.
|
| 462 |
|
- |
fn draw_authenticating(ui: &mut egui::Ui, state: &mut BrowserState, sync: &SyncManager) {
|
| 463 |
|
- |
ui.horizontal(|ui| {
|
| 464 |
|
- |
ui.label("Waiting for authentication in your browser...");
|
| 465 |
|
- |
ui.spinner();
|
| 466 |
|
- |
});
|
| 467 |
|
- |
ui.add_space(theme::space::peer());
|
| 468 |
|
- |
ui.label(
|
| 469 |
|
- |
egui::RichText::new("The app will update automatically once you sign in.")
|
| 470 |
|
- |
.small()
|
| 471 |
|
- |
.weak(),
|
| 472 |
|
- |
);
|
| 473 |
|
- |
|
| 474 |
|
- |
// Copy-URL fallback: the browser may have failed to open silently (wrong
|
| 475 |
|
- |
// default browser, headless system, popup blocker on a Tauri host).
|
| 476 |
|
- |
if let Some(ref url) = state.sync.auth_url.clone() {
|
| 477 |
|
- |
ui.add_space(theme::space::peer());
|
| 478 |
|
- |
ui.separator();
|
| 479 |
|
- |
ui.add_space(theme::space::bound());
|
| 480 |
|
- |
ui.label(
|
| 481 |
|
- |
egui::RichText::new("Browser didn't open? Copy this URL into a browser manually.")
|
| 482 |
|
- |
.small()
|
| 483 |
|
- |
.weak(),
|
| 484 |
|
- |
);
|
| 485 |
|
- |
ui.add_space(theme::space::hair());
|
| 486 |
|
- |
ui.horizontal(|ui| {
|
| 487 |
|
- |
// Read-only truncated URL display + Copy button. The URL itself is
|
| 488 |
|
- |
// long (OAuth + PKCE + state) so truncation is necessary.
|
| 489 |
|
- |
let mut shown = url.clone();
|
| 490 |
|
- |
widgets::text_field(
|
| 491 |
|
- |
ui,
|
| 492 |
|
- |
egui::TextEdit::singleline(&mut shown).desired_width(ui.available_width() - 70.0),
|
| 493 |
|
- |
);
|
| 494 |
|
- |
if ui.button("Copy").clicked() {
|
| 495 |
|
- |
ui.ctx().copy_text(url.clone());
|
| 496 |
|
- |
state.status = "Copied auth URL.".to_string();
|
| 497 |
|
- |
}
|
| 498 |
|
- |
});
|
| 499 |
|
- |
}
|
| 500 |
|
- |
|