mission-control-web

    Mission Control web UI, written with Rabbita

    mission-control
    rabbita
    web
    ui
    Download zip
    Author
    Version
    0.5.0
    License
    Apache-2.0
    Last updated
    2 hours ago
    Downloads
    107

    #mission-control-web

    The Mission Control web UI, for a browser and for the window of the desktop app. It is a Rabbita page with the components of rui. It shows the projects, adds and removes them, and stops Mission Control. The guide for users says how to open it and how to add a project.

    moon test apps/web --target js moon build apps/web --target js --release

    This package is JavaScript only. The build makes one script, _build/js/release/build/moonrockz/mission-control-web/mission-control-web.js.

    #The bundle

    The server has a small form of this script in pkgs/server/ui/bundle.mbt. After each change of this package, run:

    mise run web:bundle

    Commit the file with the change. mise run validate makes the script again and fails when the file is old.

    #The page

    The server of Mission Control gives the page. The script needs:

    • an element with the ID app, where it mounts;
    • the name of the instance in data-instance on the html element. A view that cannot connect needs it for the command that opens Mission Control again;
    • data-surface="desktop" on the html element in a window of the desktop app, and no such attribute in a browser;
    • the view key in localStorage, under mission-control-view-key. Without a valid key the page says how to open Mission Control again;
    • /hub and /session on the origin of the page.

    The script keeps the state of the primary sidebar in localStorage, under mission-control-primary-sidebar, as shown or hidden. Without it, or with another text, the page shows the primary sidebar. Each page reads it only at the start.

    The theme is the one of the operating system. The address of the page has the open project, for example #/projects/3, so a reload and the buttons of the browser keep it.

    #Files

    • main.mbt reads the page and mounts the UI.
    • model.mbt has the state and its rules. step is pure: it gives the next state and the effects. update makes Rabbita commands of the effects.
    • actions.mbt has the operations of the user: open a project, add, remove, hide or show the primary sidebar, and stop. actions(model) gives the ones of a view, and finds is the search for them.
    • palette.mbt has the command palette.
    • shortcuts.mbt has the shortcuts of the page.
    • view.mbt has the screen, the colors and the subscriptions. app(connection, surface~, instance~, primary_sidebar~, mac~) is the UI.
    • connection.mbt has the connection to the server.

    A control and an entry of the palette for the same operation send the same message, ActionChosen(action). Action::enabled says if the operation is possible now. The controls show it, and step ignores an operation that is not possible. To add an operation, add a case to Action.

    #Command palette

    Ctrl+K or Ctrl+Shift+P opens the palette, and on macOS Cmd+K or Cmd+Shift+P. The button Find… in the primary sidebar opens it also. Firefox keeps Ctrl+Shift+P for itself. The palette finds each action that has all typed words in its title, its search words or its path, in any order.

    The palette is a combobox with a list. The focus stays in the search field, and the selected action is in the model (Palette(query~, selected~)) as an ActionId. The selection stays with its action when the projects or the connection change. If its action goes away, the first result is selected. Enter does nothing when the page still shows the actions before such a change, so it never runs an action that the user did not see.

    #Connection

    connection.mbt gives the UI a Proton client over the SignalR hub of the server, and the loop that connects again. No other file of the UI names SignalR.

    The button Browse… of the dialog that adds a project is only in a window of the desktop app. It calls app.choose_folder with @proton_client.desktop, which is the bridge of the window and not the server.

    • Connection::to_hub(url, key, session) makes the connection. check_session(url, key) is the request for the session.
    • ViewKey(text) parses the key that the server gave the view. Each request sends it. A page with no key uses Connection::without_key(), whose state is Restarted from the start.
    • client calls the server and gets its events. A subscription continues on each new connection.
    • run tries at once, after 1, 2 and 5 seconds, and then each 5 seconds. A try has 10 seconds to open a connection. A connection that was open for less than 5 seconds counts as a failed try. run ends when the server refuses the session (Restarted) or after stopped (Stopped).
    • The console of the browser gets the cause of each failure, without the key.

    ViewKeyError

    pub(all) suberror ViewKeyError {
    Empty
    NotUrlSafe
    TooLong
    } derive(Eq,
    Debug
    )

    The rule of a view key that a text breaks. An error never has the text, because the text can be almost a key.

    ViewKeyError::equal

    automatically derived

    ViewKeyError::not_equal

    fn ViewKeyError::not_equal(x : ViewKeyError, y : ViewKeyError) -> Bool
    automatically derived

    ViewKeyError::to_repr

    automatically derived

    Action

    An operation of the user.

    Action::enabled

    fn Action::enabled(self : Action, model : Model) -> Bool

    The user can do the action now. step ignores an action that is not enabled.

    Action::equal

    fn Action::equal(Action, Action) -> Bool
    automatically derived

    Action::group

    fn Action::group(self : Action) -> ActionGroup

    Action::id

    fn Action::id(self : Action) -> ActionId

    Action::not_equal

    fn Action::not_equal(x : Action, y : Action) -> Bool
    automatically derived

    Action::search_words

    fn Action::search_words(self : Action) -> Array[String]

    Words that find the action in the command palette, and that its title does not have.

    Action::title

    fn Action::title(self : Action) -> String

    The text of the action for the user.

    Action::to_repr

    automatically derived

    ActionGroup

    pub(all) enum ActionGroup {
    Projects
    Commands
    } derive(Eq,
    Debug
    )

    A group of actions in the command palette.

    ActionGroup::equal

    fn ActionGroup::equal(ActionGroup, ActionGroup) -> Bool
    automatically derived

    ActionGroup::not_equal

    fn ActionGroup::not_equal(x : ActionGroup, y : ActionGroup) -> Bool
    automatically derived

    ActionGroup::to_repr

    automatically derived

    ActionId

    What an action is, without the details that can change. Two projects can have the same name, and a project can get a different place in the list.

    ActionId::equal

    fn ActionId::equal(ActionId, ActionId) -> Bool
    automatically derived

    ActionId::not_equal

    fn ActionId::not_equal(x : ActionId, y : ActionId) -> Bool
    automatically derived

    ActionId::to_repr

    automatically derived

    AddState

    pub(all) enum AddState {
    Typing
    Refused(String)
    Browsing
    Sending
    } derive(Eq,
    Debug
    )

    The path of a new project.

    AddState::equal

    fn AddState::equal(AddState, AddState) -> Bool
    automatically derived

    AddState::not_equal

    fn AddState::not_equal(x : AddState, y : AddState) -> Bool
    automatically derived

    AddState::to_repr

    automatically derived

    Connection

    pub struct Connection {
    client :
    Client

    run : async ((ConnectionState) -> Unit) -> Unit
    stopped : () -> Unit
    }

    The connection of the UI. One value lives as long as the page.

    Connection::to_hub

    fn Connection::to_hub(url : String, key : ViewKey, session : async () -> SessionCheck) -> Connection

    The connection to the hub at url, for example http://127.0.0.1:3090/hub, with the key of the view. session asks the server for the session after each failed try; see check_session. A page with no key uses Connection::without_key.

    The cause of each failure goes to the console of the browser, without the key.

    Connection::without_key

    fn Connection::without_key() -> Connection

    The connection of a page that has no view key. The server refuses such a page, so the state is Restarted from the start: run gives it and ends, with no request. Each call fails with TransportFailure.

    ConnectionState

    pub(all) enum ConnectionState {
    Connecting
    Connected
    Reconnecting
    Restarted
    Stopped
    } derive(Eq,
    Debug
    )

    What the UI knows about its connection to the server.

    ConnectionState::equal

    automatically derived

    ConnectionState::not_equal

    fn ConnectionState::not_equal(x : ConnectionState, y : ConnectionState) -> Bool
    automatically derived

    ConnectionState::to_repr

    automatically derived

    Dialog

    pub(all) enum Dialog {
    NoDialog
    AddDialog(path~ : String, state~ : AddState)
    ConfirmStop
    Palette(query~ : String, selected~ : ActionId?)
    } derive(Eq,
    Debug
    )

    The dialog that is open. Two dialogs are never open at the same time.

    Dialog::add

    fn Dialog::add() -> Dialog

    The dialog that adds a project, with an empty field.

    Dialog::equal

    fn Dialog::equal(Dialog, Dialog) -> Bool
    automatically derived

    Dialog::not_equal

    fn Dialog::not_equal(x : Dialog, y : Dialog) -> Bool
    automatically derived

    Dialog::to_repr

    automatically derived

    DialogElement

    pub(all) enum DialogElement {
    AddElement
    StopElement
    PaletteElement
    } derive(Eq,
    Debug
    )

    An element of the page that shows a dialog.

    DialogElement::equal

    automatically derived

    DialogElement::not_equal

    fn DialogElement::not_equal(x : DialogElement, y : DialogElement) -> Bool
    automatically derived

    DialogElement::to_repr

    automatically derived

    Direction

    pub(all) enum Direction {
    Up
    Down
    } derive(Eq,
    Debug
    )

    A direction in the list of the palette.

    Direction::equal

    fn Direction::equal(Direction, Direction) -> Bool
    automatically derived

    Direction::not_equal

    fn Direction::not_equal(x : Direction, y : Direction) -> Bool
    automatically derived

    Direction::to_repr

    automatically derived

    Model

    The state of one view.

    Model::Model

    The state of a view before its first connection.

    Model::equal

    fn Model::equal(Model, Model) -> Bool
    automatically derived

    Model::is_over

    fn Model::is_over(self : Model) -> Bool

    The view ended: it does not connect again, and its state does not change.

    Model::not_equal

    fn Model::not_equal(x : Model, y : Model) -> Bool
    automatically derived

    Model::open_project

    The open project, or None when no project is open or the list does not have it.

    Model::other_instance

    fn Model::other_instance(self : Model) -> String?

    The name of the instance, if it is not stable.

    Model::to_repr

    automatically derived

    Msg

    pub(all) enum Msg {
    ConnectionChanged(ConnectionState)
    ConnectionFailed(String)
    InfoRead(
    AppInfo
    )
    ProjectsListed(ReadOnlyArray[
    Project
    ])
    ProjectShown(
    ShownProject
    )
    AppStopping
    HashChanged(
    ProjectId
    ?)
    WindowResized(WindowSize)
    ActionChosen(Action)
    PaletteOpened
    PaletteTyped(String)
    PaletteMoved(Direction)
    PalettePointed(ActionId)
    PaletteEntered(seen~ : ReadOnlyArray[Action])
    CloseDialog
    DialogClosed(DialogElement)
    PathTyped(String)
    BrowseChosen
    FolderChosen(
    ChosenFolder
    )
    BrowseFailed(
    ClientFailure
    )
    AddSubmitted
    ProjectAdded(path~ : String,
    Project
    )
    AddFailed(path~ : String,
    ClientFailure
    )
    ProjectRemoved(
    ProjectId
    )
    RemoveFailed(
    ProjectId
    ,
    ClientFailure
    )
    StopConfirmed
    CallFailed(
    ClientFailure
    )
    NoticeDismissed
    }

    What happens to a view.

    PrimarySidebar

    pub(all) enum PrimarySidebar {
    Shown
    Hidden
    } derive(Eq,
    Debug
    )

    The state of the primary sidebar, which is at the left of a wide window.

    PrimarySidebar::equal

    automatically derived

    PrimarySidebar::not_equal

    fn PrimarySidebar::not_equal(x : PrimarySidebar, y : PrimarySidebar) -> Bool
    automatically derived

    PrimarySidebar::to_repr

    automatically derived

    SessionCheck

    pub(all) enum SessionCheck {
    Valid
    Invalid
    NoAnswer
    } derive(Eq,
    Debug
    )

    What the server says about the session of the view.

    SessionCheck::equal

    automatically derived

    SessionCheck::not_equal

    fn SessionCheck::not_equal(x : SessionCheck, y : SessionCheck) -> Bool
    automatically derived

    SessionCheck::to_repr

    automatically derived

    Shortcut

    pub(all) enum Shortcut {
    OpenPalette
    ChangePrimarySidebar
    } derive(Eq,
    Debug
    )

    A shortcut of the page.

    Shortcut::equal

    fn Shortcut::equal(Shortcut, Shortcut) -> Bool
    automatically derived

    Shortcut::not_equal

    fn Shortcut::not_equal(x : Shortcut, y : Shortcut) -> Bool
    automatically derived

    Shortcut::of_key

    fn Shortcut::of_key(key~ : String, code~ : String, ctrl~ : Bool, alt~ : Bool, meta~ : Bool, shift~ : Bool, composing~ : Bool, mac~ : Bool) -> Shortcut?

    The shortcut of a key press, if it has one. composing is true for a key of an input method. alt is necessary because AltGr is Ctrl+Alt on Windows, and AltGr+K types a character on some keyboards.

    code is the key on the keyboard. It counts only when the character is not one of ASCII, because a keyboard for a different alphabet has no K, no P and no B.

    Shortcut::to_repr

    automatically derived

    ViewKey

    The key that the server gave this view with its session. The page sends it with the cookie in each request for the hub and for the session. Debug text never shows it, and no function gives its text.

    ViewKey::ViewKey

    fn ViewKey::ViewKey(text : String) -> ViewKey raise ViewKeyError

    Parses the text of a view key, which is URL-safe base64 without padding.

    ViewKey::equal

    fn ViewKey::equal(ViewKey, ViewKey) -> Bool
    automatically derived

    ViewKey::not_equal

    fn ViewKey::not_equal(x : ViewKey, y : ViewKey) -> Bool
    automatically derived

    ViewKey::to_repr

    automatically derived

    WindowSize

    pub(all) enum WindowSize {
    Wide
    Small
    } derive(Eq,
    Debug
    )

    The size of the window. A small one has no space for the primary sidebar, and shows the same content in a sheet.

    WindowSize::equal

    fn WindowSize::equal(WindowSize, WindowSize) -> Bool
    automatically derived

    WindowSize::not_equal

    fn WindowSize::not_equal(x : WindowSize, y : WindowSize) -> Bool
    automatically derived

    WindowSize::to_repr

    automatically derived

    actions

    fn actions(model : Model) -> ReadOnlyArray[Action]

    The actions of a view, also the ones that are disabled now: each project in the order of the list, and then the commands. A small window has no primary sidebar.

    app

    The UI. surface is the kind of this view, and instance gave its page. primary_sidebar is the state that the browser kept. mac is true on macOS, which has other shortcuts. The UI runs the connection.

    check_session

    async fn check_session(url : String, key : ViewKey) -> SessionCheck

    Asks the server for the session of this view. url is the complete URL of /session, for example http://127.0.0.1:3090/session. The browser adds the cookie. A failed request, also because of a wrong URL, is NoAnswer.

    finds

    fn finds(query : String, title : String, words : Array[String]) -> Bool

    The action has each word of the query in its title or in one of its search words. The order of the words and their case make no difference.

    hash_of_project

    fn hash_of_project(project :
    ProjectId
    ?) -> String

    The fragment of the address of a project, or of no project.

    project_of_hash

    The project in the fragment of an address, such as #/projects/3. Each other text gives None, because a user can type an address.

    retry_delay

    fn retry_delay(attempt : Int) -> Int

    The time before a try, in milliseconds. attempt is the number of tries that failed since the last long connection: the UI tries at once, after 1, 2 and 5 seconds, and then each 5 seconds.

    update

    The model after a message, and the command that does the rest, with the connection to the server.