Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions app/application.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2149,7 +2149,7 @@ module Root_navigation = struct
| Some retained -> retained
| None -> let fresh=replace_graph ~discard {initial_state with graph_drafts=state.graph_drafts} generation (Some graph_id) in
{fresh with graph_state={fresh.graph_state with graph_id=Some graph_id}} in
{retained with resident_states=states;calendar=state.calendar;environment=state.environment;
{retained with startup_presentation=state.startup_presentation;resident_states=states;calendar=state.calendar;environment=state.environment;
manager=state.manager;graph_catalog=state.graph_catalog;local_copies=state.local_copies;
local_copy_check=state.local_copy_check;local_copy_deleting=state.local_copy_deleting;
local_copy_message=state.local_copy_message;graph_picker_open=state.graph_picker_open;
Expand Down Expand Up @@ -2837,7 +2837,9 @@ let timeline_page
~on_choose_graph:None
|> V.Body.static
| None when loading ->
Journal_timeline.loading_view ()
(* An unfocused resident preview has no loading deadline. The selected
graph presents its wait through the root manager, not this page. *)
V.empty ()
|> V.with_test_id (Ui.Test_id.string "journal-timeline")
|> V.Body.static
| None ->
Expand Down Expand Up @@ -6460,13 +6462,15 @@ let start
let delivery=deliver_output output in
Effect.run(apply_graph_responses set_state_and_effect delivery.responses)));
let startup_loading_key state =
if platform_code = 2 && Journal_startup.Presentation.initial_attempt state.startup_presentation
then None else Journal_startup.Presentation.loading_request state.startup_presentation
let presentation = state.startup_presentation in
if Journal_startup.Presentation.initial_attempt presentation then None
else Option.map (fun key -> key, Journal_startup.Presentation.loading_delay presentation)
(Journal_startup.Presentation.loading_request presentation)
in
let prev_startup_loading_key = ref None in
let arm_startup_loading_timer key =
let arm_startup_loading_timer (key,delay) =
let started = Mtime_clock.counter () in
schedule_after 0.1 (fun () -> Effect.run (set_state (fun state ->
schedule_after delay (fun () -> Effect.run (set_root_state (fun state ->
let elapsed = Mtime.Span.to_float_ns (Mtime_clock.count started) *. 1e-9 in
let next = Journal_startup.Presentation.step state.startup_presentation (Elapsed(key,elapsed)) in
if next == state.startup_presentation then state else {state with startup_presentation=next})))
Expand Down Expand Up @@ -7110,6 +7114,7 @@ let start
|head::rest->head::insert(index-1)rest in
let ids=if List.mem graph_id kept then kept else insert index kept in
Effect.bind(set_root_state(fun state->{state with resident_replacement=None;
startup_presentation=Journal_startup.Presentation.step state.startup_presentation Begin_operation;
graph_picker_open=false;local_copy_message=None})) ~f:(fun()->
Effect.bind(send_manager(Graph_service.Configure_resident_graphs ids))
~f:(fun()->send_manager(Graph_service.Focus_resident_graph graph_id))))))
Expand All @@ -7129,12 +7134,14 @@ let start
error.recovery=Some Journal_startup.Retry_graph_open)
(Journal_startup.derive ~snapshot:m ~graph:snapshot.graph_state).error) snapshot.manager in
if retry_local then
Effect.bind (update (fun state->{state with graph_picker_open=false;resident_replacement=None;
Effect.bind (update (fun state->{state with startup_presentation=Journal_startup.Presentation.step state.startup_presentation Begin_operation;
graph_picker_open=false;resident_replacement=None;
local_copy_check=None;local_copy_message=None;modal=No_modal}))
~f:(fun ()->send_manager (Graph_service.Select_graph graph_id))
else if not (List.mem graph_id ids) && List.length ids>=3 then
update (fun state->{state with resident_replacement=Some value})
else Effect.bind (update (fun state->{state with graph_picker_open=false;resident_replacement=None;
else Effect.bind (update (fun state->{state with startup_presentation=Journal_startup.Presentation.step state.startup_presentation Begin_operation;
graph_picker_open=false;resident_replacement=None;
local_copy_check=None;local_copy_message=None;modal=No_modal})) ~f:(fun ()->
let configured=if List.mem graph_id ids then ids else ids @ [graph_id] in
Effect.bind (send_manager (Graph_service.Configure_resident_graphs configured))
Expand Down Expand Up @@ -7707,7 +7714,7 @@ let start
comparison: the key is recomputed from the new model and the callback
fires when it differs from the previous post-update value. *)
let prev_detail_observation_routes=graph_ref(fun()->None) in
let run_edge_callbacks model =
let run_edge_callbacks ~visible model =
(* A root manager push can still describe the graph being closed. Its
physical retirement resets these cells; do not restart business work. *)
if Option.exists(fun owner->not(runtime_owner_is_live model owner))(timeline_scope model)
Expand Down Expand Up @@ -7743,7 +7750,7 @@ let start
prev_timeline_drain_key := key;
Effect.run (timeline_drain_callback key)));
(let key = startup_loading_key model in
if key <> !prev_startup_loading_key then (
if visible && key <> !prev_startup_loading_key then (
prev_startup_loading_key := key;
Option.iter arm_startup_loading_timer key));
(let generation, requests = detail_loading_key model in
Expand Down Expand Up @@ -7866,7 +7873,7 @@ let start
let key=owner_key owner in
match Hashtbl.find_opt pending_change_notices key with
| None->() | Some(notice,build)->Hashtbl.remove pending_change_notices key;Effect.run(build notice)) (timeline_scope model);
let model=sync_startup_presentation model |> run_edge_callbacks |> prune_resident_models in
let model=sync_startup_presentation model |> run_edge_callbacks ~visible |> prune_resident_models in
let model=if visible then prepare_presentation model else model in
state_ref:=model;save_runtime ();processing_owner:=previous;
if visible then (retire_absent_runtimes model;drain_retired_runtimes ();
Expand Down
29 changes: 22 additions & 7 deletions app/journal_startup.ml
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,10 @@ module Presentation = struct
type account_result = Local | No_local | User | No_user
type screen = Waiting | Timeline | Interaction of startup_state | Account_failure
type account = Discovering | Local_available | User_available | User_required
type wait_kind = Cold_start | Operation
type t =
{ screen : screen
; initial : bool
; wait_kind : wait_kind
; serial : int64
; account_serial : int64
; indicator : bool
Expand All @@ -222,13 +223,14 @@ module Presentation = struct
| Observe of observation
| Account of ticket * account_result
| Account_error of ticket
| Begin_operation
| Retry
| Signed_out
| Foreground of bool
| Elapsed of ticket * float

let create () =
{ screen = Waiting; initial = true; serial = 0L; account_serial = 0L; indicator = false
{ screen = Waiting; wait_kind = Cold_start; serial = 0L; account_serial = 0L; indicator = false
; foreground = true; account = Discovering; local_available = false
; account_failed = false; observed = None }
let foreground t = t.foreground
Expand All @@ -237,7 +239,7 @@ module Presentation = struct
let loading_request t =
if t.foreground && t.screen = Waiting && not t.indicator then Some t.serial else None
let account_ticket t = t.account_serial
let initial_attempt t = t.initial
let initial_attempt t = t.wait_kind = Cold_start
let equal_presentation left right =
left.screen = right.screen
&& (left.screen <> Waiting ||
Expand Down Expand Up @@ -266,11 +268,18 @@ module Presentation = struct
| None -> if t.account_failed && not t.local_available then Account_failure else Waiting)
| None -> if t.account_failed && not t.local_available then Account_failure else Waiting

let business_wait t = {t with wait_kind=Operation;serial=Int64.succ t.serial;indicator=false}
let loading_delay t = match t.wait_kind with Cold_start -> 5. | Operation -> 0.5

let project t =
let next = classify t in
if next = t.screen then t
if next = Waiting && t.wait_kind = Cold_start && Option.fold ~none:false
~some:(fun o -> Option.fold ~none:false ~some:(fun (m:Graph_service.snapshot) ->
m.startup.bootstrapping || Option.is_some m.local_deletion) o.manager) t.observed
then business_wait {t with screen=Waiting}
else if next = t.screen then t
else if next = Waiting then
{t with screen=next;initial=false;serial=Int64.succ t.serial;indicator=false}
business_wait {t with screen=next}
else {t with screen=next;indicator=false}

let step t event =
Expand All @@ -286,6 +295,11 @@ module Presentation = struct
&& not manager.startup.restoring_local && manager.startup.local_access=Graph_service.Local_pending -> User_required
| Some manager when manager.startup.authenticated && t.account <> User_required -> User_available
| _ -> t.account in
let t = match previous,o.manager with
| Some previous,Some next when t.screen=Waiting && previous.selected_graph<>None
&& (previous.selected_graph<>next.selected_graph ||
previous.startup.graph_generation<>next.startup.graph_generation) -> business_wait t
| _ -> t in
project {t with observed=Some o;account;
account_serial=(if changed_account then Int64.succ t.account_serial else t.account_serial)}
| Account (key,result) when key=t.account_serial ->
Expand All @@ -296,8 +310,9 @@ module Presentation = struct
| No_user -> User_required,false in
project {t with account;local_available;account_failed=false}
| Account_error key when key=t.account_serial -> project {t with account_failed=true}
| Begin_operation -> business_wait t
| Retry ->
{t with screen=Waiting;initial=false;serial=Int64.succ t.serial;account_serial=Int64.succ t.account_serial;
{t with screen=Waiting;wait_kind=Operation;serial=Int64.succ t.serial;account_serial=Int64.succ t.account_serial;
indicator=false;account=Discovering;local_available=false;account_failed=false;observed=None}
| Signed_out ->
{t with screen=required Signed_out;indicator=false;account=User_required;
Expand All @@ -306,7 +321,7 @@ module Presentation = struct
{t with foreground=active;indicator=false;
serial=(if active && t.screen=Waiting then Int64.succ t.serial else t.serial)}
| Elapsed (key,elapsed) when key=t.serial && t.foreground && t.screen=Waiting
&& elapsed>=0.1 && not t.indicator -> {t with indicator=true}
&& elapsed>=loading_delay t && not t.indicator -> {t with indicator=true}
| Account _ | Account_error _ | Foreground _ | Elapsed _ -> t
in
if next=t then t else next
Expand Down
2 changes: 2 additions & 0 deletions app/journal_startup.mli
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ module Presentation : sig
| Observe of observation
| Account of ticket * account_result
| Account_error of ticket
| Begin_operation
| Retry
| Signed_out
| Foreground of bool
Expand All @@ -82,6 +83,7 @@ module Presentation : sig
val foreground : t -> bool
val screen : t -> screen
val loading_indicator : t -> bool
val loading_delay : t -> float
val loading_request : t -> ticket option
val account_ticket : t -> ticket
val initial_attempt : t -> bool
Expand Down
14 changes: 3 additions & 11 deletions swift/JournalRuntimeHost.swift
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,7 @@ struct JournalStartupLoadingSurface: View {
var action: AnyView? = nil
@Environment(\.journalStartupClock) private var clock
private var visible: Bool {
#if os(iOS)
active && (initial && clock?.phase != .finished ? clock?.phase == .slow : loading)
#else
active && (loading || (initial && clock?.phase == .slow))
#endif
active && (initial ? clock?.phase == .slow : loading)
}
var body: some View {
VStack(spacing: 12) {
Expand Down Expand Up @@ -204,12 +200,8 @@ struct JournalStartupLoadingSurface: View {
.padding(24)
.background(.background)
.accessibilityIdentifier("journal-startup-waiting")
.onAppear {
#if os(macOS)
clock?.begin(after: .milliseconds(100))
#else
clock?.begin()
#endif
.onChange(of: initial, initial: true) { _, cold in
if cold { clock?.begin() } else { clock?.finish() }
}
}
}
Expand Down
35 changes: 27 additions & 8 deletions test/startup_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -254,21 +254,40 @@ let test_stable_startup_presentation () =
let t=account t Local in
let t=observe ~manager:(startup_snapshot ~authenticated:false ~restoring_local:true ()) ~graph:(graph_state ~phase:Graph_closed ()) t in
require (P.screen t=Waiting) "local binding restore flashes intermediate page");
"one 100ms grace spans catalog restore and first feed",(fun () ->
"one five-second grace spans catalog restore and first feed",(fun () ->
let t=observe ~manager:(startup_snapshot ~catalog_loading:true ()) ~graph:(graph_state ~phase:Graph_closed ()) (P.create ()) in
let key=timer t in
let early=P.step t (Elapsed(key,0.099)) in
require (not(P.loading_indicator early)) "99ms shows loading";
require (P.step early (Elapsed(key,0.099999999))==early)
"one nanosecond before 100ms shows loading";
require (P.step early (Elapsed(key,4.999999999))==early)
"one nanosecond before five seconds shows loading";
let t=observe ~manager:(startup_snapshot ~restoring_local:true ()) early in
require (timer t=key) "busy phase restarts grace";
let slow=P.step t (Elapsed(key,0.1)) in
require (P.screen slow=Waiting && P.loading_indicator slow) "100ms waiting has no loading";
let slow=P.step t (Elapsed(key,5.)) in
require (P.screen slow=Waiting && P.loading_indicator slow) "five-second waiting has no loading";
require (P.step slow (Elapsed(key,0.2))==slow) "duplicate elapsed changes owner";
let ready=observe ~manager:(startup_snapshot ()) ~graph_ready:true ~feed_loaded:true slow in
require (P.screen ready=Timeline && not(P.loading_indicator ready)) "ready body retains loading";
require (P.step ready (Elapsed(key,2.))==ready) "late timer changes ready Timeline");
"automatic bootstrap takes over the cold deadline",(fun () ->
let cold=P.create () in
let snapshot=startup_snapshot ~bootstrapping:true () in
let download=observe ~manager:snapshot cold in
let key=timer download in
require (key<>timer cold && not(P.initial_attempt download)) "download inherited cold grace";
require (timer (observe ~manager:snapshot download)=key) "progress restarted download grace";
require (P.step download (Elapsed(timer cold,5.))==download) "cold callback leaked";
require (P.step download (Elapsed(key,0.499999999))==download) "early download indicator";
require (P.loading_indicator (P.step download (Elapsed(key,0.5)))) "download missed deadline");
"picker override starts a fresh wait even without a screen transition",(fun () ->
let cold=P.create () in
let slow=P.step cold (Elapsed(timer cold,5.)) in
let selected=P.step slow Begin_operation in
let key=timer selected in
require (not(P.initial_attempt selected) && not(P.loading_indicator selected)) "picker kept slow cold loading";
let pending=observe ~manager:(startup_snapshot ~bootstrapping:true ()) selected in
require (timer pending=key && P.step pending (Elapsed(timer cold,5.))==pending) "bootstrap displaced selection";
require (P.loading_indicator (P.step pending (Elapsed(key,0.5)))) "selection missed grace");
"Graph_open waits for first feed and an empty feed completes",(fun () ->
let t=observe ~manager:(startup_snapshot ()) ~graph_ready:true (P.create ()) in
require (P.screen t=Waiting) "Graph_open mounts feed's transient loading page";
Expand Down Expand Up @@ -335,10 +354,10 @@ let test_stable_startup_presentation () =
require (timer resumed<>old && not(P.loading_indicator resumed)) "resume reuses old grace";
require (P.step resumed (Elapsed(old,3600.))==resumed) "late background timer changes resume";
let key=timer resumed in
require (P.step resumed (Elapsed(key,0.099999999))==resumed)
require (P.step resumed (Elapsed(key,4.999999999))==resumed)
"resume counts suspended time towards its fresh grace";
require (P.loading_indicator (P.step resumed (Elapsed(key,0.1))))
"resume does not show loading after its fresh 100ms grace");
require (P.loading_indicator (P.step resumed (Elapsed(key,5.))))
"resume does not show loading after its fresh five-second grace");
"negative/NaN elapsed and explicit signout are safe",(fun () ->
let t=observe ~manager:(startup_snapshot ~restoring_local:true ()) (P.create ()) in
let key=timer t in
Expand Down
Loading