diff --git a/locales/cs.txt b/locales/cs.txt index dc51923f3..aa1973cf3 100644 --- a/locales/cs.txt +++ b/locales/cs.txt @@ -16,9 +16,6 @@ Můj záměr [profile_progress_title] Aktivita --- -[profile_weekly_insight] -Tento týden jste se zapojili ve %d dnech. ---- [tab_habits] Návyky --- @@ -28,6 +25,9 @@ Cvičení [profile_data] Data --- +[profile_manage_data] +Spravovat data +--- [profile_sync_tab] Synchronizace --- @@ -2256,6 +2256,9 @@ Položky [profile_picture_title] Profilový obrázek --- +[profile_change_picture] +Změnit obrázek +--- [audio_custom_default_title] Vlastní zvuk --- @@ -5791,6 +5794,10 @@ Hlasitěji Úspěchy --- +[achievement_unlocked] +Úspěch odemčen +--- + [achievement_alerts_label] Upozornění na úspěchy --- diff --git a/locales/de.txt b/locales/de.txt index a55bd283f..9de0df25a 100644 --- a/locales/de.txt +++ b/locales/de.txt @@ -16,9 +16,6 @@ Meine Absicht [profile_progress_title] Aktivität --- -[profile_weekly_insight] -Du warst diese Woche an %d Tagen aktiv. ---- [tab_habits] Gewohnheiten --- @@ -28,6 +25,9 @@ Praxis [profile_data] Daten --- +[profile_manage_data] +Daten verwalten +--- [profile_sync_tab] Synchronisierung --- @@ -2256,6 +2256,9 @@ Einträge [profile_picture_title] Profilbild --- +[profile_change_picture] +Bild ändern +--- [audio_custom_default_title] Eigenes Audio --- @@ -5785,6 +5788,10 @@ Lauter Erfolge --- +[achievement_unlocked] +Erfolg freigeschaltet +--- + [achievement_alerts_label] Erfolgsmeldungen --- diff --git a/locales/en.txt b/locales/en.txt index f177ecdcf..ff5f0ebe2 100644 --- a/locales/en.txt +++ b/locales/en.txt @@ -16,9 +16,6 @@ My intention [profile_progress_title] Activity --- -[profile_weekly_insight] -You showed up on %d days this week. ---- [profile_today_short] Today --- @@ -43,6 +40,9 @@ Practice [profile_data] Data --- +[profile_manage_data] +Manage data +--- [profile_sync_tab] Sync --- @@ -2255,6 +2255,9 @@ Items [profile_picture_title] Profile picture --- +[profile_change_picture] +Change picture +--- [audio_custom_default_title] Custom audio --- @@ -5809,6 +5812,10 @@ Louder Achievements --- +[achievement_unlocked] +Achievement unlocked +--- + [achievement_alerts_label] Achievement alerts --- diff --git a/locales/es.txt b/locales/es.txt index 86f2fe963..77958d985 100644 --- a/locales/es.txt +++ b/locales/es.txt @@ -16,9 +16,6 @@ Mi intención [profile_progress_title] Actividad --- -[profile_weekly_insight] -Estuviste presente %d días esta semana. ---- [tab_habits] Hábitos --- @@ -28,6 +25,9 @@ Práctica [profile_data] Datos --- +[profile_manage_data] +Gestionar datos +--- [profile_sync_tab] Sincronización --- @@ -2256,6 +2256,9 @@ Elementos [profile_picture_title] Foto de perfil --- +[profile_change_picture] +Cambiar imagen +--- [audio_custom_default_title] Audio personalizado --- @@ -5785,6 +5788,10 @@ Subir volumen Logros --- +[achievement_unlocked] +Logro desbloqueado +--- + [achievement_alerts_label] Avisos de logros --- diff --git a/locales/fr.txt b/locales/fr.txt index aa7e415c8..dd9874482 100644 --- a/locales/fr.txt +++ b/locales/fr.txt @@ -16,9 +16,6 @@ Mon intention [profile_progress_title] Activité --- -[profile_weekly_insight] -Vous avez été présent pendant %d jours cette semaine. ---- [tab_habits] Habitudes --- @@ -28,6 +25,9 @@ Pratique [profile_data] Données --- +[profile_manage_data] +Gérer les données +--- [profile_sync_tab] Synchronisation --- @@ -2256,6 +2256,9 @@ Listes [profile_picture_title] Photo de profil --- +[profile_change_picture] +Changer d'image +--- [audio_custom_default_title] Audio personnalisé --- @@ -5773,6 +5776,10 @@ Plus fort Réussites --- +[achievement_unlocked] +Réussite débloquée +--- + [achievement_alerts_label] Alertes de réussite --- diff --git a/locales/id.txt b/locales/id.txt index 051e7d12f..f1aafdf09 100644 --- a/locales/id.txt +++ b/locales/id.txt @@ -16,9 +16,6 @@ Niat saya [profile_progress_title] Aktivitas --- -[profile_weekly_insight] -Anda hadir selama %d hari minggu ini. ---- [tab_habits] Kebiasaan --- @@ -28,6 +25,9 @@ Latihan [profile_data] Data --- +[profile_manage_data] +Kelola data +--- [profile_sync_tab] Sinkronisasi --- @@ -2256,6 +2256,9 @@ Item [profile_picture_title] Foto profil --- +[profile_change_picture] +Ganti gambar +--- [audio_custom_default_title] Audio kustom --- @@ -5774,6 +5777,10 @@ Lebih keras Pencapaian --- +[achievement_unlocked] +Pencapaian terbuka +--- + [achievement_alerts_label] Pemberitahuan pencapaian --- diff --git a/locales/it.txt b/locales/it.txt index 7d64a50dc..dfbab7228 100644 --- a/locales/it.txt +++ b/locales/it.txt @@ -16,9 +16,6 @@ La mia intenzione [profile_progress_title] Attività --- -[profile_weekly_insight] -Ti sei dedicato a te per %d giorni questa settimana. ---- [tab_habits] Abitudini --- @@ -28,6 +25,9 @@ Pratica [profile_data] Dati --- +[profile_manage_data] +Gestisci dati +--- [profile_sync_tab] Sincronizzazione --- @@ -2256,6 +2256,9 @@ Elementi [profile_picture_title] Immagine del profilo --- +[profile_change_picture] +Cambia immagine +--- [audio_custom_default_title] Audio personalizzato --- @@ -5774,6 +5777,10 @@ Alza volume Traguardi --- +[achievement_unlocked] +Traguardo raggiunto +--- + [achievement_alerts_label] Avvisi dei traguardi --- diff --git a/locales/ja.txt b/locales/ja.txt index dbf6cc21c..36ad0efa1 100644 --- a/locales/ja.txt +++ b/locales/ja.txt @@ -16,9 +16,6 @@ [profile_progress_title] 活動 --- -[profile_weekly_insight] -今週は%d日、自分のために取り組みました。 ---- [tab_habits] 習慣 --- @@ -28,6 +25,9 @@ [profile_data] データ --- +[profile_manage_data] +データを管理 +--- [profile_sync_tab] 同期 --- @@ -2258,6 +2258,9 @@ Inner Breezeの通知は機能しています。 [profile_picture_title] プロフィール画像 --- +[profile_change_picture] +画像を変更 +--- [audio_custom_default_title] カスタムオーディオ --- @@ -5770,6 +5773,10 @@ Dewが不足しています。プロフィールでDewを追加してくださ 実績 --- +[achievement_unlocked] +実績を解除しました +--- + [achievement_alerts_label] 実績の通知 --- diff --git a/locales/ko.txt b/locales/ko.txt index 19d81eae0..07774405f 100644 --- a/locales/ko.txt +++ b/locales/ko.txt @@ -16,9 +16,6 @@ Inner Breeze [profile_progress_title] 활동 --- -[profile_weekly_insight] -이번 주에는 %d일 동안 실천했어요. ---- [tab_habits] 습관 --- @@ -28,6 +25,9 @@ Inner Breeze [profile_data] 데이터 --- +[profile_manage_data] +데이터 관리 +--- [profile_sync_tab] 동기화 --- @@ -2256,6 +2256,9 @@ Inner Breeze 알림이 작동합니다. [profile_picture_title] 프로필 사진 --- +[profile_change_picture] +사진 변경 +--- [audio_custom_default_title] 사용자 오디오 --- @@ -5780,6 +5783,10 @@ Dew가 부족합니다. 프로필에서 Dew를 추가하세요. 업적 --- +[achievement_unlocked] +업적 달성 +--- + [achievement_alerts_label] 업적 알림 --- diff --git a/locales/pt.txt b/locales/pt.txt index 98df8b896..989c482e8 100644 --- a/locales/pt.txt +++ b/locales/pt.txt @@ -16,9 +16,6 @@ Minha intenção [profile_progress_title] Atividade --- -[profile_weekly_insight] -Você esteve presente em %d dias esta semana. ---- [tab_habits] Hábitos --- @@ -28,6 +25,9 @@ Prática [profile_data] Dados --- +[profile_manage_data] +Gerenciar dados +--- [profile_sync_tab] Sincronização --- @@ -2256,6 +2256,9 @@ Itens [profile_picture_title] Foto de perfil --- +[profile_change_picture] +Alterar imagem +--- [audio_custom_default_title] Áudio personalizado --- @@ -5783,6 +5786,10 @@ Aumentar volume Conquistas --- +[achievement_unlocked] +Conquista desbloqueada +--- + [achievement_alerts_label] Alertas de conquistas --- diff --git a/locales/ru.txt b/locales/ru.txt index f78570068..443995879 100644 --- a/locales/ru.txt +++ b/locales/ru.txt @@ -16,9 +16,6 @@ Inner Breeze [profile_progress_title] Активность --- -[profile_weekly_insight] -На этой неделе вы уделили себе %d дн. ---- [tab_habits] Привычки --- @@ -28,6 +25,9 @@ Inner Breeze [profile_data] Данные --- +[profile_manage_data] +Управление данными +--- [profile_sync_tab] Синхронизация --- @@ -2256,6 +2256,9 @@ Health Connect открыт [profile_picture_title] Фото профиля --- +[profile_change_picture] +Изменить изображение +--- [audio_custom_default_title] Своё аудио --- @@ -5779,6 +5782,10 @@ Lumi остаётся без сети, пока вы не примете её у Достижения --- +[achievement_unlocked] +Достижение получено +--- + [achievement_alerts_label] Уведомления о достижениях --- diff --git a/locales/zh.txt b/locales/zh.txt index 08bec9873..24550237a 100644 --- a/locales/zh.txt +++ b/locales/zh.txt @@ -16,9 +16,6 @@ [profile_progress_title] 活动 --- -[profile_weekly_insight] -本周有 %d 天完成习惯。 ---- [tab_habits] 习惯 --- @@ -28,6 +25,9 @@ [profile_data] 数据 --- +[profile_manage_data] +管理数据 +--- [profile_sync_tab] 同步 --- @@ -2256,6 +2256,9 @@ Inner Breeze 的通知正常工作。 [profile_picture_title] 个人头像 --- +[profile_change_picture] +更换图片 +--- [audio_custom_default_title] 自定义音频 --- @@ -5785,6 +5788,10 @@ Dew不足,请在个人资料中添加Dew。 成就 --- +[achievement_unlocked] +成就已解锁 +--- + [achievement_alerts_label] 成就提醒 --- diff --git a/src/app/achievement_host.zi b/src/app/achievement_host.zi index 2d6df0091..7bedb3aaa 100644 --- a/src/app/achievement_host.zi +++ b/src/app/achievement_host.zi @@ -14,6 +14,7 @@ EntityAchievements :: #import "entity/model"; #import "text_widget" #import "text_props" #import, file "locale.zi"; +#import, file "achievement_locale.zi"; #import, file "assets.zi"; #import, file "../storage/achievements.zi"; #import, file "../storage/achievement_records.zi"; @@ -236,8 +237,7 @@ AchievementPageDocument :: (page: s32, app_filter: string = "") -> string { BuilderPrint(*out, ",\"id\":") EntityAchievements.EntityQuote(*out, TextUntilNul(entry.id[:])) BuilderPrint(*out, ",\"icon\":") - icon := AssetRead(TextUntilNul(entry.icon[:])) - EntityAchievements.EntityQuote(*out, ifx icon.found && icon.data.count < 1024 then icon.data else "") + EntityAchievements.EntityQuote(*out, AchievementIconShape(*entry)) BuilderPrint(*out, ",\"title\":") EntityAchievements.EntityQuote(*out, LocaleText(TextUntilNul(entry.title_key[:]))) BuilderPrint(*out, ",\"description\":") diff --git a/src/app/achievement_locale.zi b/src/app/achievement_locale.zi index e3c4759b3..5fc90d5d3 100644 --- a/src/app/achievement_locale.zi +++ b/src/app/achievement_locale.zi @@ -12,6 +12,15 @@ AchievementLocaleAssetFn :: #type (app: string, path: string) -> AssetView; achievement_locale_asset: AchievementLocaleAssetFn; +// A badge's shape from its own app's package, or "" without one. +AchievementIconShape :: (entry: *AchievementDefinition) -> string { + path := TextUntilNul(entry.icon[:]) + if path == "" { return "" } + asset := AssetRead(path) + if !asset.found && achievement_locale_asset != null { asset = achievement_locale_asset(TextUntilNul(entry.app[:]), path) } + return ifx asset.found && asset.data.count < 1024 then asset.data else "" +} + AchievementTranslation :: struct { title: string description: string diff --git a/src/app/achievement_runtime.zi b/src/app/achievement_runtime.zi index 233cce4bb..c64bc321a 100644 --- a/src/app/achievement_runtime.zi +++ b/src/app/achievement_runtime.zi @@ -4,8 +4,8 @@ #import "std/c_string" #import "std/text_buffer" #import "std/vec" -#import "toast_widget" -#import "toast_props" +#import "entity/achievement_toast" +#import "drawing_props" #import "geometry" #import "notification" #import, file "achievement_host.zi"; @@ -44,8 +44,7 @@ achievement_scan_profile_revision: u64; achievement_scan_restart: bool; achievement_snapshot_revision: u64 = 18446744073709551615; achievement_habits: Habits; -achievement_toast: ToastState; -achievement_toast_message: string; +achievement_toast: AchievementToast; AchievementInstalled :: (id: string) -> bool { for index: cast(s32)1..PackageCount - 1 { @@ -126,8 +125,6 @@ AchievementFrame :: (app: *InnerBreeze) { achievement_scan_restart = false unused CopyCString(owner, achievement_scan_owner[:]) achievement_toast = .{} - PackageFree(achievement_toast_message) - achievement_toast_message = "" achievement_radio_account = .{} achievement_radio_seconds = 0.0 achievement_radio_audible = false @@ -205,39 +202,41 @@ AchievementFrame :: (app: *InnerBreeze) { AchievementDrawAlerts :: (app: *InnerBreeze) { if app == null { return } if !AchievementAlerts() { - achievement_toast = .{} - PackageFree(achievement_toast_message) - achievement_toast_message = "" + AchievementToastClose(*achievement_toast) unused AchievementConsumeAlerts() return } if app_is_session_screen(app.breathing.screen) || app_is_session_screen(app.session_window.screen) || app.modal.active != 0 || app.launcher_open { return } if achievement_dirty || achievement_reconciling { return } - earned := AchievementConsumeAlerts() - if earned > 0 { - PackageFree(achievement_toast_message) - out: Vec(u8) - BuilderPrint(*out, "% · %", LocaleText("achievements_title"), earned) - achievement_toast_message = BuilderFinish(out) + latest: s32 = -1 + earned := AchievementConsumeAlerts(*latest) + if earned > 0 && latest >= 0 { + entry := *achievement_definitions[latest] + // The newest award by name; several at once say how many. + label: Vec(u8) + if earned > 1 { BuilderPrint(*label, "% · %", LocaleText("achievement_unlocked"), earned) } + else { BuilderPrint(*label, "%", LocaleText("achievement_unlocked")) } + text := BuilderFinish(label) + AchievementToastShow(*achievement_toast, text, LocaleText(TextUntilNul(entry.title_key[:])), + AchievementIconShape(entry), AchievementFrameTime()) + PackageFree(text) } if app.backgrounded != 0 { if earned > 0 && NotificationsAllowed() { unused Notify(NotificationProps.{ - .title = LocaleText("achievements_title"), .body = achievement_toast_message, + .title = TextUntilNul(achievement_toast.label[:]), .body = TextUntilNul(achievement_toast.title[:]), .tag = "inbe.achievements", .id = 8, .priority = NotificationPriority.NotificationPriorityLow, .suppress_when_focused = true}) } - achievement_toast = .{} - PackageFree(achievement_toast_message) - achievement_toast_message = "" + AchievementToastClose(*achievement_toast) return } - if achievement_toast.message.count == 0 && earned == 0 { return } - achievement_toast = Toast(app.ui.session, ToastProps.{ + unused AchievementToastDraw(app.ui.session, *achievement_toast, AchievementToastProps.{ .key = cast(u64)0x61636869657665, .viewport = Rectangle.{0.0, 0.0, cast(float32)app.ui.view_width, cast(float32)app.ui.view_height}, - .state = achievement_toast, .message = ifx earned > 0 then achievement_toast_message else "", - .seconds = 4.0, .now_seconds = AchievementFrameTime(), .scale = 1.0}).state + .top = cast(float32)AppTitleBarHeight(), .scale = MetricsScale(), .now = AchievementFrameTime(), + .fill = StyleTokenColor("surface"), .border = DarkenColor(StyleTokenColor("canvas"), 18), + .accent = StyleTokenColor("accent")}) } diff --git a/src/app/entity_host.zi b/src/app/entity_host.zi index 5fa958472..891ea2304 100644 --- a/src/app/entity_host.zi +++ b/src/app/entity_host.zi @@ -30,7 +30,15 @@ Shared :: #import "entity/native_files"; #import, file "../storage/storage_profile_stats.zi"; #import, file "../platform/dew_payment.zi"; #import, file "../storage/dew.zi"; +#import, file "../screens/profile_dew.zi"; +#import, file "app_sync.zi"; +#import "std/vec" +#import "std/format" +#import, file "../screens/dew_worth.zi"; #import, file "../habits/habit_model.zi"; +#import, file "../habits/habit_calendar.zi"; +#import, file "../storage/sync_node_storage.zi"; +#import, file "current_app.zi"; #import, file "../platform/raylib_text_input.zi"; entity_context: AppContext; @@ -39,14 +47,13 @@ entity_document: string; entity_inner_breeze: bool; entity_reload_after_route: bool; entity_account_route: bool; -entity_dew_ready: bool; -entity_dew_known: bool; -entity_dew_balance: s64; +entity_snapshot: string; InbeEntityRead :: (app: *InnerBreeze) -> string { Entity.EntityFree(entity_document) state := Entity.EntityDefault() - state.controls = Entity.ENTITY_IDENTITY | Entity.ENTITY_INTENTION | Entity.ENTITY_NODES + // Name and Intention stay stored but Profile no longer edits them. + state.controls = Entity.ENTITY_NODES state.pictures &= ~((1 << 21) | (1 << 22) | (1 << 23)) state.name = app.profile_display_name state.intention = app.profile_intention @@ -74,31 +81,12 @@ InbeEntityRead :: (app: *InnerBreeze) -> string { } state.host_navigation = true Entity.EntityAddExtension(*state, "account", LocaleText("sync_account_title")) - if DewAvailable() { - Entity.EntityAddExtension(*state, "dew", LocaleText("profile_dew_title")) - entity_dew_ready = DewReady() - entity_dew_known = entity_dew_ready && dew_account.known - entity_dew_balance = dew_account.balance - summary: [256]u8 - if entity_dew_known { - unused DewFormat(dew_account.balance, DewUnits, summary[:]) - unused AppAppendText(" Dew", summary[:]) - } else { - unused CopyCString(LocaleText(ifx DewReady() then "profile_dew_loading" else "profile_dew_connect"), summary[:]) - } - unused Entity.EntityDescribeExtension(*state, "dew", TextUntilNul(summary[:]), "", "") - } - Entity.EntityAddExtension(*state, "inbe", LocaleText("profile_progress_title")) - Entity.EntityAddExtension(*state, "data", LocaleText("profile_data")) + // The Dew card holds the balance, storage plans and data management; + // builds without Dew keep Data as its own row. + if !DewAvailable() { Entity.EntityAddExtension(*state, "data", LocaleText("profile_data")) } Entity.EntityAddExtension(*state, "friends", LocaleText("profile_friends_title")) Entity.EntityAddExtension(*state, "telegram", "Telegram") Entity.EntityAddExtension(*state, "achievements", LocaleText("achievements_title")) - active_days: s32 - sessions: s32 - unused storage_profile_week_stats(habits_today_index(), *active_days, *sessions) - summary: [256]u8 - unused FormatNumberTemplate(LocaleText("profile_weekly_insight"), active_days, summary[:]) - unused Entity.EntityDescribeExtension(*state, "inbe", TextUntilNul(summary[:]), "", "activity") entity_document = Entity.EntityEncode(state) return entity_document } @@ -147,7 +135,108 @@ EntityHostAllows :: (context: *void, name: string) -> bool { return name == "ReadStoreHost" || name == "WriteStoreHost" || name == "AppLocaleHost" || name == "ClipboardCopyHost" || name == "AppServiceHost" || name == "entity.management" || name == "entity.text_height" || - name == "entity.achievements" + name == "entity.achievements" || name == "entity.activity" || (name == "entity.dew" && DewAvailable()) +} + +// The node-confirmed Dew account and Inner Breeze's own summaries for the +// shared balance card; its buttons come back as dew-* routes. +InbeEntityDew :: () -> string { + DewContext() + Entity.EntityFree(entity_snapshot) + out: Vec(u8) + BuilderPrint(*out, "{\"sequence\":%,\"busy\":%,\"available\":%,\"error\":%,\"host_actions\":true,\"manage_data\":true,\"owner\":", + cast(s64)dew_sequence, ifx DewBusy() then "true" else "false", + ifx DewReady() then "true" else "false", ifx dew_notice != "" then "true" else "false") + Entity.EntityQuote(*out, storage_get_setting_text("sync_public_id")) + account := TextUntilNul(dew_account_json[:]) + if dew_account.known && account != "" { + DewRatesRefresh() + BuilderPrint(*out, ",\"account\":%", account) + line: [256]u8 + if DewWorthText(dew_account.balance, line[:]) { + BuilderPrint(*out, ",\"worth\":") + Entity.EntityQuote(*out, TextUntilNul(line[:])) + } + line = .{} + size: [24]u8 + if ProfileDewCurrentSize() > 0 { + ProfileDewSizeText(dew_account.limit_bytes, size[:]) + arguments: [2]FormatArg = .[FormatArg.{.text = TextUntilNul(size[:]), .is_text = true}, + FormatArg.{.number = ProfileDewDaysLeft()}] + unused FormatTemplate(LocaleText("profile_dew_paid"), arguments[:], line[:]) + } else { + free := ifx dew_account.free_bytes > 0 then dew_account.free_bytes else dew_account.limit_bytes + if free > 0 { + ProfileDewSizeText(free, size[:]) + arguments: [1]FormatArg = .[FormatArg.{.text = TextUntilNul(size[:]), .is_text = true}] + unused FormatTemplate(LocaleText("profile_dew_free"), arguments[:], line[:]) + } else { + unused AppCopyText(LocaleText("profile_dew_plan_free"), line[:]) + } + } + BuilderPrint(*out, ",\"plan_summary\":") + Entity.EntityQuote(*out, TextUntilNul(line[:])) + if dew_account.limit_bytes > 0 { + used: [32]u8 + limit: [32]u8 + unused SyncStorageFormatBytes(dew_account.used_bytes, used[:]) + unused SyncStorageFormatBytes(dew_account.limit_bytes, limit[:]) + arguments: [2]FormatArg = .[FormatArg.{.text = TextUntilNul(used[:]), .is_text = true}, + FormatArg.{.text = TextUntilNul(limit[:]), .is_text = true}] + line = .{} + unused FormatTemplate(LocaleText("profile_node_storage_used_of"), arguments[:], line[:]) + BuilderPrint(*out, ",\"usage_summary\":") + Entity.EntityQuote(*out, TextUntilNul(line[:])) + } + } else { + BuilderPrint(*out, ",\"account\":null") + } + BuilderPrint(*out, "}") + entity_snapshot = BuilderFinish(out) + return entity_snapshot +} + +// Today's habits and this week's practice, shown on Profile only in Inner Breeze. +InbeEntityActivity :: () -> string { + today := habits_today_index() + due: s32 = 0 + done: s32 = 0 + app := CurrentApp() + if app != null { + for index: 0..app.habits.count - 1 { + if habit_scheduled_day(*app.habits.items[index], today) != 0 { + due += 1 + if habit_completed_day(*app.habits.items[index], today) != 0 { done += 1 } + } + } + } + active_days: s32 + sessions: s32 + unused storage_profile_week_stats(today, *active_days, *sessions) + loading := app_sync_loading() != 0 + values: [3][24]u8 + if loading { + for index: 0..2 { unused AppCopyText("…", values[index][:]) } + } else { + unused FormatTwoNumberTemplate("%d/%d", done, due, values[0][:]) + unused AppFormatS32(active_days, values[1][:]) + unused AppFormatS32(sessions, values[2][:]) + } + labels: [3]string = .["profile_today_short", "profile_active_days_short", "profile_sessions_short"] + icons: [3]string = .["today", "days", "sessions"] + Entity.EntityFree(entity_snapshot) + out: Vec(u8) + BuilderPrint(*out, "{\"stats\":[") + for index: 0..2 { + BuilderPrint(*out, "%{\"label\":", ifx index > 0 then "," else "") + Entity.EntityQuote(*out, LocaleText(labels[index])) + BuilderPrint(*out, ",\"value\":") + Entity.EntityQuote(*out, TextUntilNul(values[index][:])) + BuilderPrint(*out, ",\"icon\":\"%\"}", icons[index]) + } + BuilderPrint(*out, "]}") + entity_snapshot = BuilderFinish(out) + return entity_snapshot } EntityHostText :: (text: string) -> HostValue { @@ -167,8 +256,9 @@ EntityHostLocale :: (key: string) -> string { if key == "entity.node_address" { return LocaleText("sync_remote_label") } if key == "entity.add" { return LocaleText("sync_nodes_add") } if key == "entity.remove" { return LocaleText("launcher_uninstall") } - if key == "entity.picture" || key == "entity.change_picture" { return LocaleText("profile_picture_title") } - if key == "entity.done" { return LocaleText("close_button") } + if key == "entity.picture" { return LocaleText("profile_picture_title") } + if key == "entity.change_picture" { return LocaleText("profile_change_picture") } + if key == "entity.done" { return LocaleText("done_button") } if key == "entity.node_invalid" { return LocaleText("sync_server_url_invalid") } if key == "entity.node_limit" { return LocaleText("sync_nodes_limit") } if key == "entity.account" { return LocaleText("sync_account_title") } @@ -210,6 +300,9 @@ EntityHostLocale :: (key: string) -> string { if key == "entity.storage_used_unlimited" { return LocaleText("profile_node_storage_used_unlimited") } if key == "entity.storage_full" { return LocaleText("profile_node_storage_full") } if key == "entity.node_media" { return LocaleText("profile_node_storage_media") } + if key == "entity.manage_data" { return LocaleText("profile_manage_data") } + // The shared Dew card reads Inner Breeze's own Dew strings. + if key.count > 12 && key[:12] == "profile_dew_" { return LocaleText(key) } return key } @@ -220,6 +313,15 @@ EntityHostCall :: (context: *void, module: *u8, function: *u8, if AchievementEntityCall(cast(*void)app, name, arguments, count, result) { return 1 } + if name == "AppServiceHost" && count == 2 && AppArgumentText(arguments[0]) == "entity.dew" && DewAvailable() { + request := AppArgumentText(arguments[1]) + result.* = EntityHostText(ifx request == "" then InbeEntityDew() else ifx DewRequestRefresh(request) then "queued" else "rejected") + return 1 + } + if name == "AppServiceHost" && count == 2 && AppArgumentText(arguments[0]) == "entity.activity" { + result.* = EntityHostText(InbeEntityActivity()) + return 1 + } if name == "AppServiceHost" && count == 2 && AppArgumentText(arguments[0]) == "entity.management" { InbeManagementStart(app) request := AppArgumentText(arguments[1]) @@ -282,15 +384,6 @@ EntityHostFrame :: (app: *InnerBreeze, bounds: Rectangle) -> bool { entity_opened = true } InbeManagementPump(app) - if entity_document.count > 0 && DewAvailable() && - (entity_dew_ready != DewReady() || - entity_dew_known != (DewReady() && dew_account.known) || - (entity_dew_known && entity_dew_balance != dew_account.balance)) { - // Save current edits before refreshing the balance shown by Entity. - if AppContextRun(*entity_context, Portable.APP_SAVE) { - entity_reload_after_route = true - } - } typed: [1024]u8 if entity_reload_after_route { entity_context.command = "reload" @@ -316,6 +409,10 @@ EntityHostFrame :: (app: *InnerBreeze, bounds: Rectangle) -> bool { InbeManagementPump(app) if !ran { return false } route := entity_context.reply + // The Dew card's buttons open Inner Breeze's own windows over Profile. + if route == "dew-topup" && DewAvailable() { ProfileTopUpOpen(app); return true } + if route == "dew-plans" && DewAvailable() { ProfileStoragePlansOpen(app); return true } + if route == "dew-data" { route = "data" } if route != "" { entity_reload_after_route = true } if route == "inbe" { entity_inner_breeze = true; app.profile_scroll = 0 } else if route == "account" { app.profile_tab = PROFILE_TAB_SYNC; app.profile_scroll = 0 } diff --git a/src/screens/dew_worth.zi b/src/screens/dew_worth.zi index 188003b9f..bd2a49095 100644 --- a/src/screens/dew_worth.zi +++ b/src/screens/dew_worth.zi @@ -1,6 +1,7 @@ // Dew amounts read alongside what they are worth in Monero and US dollars, // at the rates the node publishes. #import "text_buffer" +#import "entity/dew_model" #import, file "../storage/dew.zi"; #import, file "../app/locale.zi"; #import, file "../app/text_buffers.zi"; diff --git a/src/screens/leaderboard_screen.zi b/src/screens/leaderboard_screen.zi index 753be8698..7bc0cf951 100644 --- a/src/screens/leaderboard_screen.zi +++ b/src/screens/leaderboard_screen.zi @@ -191,12 +191,13 @@ LeaderboardPracticeId :: (practice: s32) -> string { return "whm" } -// The board offers the practices installed on Practice, in Practice's order. +// The board ranks Wim Hof and meditation, the practices with averages, +// when they are installed, in Practice's order. LeaderboardInstalledPractices :: () -> LeaderboardMessage { installed := LeaderboardMessage.{.practices_listed = true} for index: cast(s32)0..EXERCISE_COUNT - 1 { practice := practice_ordered_id(index) - if PracticeInstalled(practice) && installed.practice_count < installed.practices.count { + if LeaderboardHasAverage(practice) && PracticeInstalled(practice) && installed.practice_count < installed.practices.count { installed.practices[installed.practice_count] = practice installed.practice_count += 1 } diff --git a/src/screens/profile_screen.zi b/src/screens/profile_screen.zi index eac53327f..1c5f6f563 100644 --- a/src/screens/profile_screen.zi +++ b/src/screens/profile_screen.zi @@ -136,7 +136,7 @@ profile_content_height :: (content_w: s32, user_data: *void) -> s32 { return AppScale(12) + profile_sync_content_height(content_w) } if app != null && app.profile_tab == PROFILE_TAB_OVERVIEW { - return AppScale(236) + ProfileDewHeight(app, content_w) + return AppScale(160) + ProfileDewHeight(app, content_w) } if app != null && app.profile_tab == PROFILE_TAB_DATA { return AppScale(12) + profile_data_content_height(content_w) @@ -205,7 +205,6 @@ profile_draw_overview :: (app: *InnerBreeze, x: s32, w: s32, y: *s32) { active_days: s32 = 0 practice_sessions: s32 = 0 value: [64] u8 - insight: [160] u8 loading := app_sync_loading() != 0 stat_gap := AppScale(8) stat_w := (w - stat_gap * 2) / 3 @@ -259,20 +258,6 @@ profile_draw_overview :: (app: *InnerBreeze, x: s32, w: s32, y: *s32) { FrameTextHold(*app.ui.frame_text, AppTextFromCString(*value[0], 64)), StyleTokenColor("accent")) y.* += stat_h + AppScale(14) - - if loading { - unused AppCopyText(LocaleText("profile_updating_status"), insight[:]) - unused AppAppendText("…", insight[:]) - } else { - unused FormatNumberTemplate(LocaleText("profile_weekly_insight"), - active_days, insight[:]) - } - - Text(app.ui.session, TextProps.{.bounds = Rectangle.{cast(float32)x, - cast(float32)y.*, cast(float32)w, cast(float32)AppScale(64)}, - .text = AppTextFromCString(*insight[0], 160), .wrap = cast(TextWrap)TextWrapAuto}) - y.* += AppScale(76) - } profile_draw_stat_row :: (x: s32, w: s32, y: *s32, label: string, diff --git a/src/storage/achievements.zi b/src/storage/achievements.zi index 88abc6c7b..0662e0f97 100644 --- a/src/storage/achievements.zi +++ b/src/storage/achievements.zi @@ -440,7 +440,8 @@ AchievementEvaluate :: () { } } -AchievementConsumeAlerts :: () -> s32 { +// Counts the awards to announce; `latest`, when given, names the last one. +AchievementConsumeAlerts :: (latest: *s32 = null) -> s32 { count: s32 = 0 enabled := AchievementAlerts() for index: cast(s32)0..achievement_count - 1 { @@ -452,7 +453,10 @@ AchievementConsumeAlerts :: () -> s32 { defer { PackageFree(key) } if storage_get_setting_int(key, 0) != 0 { continue } storage_set_setting_int(key, 1) - if storage_get_setting_int(key, 0) == 1 { count += 1 } + if storage_get_setting_int(key, 0) == 1 { + count += 1 + if latest != null { latest.* = index } + } } return count } diff --git a/src/storage/dew.zi b/src/storage/dew.zi index 9881e144d..0c2f08f36 100644 --- a/src/storage/dew.zi +++ b/src/storage/dew.zi @@ -61,6 +61,13 @@ dew_action: s32; dew_next_refresh: float64; dew_notice: string; dew_sync_requested: bool; +// The node's last confirmed answer for this account, kept between launches +// so Profile shows a balance at once; a fresh read replaces it. +dew_account_json: [8192]u8; +dew_account_fresh: bool; +dew_background_reads: s32; +// Profile's refresh requests count up; an older one is ignored. +dew_sequence: s32; // A gift waiting for the node's answer, as the request it sends, kept until // the node confirms or refuses it so an uncertain send repeats the same ID. dew_gift_attempt: [192]u8; @@ -75,6 +82,10 @@ DewReady :: () -> bool { SyncNodeSameAddress(storage_get_setting_text("sync_server_url"), DewNode) } +DewBusy :: () -> bool { + return dew_operation.active +} + DewCancel :: () { CancelStoredOperation(*dew_operation) dew_account = DewAccount.{} @@ -89,6 +100,9 @@ DewCancel :: () { dew_next_refresh = 0.0 dew_notice = "" dew_sync_requested = false + dew_account_json = .{} + dew_account_fresh = false + dew_background_reads = 0 dew_gift_attempt = .{} dew_gift_retry_at = 0.0 dew_gift_state = DewGiftNone @@ -115,6 +129,13 @@ DewContext :: () { } DewCancel() dew_identity = identity + cached: [8192]u8 + unused storage_get_social_cache_json("dew.account", *cached[0], 8192) + if DewParseAccount(TextUntilNul(cached[:]), TextUntilNul(dew_identity[:]), *dew_account) { + dew_account_json = cached + } else { + dew_account = DewAccount.{} + } unused storage_get_social_cache_json("dew.upgrade", *dew_attempt[0], 256) if FieldAt(TextUntilNul(dew_attempt[:]), 0, "request_id") < 0 { dew_attempt[0] = cast(u8)0 @@ -128,34 +149,6 @@ DewContext :: () { } } -// Six decimal places match the existing signed ledger; trailing zeros vanish. -DewFormat :: (units: s64, divisor: s64, output: []u8) -> bool { - if units < 0 || divisor <= 0 || !AppFormatS64(units / divisor, output) { - return false - } - remainder := units % divisor - if remainder == 0 { - return true - } - if !AppAppendText(".", output) { - return false - } - scale := divisor / 10 - while scale > 0 { - digit: [2]u8 - digit[0] = cast(u8)(48 + remainder / scale) - if !AppAppendText(TextUntilNul(digit[:]), output) { - return false - } - remainder %= scale - if remainder == 0 { - return true - } - scale /= 10 - } - return true -} - DewBegin :: (action: s32, path: string, body: string) -> bool { if !DewReady() || dew_operation.active { return false @@ -342,6 +335,9 @@ DewTick :: (visible: bool, now: float64) { if DewParseAccount(json, TextUntilNul(dew_identity[:]), *received) { previous := SyncNodeStorageRead(DewNode) dew_account = received + dew_account_fresh = true + unused AppCopyText(json, dew_account_json[:]) + unused storage_set_social_cache_json("dew.account", json) storage := SyncNodeStorage.{ .known = true, .used_bytes = received.used_bytes, @@ -358,7 +354,7 @@ DewTick :: (visible: bool, now: float64) { dew_sync_requested = true } } else { - dew_account.known = false + // The last confirmed balance stays, marked as not refreshed. dew_notice = "profile_dew_error" } } @@ -399,12 +395,36 @@ DewTick :: (visible: bool, now: float64) { dew_gift_retry_at = now + 15.0 return } - if visible && DewReady() && !dew_operation.active && now >= dew_next_refresh { + // One read soon after launch keeps the balance current before Profile + // opens; a few background tries, then only while Profile shows it. + background := !dew_account_fresh && dew_background_reads < 3 + if (visible || background) && DewReady() && !dew_operation.active && now >= dew_next_refresh { + if !visible { dew_background_reads += 1 } unused DewBegin(DewRead, "/api/v1/storage/plan", "") dew_next_refresh = now + 15.0 } } +// Profile asks for a fresh read; the request names the account and a newer sequence. +DewRequestRefresh :: (request: string) -> bool { + DewContext() + owner: [65]u8 + operation: [24]u8 + sequence: s64 + if !DewReady() || Space(request, ValueEnd(request, 0, 0)) != cast(s32)request.count || + ReadStringText(request, FieldAt(request, 0, "owner"), owner[:]) != 64 || + TextUntilNul(owner[:]) != TextUntilNul(dew_identity[:]) || + !DewInteger(request, FieldAt(request, 0, "sequence"), *sequence) || + sequence <= cast(s64)dew_sequence || sequence > 2147483647 || + ReadStringText(request, FieldAt(request, 0, "operation"), operation[:]) <= 0 || + TextUntilNul(operation[:]) != "refresh" { + return false + } + dew_sequence = cast(s32)sequence + dew_next_refresh = 0.0 + return true +} + // {"xmr_usd_cents":N,"updated_at":unix,"sources":[...],"xmr_atomic_units":N,"token_units":N} // A zero price means the node has no current rate. DewParseRates :: (json: string, rates: *DewRates) -> bool { diff --git a/tests/leaderboard_ui_test.py b/tests/leaderboard_ui_test.py index 7b50ed3ff..0822882fc 100644 --- a/tests/leaderboard_ui_test.py +++ b/tests/leaderboard_ui_test.py @@ -196,9 +196,8 @@ with tempfile.TemporaryDirectory(prefix="inbe-leaderboard-") as directory: shutil.copyfile(root / "build/practice-content/taichi.zib", packages / "practice-taichi.zib") app, window = launch(profile, "board") try: - # Installed practices only, in Practice's order, two per row on phones. - expected = [["Astral Projection", "Wim Hof Breathing"], ["Breathing Patterns", "Meditation"], - ["7-Minute Workout"]] + # Only Wim Hof and Meditation are ranked, in Practice's order, side by side on phones. + expected = [["Wim Hof Breathing", "Meditation"]] grid = practice_grid(expected) assert grid == expected, f"installed practices: {grid}" assert selected_practice() == "Wim Hof Breathing" @@ -208,19 +207,12 @@ with tempfile.TemporaryDirectory(prefix="inbe-leaderboard-") as directory: choose("Avg hold") average = board(["river", "maple", "cedar"]) assert [name for name, _ in average] == ["river", "maple", "cedar"], f"average hold order: {average}" - # Meditation is on the second row of the phone grid. choose("Meditation") meditation = board(["river", "cedar"]) assert [name for name, _ in meditation] == ["river", "cedar"] and "0:15" in dict(meditation)["river"], \ f"meditation: {meditation}" - choose("Breathing Patterns") - patterns = board(["cedar", "river"]) - assert sorted(name for name, _ in patterns) == ["cedar", "river"], f"breathing patterns: {patterns}" - # Astral Projection ranks its own board, by streak only. - choose("Astral Projection") - astral = board(["river", "maple", "cedar"]) - assert [name for name, _ in astral] == ["river", "maple", "cedar"], f"astral projection: {astral}" - assert not driver.find(label="Avg hold", role="button", visible=True), "Astral Projection ranks an average" + for other in ("Breathing Patterns", "Astral Projection", "7-Minute Workout"): + assert not driver.find(label=other, role="button", visible=True), f"{other} is ranked" # Only apps with a ranking are offered. Without a game that reported # a score, that is Practice alone, so there is nothing to choose. assert not driver.find(role="combo_box", visible=True), "an app without a ranking was offered" @@ -231,12 +223,11 @@ with tempfile.TemporaryDirectory(prefix="inbe-leaderboard-") as directory: assert app.poll() is None, log finally: stop(app) - # A downloaded Sun Salutation joins the board in Practice's order. + # A downloaded Sun Salutation is not ranked either. shutil.copyfile(root / "build/practice-content/sunsalutation.zib", packages / "practice-sunsalutation.zib") app, window = launch(profile, "with-sun-salutation") try: - expected = [["Astral Projection", "Wim Hof Breathing"], ["Breathing Patterns", "Meditation"], - ["Sun Salutation", "7-Minute Workout"]] + expected = [["Wim Hof Breathing", "Meditation"]] grid = practice_grid(expected) assert grid == expected, f"after download: {grid}" log = (output / "with-sun-salutation.log").read_text() @@ -261,6 +252,5 @@ with tempfile.TemporaryDirectory(prefix="inbe-about-") as directory: assert about.returncode == 0 and shot.exists(), stdout[-4000:] + stderr[-2000:] assert "out of bounds" not in stdout + stderr, stdout[-4000:] driver_directory.cleanup() -print("Leaderboard: preinstalled and unpinned, installed practices in order, saved ranks, average hold, " - "meditation time, patterns, Astral Projection, only ranked apps offered, " - "a downloaded practice joining and About passed") +print("Leaderboard: preinstalled and unpinned, only Wim Hof and Meditation ranked, saved ranks, average hold, " + "meditation time, only ranked apps offered, a downloaded practice staying unranked and About passed") diff --git a/ziran.lock b/ziran.lock index 7365746fb..5d126d346 100644 --- a/ziran.lock +++ b/ziran.lock @@ -12,7 +12,7 @@ }, { "commit": "db5349c476bdc243c22b9c73fda4ec06d0a25ffc", - "dependencies": {"crypto": "pf039d7a776333200", "kryon": "p684a710bc00ddd1b"}, + "dependencies": {"crypto": "pf039d7a776333200", "kryon": "p4f82eca557c318bb"}, "id": "p0c45ce9ed9a0f8cf", "name": "Apps", "ref": "master", @@ -34,17 +34,9 @@ "ref": "master", "url": "https://github.com/ziranlang/qrcode.git" }, - { - "commit": "ac76f5a06efbc97b7db8a77472fa8b321f01d4da", - "dependencies": {"daochi_client": "p0cff069893bdc938", "kryon": "p684a710bc00ddd1b", "monocypher": "p809b4d31a48625a3", "qrcode": "p0dfa70137405b096"}, - "id": "p14e3f6430ce50062", - "name": "Entity", - "ref": "master", - "url": "https://github.com/waozixyz/entity.git" - }, { "commit": "1cb9df183089a77c8a16448a556186f30b261a98", - "dependencies": {"kryon": "p684a710bc00ddd1b"}, + "dependencies": {"kryon": "p4f82eca557c318bb"}, "id": "p1b13dda539ed2a39", "name": "Kss", "ref": "master", @@ -52,7 +44,7 @@ }, { "commit": "bad2caaa84ef3eae61e40c99bf572d2b060d0ca2", - "dependencies": {"kryon": "p684a710bc00ddd1b"}, + "dependencies": {"kryon": "p4f82eca557c318bb"}, "id": "p20eb23d3e6db3711", "name": "Game2D", "ref": "master", @@ -67,6 +59,14 @@ "source": true, "url": "https://github.com/open-quantum-safe/liboqs.git" }, + { + "commit": "a1f4e4899991319b0e2a300aa47114c7e665e02b", + "dependencies": {"raylib": "p5a77c9c35110e925"}, + "id": "p4f82eca557c318bb", + "name": "kryon", + "ref": "master", + "url": "https://github.com/kryonlabs/kryon.git" + }, { "commit": "fafa2cea97d0cb379d832086ba45a989fa6f9c8e", "dependencies": {}, @@ -76,14 +76,6 @@ "source": true, "url": "https://github.com/raysan5/raylib.git" }, - { - "commit": "7c09f898c171900b8bd13d011b43eed496d278c2", - "dependencies": {"raylib": "p5a77c9c35110e925"}, - "id": "p684a710bc00ddd1b", - "name": "kryon", - "ref": "master", - "url": "https://github.com/kryonlabs/kryon.git" - }, { "commit": "22d2ddbdc236796953c905a05a2cebf5ab1b4ff3", "dependencies": {"liboqs": "p4b0a50b49959e674"}, @@ -101,6 +93,14 @@ "source": true, "url": "https://github.com/LoupVaillant/Monocypher.git" }, + { + "commit": "efe0ac0d83ec9c2ecb15a20a320994ca6fc347d2", + "dependencies": {"daochi_client": "p0cff069893bdc938", "kryon": "p4f82eca557c318bb", "monocypher": "p809b4d31a48625a3", "qrcode": "p0dfa70137405b096"}, + "id": "pabca5e1965868141", + "name": "Entity", + "ref": "master", + "url": "https://github.com/waozixyz/entity.git" + }, { "commit": "9ef1a3a130450d603abd029772422abd40cfcde0", "dependencies": {}, @@ -120,7 +120,7 @@ }, { "commit": "4b0e25bd2df86b54a8f5af3db48282bd41daab1a", - "dependencies": {"kryon": "p684a710bc00ddd1b"}, + "dependencies": {"kryon": "p4f82eca557c318bb"}, "id": "pe8e21a1f2b5ff52c", "name": "plot", "ref": "master", @@ -145,7 +145,7 @@ } ], "root": { - "dependencies": {"apps": "p0c45ce9ed9a0f8cf", "crypto": "pf039d7a776333200", "curl": "pd4bcd11b7d623073", "daochi_client": "p0cff069893bdc938", "entity": "p14e3f6430ce50062", "game2d": "p20eb23d3e6db3711", "kryon": "p684a710bc00ddd1b", "kss": "p1b13dda539ed2a39", "liboqs": "p4b0a50b49959e674", "mingcute": "pe1027b9d16704793", "monocypher": "p809b4d31a48625a3", "oqs": "p7098ac9cd92f7e5f", "plot": "pe8e21a1f2b5ff52c", "qrcode": "p0dfa70137405b096", "rini": "p09fa77e94b0dfc6c", "sqlite": "peaa43c4b7ef72edf"}, + "dependencies": {"apps": "p0c45ce9ed9a0f8cf", "crypto": "pf039d7a776333200", "curl": "pd4bcd11b7d623073", "daochi_client": "p0cff069893bdc938", "entity": "pabca5e1965868141", "game2d": "p20eb23d3e6db3711", "kryon": "p4f82eca557c318bb", "kss": "p1b13dda539ed2a39", "liboqs": "p4b0a50b49959e674", "mingcute": "pe1027b9d16704793", "monocypher": "p809b4d31a48625a3", "oqs": "p7098ac9cd92f7e5f", "plot": "pe8e21a1f2b5ff52c", "qrcode": "p0dfa70137405b096", "rini": "p09fa77e94b0dfc6c", "sqlite": "peaa43c4b7ef72edf"}, "name": "Inbe" }, "toolchain": {