vplatform.h Header
Platform Contract
Types
| class | VPlatform | Platform contract of a VApp: the methods that platform code calls to start the app, install its services, deliver the user's input, and read back what to draw. |
Type Aliases
| using | HttpHandler | Platform hook that sends an HTTP request for VApp::http(), installed with VPlatform::set_http_handler(). |
| using | UploadHandler | Platform hook that picks a file and uploads it for VApp::pick_and_upload(), installed with VPlatform::set_upload_handler(). |
| using | PickHandler | Platform hook that opens a file dialog for VApp::pick_path(), installed with VPlatform::set_pick_handler(). |
| using | TimerHandler | Platform hook that runs a callback later for VApp::after(), installed with VPlatform::set_timer_handler(). |
| using | PostHandler | Platform hook that runs a callback on the UI thread, from any thread, for VApp::post(), installed with VPlatform::set_post_handler(). |
| using | OpenUrlHandler | Platform hook that opens a URL in the system browser for VApp::open_url(), installed with VPlatform::set_open_url_handler(). |
| using | CopyTextHandler | Platform hook that puts text on the system clipboard for VApp::copy_text(), installed with VPlatform::set_copy_text_handler(). |
| using | SaveTextHandler | Platform hook that saves text as a file for VApp::save_text(), installed with VPlatform::set_save_text_handler(). |
| using | RunProcessHandler | Platform hook that runs another program and streams its output back for VApp::run_process(), installed with VPlatform::set_run_process_handler(). |
| using | PurchaseHandler | Platform hook that runs the store's purchase flow for VApp::start_purchase(), installed with VPlatform::set_purchase_handler(). |
| using | QueryPurchasesHandler | Platform hook that lists the purchases that the user owns but that the server hasn't verified, for VApp::query_purchases(), installed with VPlatform::set_query_purchases_handler(). |
Type Alias Documentation
using HttpHandler = std::function<void (const HttpRequest &, HttpCallback)>
Platform hook that sends an HTTP request for
VApp::http(), installed with
VPlatform::set_http_handler().
Sends request without blocking the UI thread, then calls callback on
the UI thread with the reply.
using UploadHandler = std::function<void (const std::string &, const std::string &, const std::string &, const int &, const std::string &, UploadCallback)>
Platform hook that picks a file and uploads it for
VApp::pick_and_upload(), installed with
VPlatform::set_upload_handler().
Opens the platform's file picker, uploads the chosen file to url as a
multipart form, then calls callback with the result. The file's bytes
stay in the platform shell, since binary data can't pass into the core
safely on web and Android, so only the server's reply reaches the app.
method is the HTTP verb, like "POST" or "PUT".accept limits the picker to MIME types, like "image/png,image/jpeg".headers are sent with the upload, like an Authorization header.field_name is the form field that carries the file, like "file".using PickHandler = std::function<void (const PickRequest &, PickCallback)>
Platform hook that opens a file dialog for
VApp::pick_path(), installed with
VPlatform::set_pick_handler().
using TimerHandler = std::function<void (int, std::function<void ()>)>
Platform hook that runs a callback later for
VApp::after(), installed with
VPlatform::set_timer_handler().
Runs callback once on the UI thread after milliseconds. A timer can't
be canceled, so a caller that may change its mind has the callback check
whether it's still wanted, like by comparing a counter that each newer
timer bumps.
using PostHandler = std::function<void (std::function<void ()>)>
Platform hook that runs a callback on the UI thread, from any thread, for
VApp::post(), installed with
VPlatform::set_post_handler().
VApp must only be used from the UI thread, so a worker thread hands its
results (like a log line or a finished build) to post() instead of
touching the app. The hook must be safe to call from any thread, and must
queue callback to run on the UI thread rather than run it right away.
Desktop only: the web and Android shells install no handler.
using OpenUrlHandler = std::function<void (const std::string &)>
Platform hook that opens a URL in the system browser for
VApp::open_url(), installed with
VPlatform::set_open_url_handler().
The web shell also installs one with
VPlatform::set_navigate_handler(),
which opens the URL in the current tab instead.
using CopyTextHandler = std::function<void (const std::string &)>
Platform hook that puts text on the system clipboard for
VApp::copy_text(), installed with
VPlatform::set_copy_text_handler().
Browsers only allow clipboard writes during a user action, so on web,
copy_text() only works when called from a click handler.
using SaveTextHandler = std::function<void (const std::string &, const std::string &, const std::string &, SaveTextCallback)>
Platform hook that saves text as a file for
VApp::save_text(), installed with
VPlatform::set_save_text_handler().
Desktop and Android show a save dialog, while web downloads the file directly.
suggested_name is the file name to start with, like "notes.json".mime_type is the content's type, like "application/json".using RunProcessHandler = std::function<void (const int &, ProcessLineCallback, ProcessExitCallback)>
Platform hook that runs another program and streams its output back for
VApp::run_process(), installed with
VPlatform::set_run_process_handler().
argv[0] is the program. A path runs as given, while a bare name is
looked for next to the app's executable first (where companion tools
ship), then on the PATH. Both callbacks run on the UI thread.
Desktop only: the web and Android shells install no handler.
using PurchaseHandler = std::function<void (const std::string &, const std::string &, const std::string &, PurchaseCallback)>
Platform hook that runs the store's purchase flow for
VApp::start_purchase(), installed with
VPlatform::set_purchase_handler().
Shows the store's purchase sheet, then calls callback with the result.
product_id and plan_id name what to buy in the store's catalog,
like a subscription and its "monthly-3" plan.account_id is an opaque ID for the user's account, which the store
uses to detect fraud.Android only: Google Play. Desktop and web apps take payments some other way, like on a website, and install no handler.
using QueryPurchasesHandler = std::function<void (QueryPurchasesCallback)>
Platform hook that lists the purchases that the user owns but that the
server hasn't verified, for
VApp::query_purchases(), installed with
VPlatform::set_query_purchases_handler().
A purchase can go through at the store but never reach the server, like when the app closes mid-purchase, and the store refunds a purchase that isn't confirmed within a few days. So an app calls this at launch and sends each token to its server again. Nothing shows on screen.
Android only: the desktop and web shells install no handler.