pub struct Moonbase<R: Runtime>(/* private fields */);Expand description
The plugin’s license controller, managed as Tauri state. Reach it from Rust
with MoonbaseExt::moonbase to gate features or
drive activation without the webview.
Every method that talks to Moonbase or the disk blocks; call those from a
worker thread or spawn_blocking. state,
is_licensed, license and
has_sub_product never block on I/O.
Implementations§
Source§impl<R: Runtime> Moonbase<R>
impl<R: Runtime> Moonbase<R>
Sourcepub fn licensing(&self) -> &Licensing
pub fn licensing(&self) -> &Licensing
The SDK instance behind the plugin, for anything the plugin does not wrap.
Sourcepub fn is_licensed(&self) -> bool
pub fn is_licensed(&self) -> bool
Is there a valid license right now? Lock-free, so cheap enough to check anywhere you gate a feature.
Sourcepub fn has_sub_product(&self, sub_product_id: &str) -> bool
pub fn has_sub_product(&self, sub_product_id: &str) -> bool
Whether to unlock an add-on on this device: the license in force lists it
as active and it hasn’t expired. Takes the add-on’s own part of its product
ID ("drum-kit") or its whole ID ("my-app.drum-kit"). False while no
license is in force.
Sourcepub fn active_sub_products(&self) -> Vec<String>
pub fn active_sub_products(&self) -> Vec<String>
The add-ons has_sub_product is true for right
now, by their own part of their product ID.
Sourcepub fn license_file(&self) -> PathBuf
pub fn license_file(&self) -> PathBuf
Where the license is kept.
Sourcepub fn state(&self) -> LicenseState
pub fn state(&self) -> LicenseState
A snapshot of the license state, as the UI sees it.
Sourcepub fn activate(&self, method: ActivationMethod) -> Result<LicenseState>
pub fn activate(&self, method: ActivationMethod) -> Result<LicenseState>
Start a browser activation: create the request, open the browser, and poll
in the background until it completes. Returns once the request exists, with
its link in LicenseState::activation.
ActivationMethod::Offline mints an offline license through the same
browser flow, for a machine that has network now but will not later.
Sourcepub fn cancel_activation(&self) -> LicenseState
pub fn cancel_activation(&self) -> LicenseState
Stop waiting for a browser activation. A license held from before stays.
Sourcepub fn refresh(&self, force: bool) -> Result<LicenseState>
pub fn refresh(&self, force: bool) -> Result<LicenseState>
Re-check the license against Moonbase and refresh its entitlements in
place: call it after a purchase so new features and add-ons load without a
restart. force skips the online-validation throttle.
A revoked or lapsed license locks, and so does one that cannot be checked once the offline grace period has run out; within it a network failure keeps the license and returns the error. No-op for offline licenses, and while an activation is in progress (it brings a fresh license of its own).
With Status::NotCovered it re-checks the license that doesn’t cover this
version, so once the customer has bought the upgrade the app unlocks.
Sourcepub fn deactivate(&self) -> Result<LicenseState>
pub fn deactivate(&self) -> Result<LicenseState>
Free this device’s seat and lock. Offline and trial licenses cannot be revoked, so those are forgotten locally instead. When Moonbase cannot be reached the license is kept, and the error says so. Also hands back the seat of a license that doesn’t cover this version of the app.
Sourcepub fn forget(&self) -> LicenseState
pub fn forget(&self) -> LicenseState
Forget the license on this device only, without telling Moonbase.
Sourcepub fn device_token(&self) -> Result<String>
pub fn device_token(&self) -> Result<String>
The device token (“machine file”) for activating a machine with no network:
save it as a .dt file the customer exchanges at
https://<tenant>.moonbase.sh/activate for a license file, then pass that
file’s contents to activate_offline.
Sourcepub fn activate_offline(
&self,
license_file_contents: &str,
) -> Result<LicenseState>
pub fn activate_offline( &self, license_file_contents: &str, ) -> Result<LicenseState>
Activate from the contents of an offline license file.
A license file for this device that doesn’t cover this version of the app
is stored anyway, as it still covers the versions it did, and the app locks
with Status::NotCovered; the error says so.
Sourcepub fn upgrade_license(&self) -> Result<LicenseState>
pub fn upgrade_license(&self) -> Result<LicenseState>
Offer the upgrade the app needs. With Status::NotCovered, open the
upgrade page Moonbase named for the license or, without one, start an online
activation, whose browser page offers the upgrade where the store sells one
and activates this device once a license covers this version. Otherwise open
the upgrade page check_update found for a new
version the license doesn’t cover. After the purchase,
refresh picks up the upgraded license.
Sourcepub fn dismiss_error(&self) -> LicenseState
pub fn dismiss_error(&self) -> LicenseState
Clear the last failure, e.g. when the user dismisses its message.
Sourcepub fn device(&self) -> DeviceInfo
pub fn device(&self) -> DeviceInfo
This device, for diagnostics.
Sourcepub fn check_update(&self) -> Result<UpdateInfo>
pub fn check_update(&self) -> Result<UpdateInfo>
Whether a newer release than this app is out, with its notes when it is. Only the notes need the network. For a customer whose licenses don’t cover the new version, says so and where to upgrade.
Sourcepub fn update_download_url(&self) -> Result<DownloadTarget>
pub fn update_download_url(&self) -> Result<DownloadTarget>
A short-lived download link for the latest installer for this platform.
Fails with moonbase::Error::ReleaseNotCovered, with the upgrade link,
when the customer’s licenses don’t cover the release.
Sourcepub fn load_add_ons(&self) -> Result<LicenseState>
pub fn load_add_ons(&self) -> Result<LicenseState>
List the product’s add-ons for this device into LicenseState::add_ons,
with their prices, ownership and trials, for a store or upgrade screen.
Can take a seat: with
auto_activate_sub_products on
(the default), when the list shows an add-on the customer owns, with a seat
free, that the license doesn’t hold yet (one bought since the license was
last checked), the license is re-checked once, which takes that seat as
every check does, and the add-ons are listed again. With the option off it
only reads.
Sourcepub fn refresh_add_ons(&self) -> Result<LicenseState>
pub fn refresh_add_ons(&self) -> Result<LicenseState>
Re-check the license, so an add-on bought since takes its seat, then list the add-ons again: what “Bought an add-on? Refresh” does after a purchase in the browser.
Sourcepub fn activate_sub_product(&self, sub_product_id: &str) -> Result<LicenseState>
pub fn activate_sub_product(&self, sub_product_id: &str) -> Result<LicenseState>
Take a seat of an add-on the customer owns for this device, from the full
license in force: one whose seat was revoked here, or any, with
auto_activate_sub_products
off. Stores the license that comes back, and lists the add-ons again if they
were loaded.
One add-on at a time; why one failed is also in
AddOnsState::action_error, worded for
the customer. A license the server no longer accepts is re-checked, and
locks as refresh would.
Sourcepub fn request_sub_product_trial(
&self,
sub_product_id: &str,
) -> Result<LicenseState>
pub fn request_sub_product_trial( &self, sub_product_id: &str, ) -> Result<LicenseState>
Start the trial of an add-on the customer doesn’t own on this device, from
the full license in force (owning it, they get a seat instead). Otherwise as
activate_sub_product.
Sourcepub fn buy_sub_product(&self, sub_product_id: &str) -> Result<()>
pub fn buy_sub_product(&self, sub_product_id: &str) -> Result<()>
Open the add-on’s buy link from LicenseState::add_ons in the browser.
When the app then goes to the background (the customer is in the browser)
and comes back to the front, the add-ons are refreshed as
refresh_add_ons does, so one just bought unlocks
without a click.
Source§impl<R: Runtime> Moonbase<R>
impl<R: Runtime> Moonbase<R>
Sourcepub fn present(&self, screen: Option<Screen>) -> Result<()>
pub fn present(&self, screen: Option<Screen>) -> Result<()>
Show the activation window, creating it if needed, and bring it to the
front; or, with Presentation::Overlay, mount the overlay over its
window. screen opens it on a particular Screen; without one it shows
whatever the license state calls for.
Sourcepub fn close_ui(&self) -> Result<()>
pub fn close_ui(&self) -> Result<()>
Close the activation window, or take the overlay down, if it is showing.
Sourcepub fn skip_update(&self, version: &str) -> Result<()>
pub fn skip_update(&self, version: &str) -> Result<()>
Never prompt for this release again; a newer one still prompts.
Sourcepub fn save_machine_file(&self) -> Result<Option<PathBuf>>
pub fn save_machine_file(&self) -> Result<Option<PathBuf>>
Save the machine file for offline activation: through a save dialog when
the app has registered tauri-plugin-dialog, otherwise into Downloads,
revealed in the file manager. None when the user cancels.
Sourcepub fn download_update(&self) -> Result<()>
pub fn download_update(&self) -> Result<()>
Download the latest installer for this platform into Downloads, reporting progress to the window, then reveal it.
Sourcepub fn reveal_update(&self) -> Result<()>
pub fn reveal_update(&self) -> Result<()>
Show the downloaded installer in the file manager again.