Nucleus
Microsoft Store

Microsoft StoreNew

Sell a Nucleus app on the Microsoft Store, from Kotlin: the app's license and free trial, add-ons, in-app updates, and submissions from CI.

View as Markdown

The microsoft-store module talks to the Microsoft Store (Windows.Services.Store) from the app the Store installed. One object, MicrosoftStore, covers what you sell and how the app updates:

Entry pointWhat it does
MicrosoftStore.purchasesThe app's own license and free trial, add-ons (durables, consumables, subscriptions), and the license changes the Store reports
MicrosoftStore.updatesChecks the Store for a newer version and installs it from inside the app
microsoft-storeWindowsGradle plugin: RequiredWindow runtime: Not neededNeeds the MSIX package identity the plugin builds.

The Lab, Nucleus's test bench, ships on the Microsoft Store with this module: a paid app with a 7-day trial and four add-ons. Its probes system.purchases and system.store-updates call every function on this page.

PageCovers
Sell on the Microsoft StoreReserve the app in Partner Center, package it, submit it, test it
App license and free trialSell the app itself, offer a trial, convert it from the app
Add-onsDurables, consumables and subscriptions bought inside the app
App updatesFind a newer version on the Store and install it without leaving the app
Submit from CISend every tagged version to Partner Center from GitHub Actions

Add the dependency

build.gradle.kts
dependencies {
    implementation("dev.nucleusframework:nucleus.microsoft-store:3.0.0")
}

Where it works

The Store only answers an app it installed: an MSIX/AppX package whose identity matches a Partner Center listing. Build it with TargetFormat.AppX (see Sell on the Microsoft Store).

Where the app runsavailability()Store calls
Installed from the Store, or installed from its MSIX with the listing's identityAvailableWork
NSIS, MSI, Portable, or ./gradlew runNotPackagedFail with StoreErrorCode.NotPackaged
macOS, LinuxUnsupportedFail with StoreErrorCode.Unsupported
import dev.nucleusframework.store.microsoft.MicrosoftStore
import dev.nucleusframework.store.microsoft.StoreAvailability

if (MicrosoftStore.availability() == StoreAvailability.Available) {
    if (MicrosoftStore.purchases.appLicense().isFullLicense) unlockEverything()
}

MicrosoftStore.isSupported is true on Windows when the native bridge loaded. It says nothing about the package: check availability() before you show any Store UI.

Calls, threads and cancellation

  • Every call suspends without blocking a thread, and you may call it from any thread, the UI thread included.
  • Cancelling the coroutine cancels the Store operation behind it.
  • Store failures throw StoreException, except purchase() and purchaseApp(), which return them as PurchaseResult.Failed.
  • The Store's dialogs (purchase, update) need a window to sit on. Pass your window's handle, or let the module pick this app's foreground window:
import dev.nucleusframework.application.LocalNucleusWindow

@Composable
fun BuyButton() {
    val hwnd = LocalNucleusWindow.current.unsafe.taoWindow?.nativeHandle
    val scope = rememberCoroutineScope()
    Button(onClick = {
        scope.launch {
            MicrosoftStore.purchases.purchase("pro") { windows { ownerWindowHandle = hwnd } }
        }
    }) { Text("Buy Pro") }
}

The Store keeps the first window it was given for the life of the process.

Errors

StoreException.code tells you what failed; platformCode carries the Windows HRESULT when the failure came from the Store API.

StoreErrorCodeMeaning
UnsupportedNo Microsoft Store on this OS, or the native bridge failed to load
NotPackagedThe process has no package identity (NSIS, MSI, Portable, run)
NotAssociatedThe Store has no listing for this package (0x803F6107): the app is not published yet, or its identity differs from the Partner Center reservation
NoOwnerWindowNo visible window of this app to put the Store's dialog on
ProductNotFoundNo add-on with that product id for this app
Network, ServerThe Store's service was unreachable, or answered with an error
InsufficientQuantityA Store-managed consumable has fewer units left than you consumed
InvalidArgumentAn empty product id, a zero quantity, a foreign consume token
UpdateBlockedThe Store holds an app update until the device charges or reaches Wi-Fi
PlatformAny other Store error; see platformCode
InternalA bug in the module or its native bridge

Logging

The module logs through java.util.logging under dev.nucleusframework.store.microsoft. At FINE, it logs every license change the Store reports, with the app's license and the add-ons it covers. Raise that logger's level to see them, or set allowNucleusRuntimeLogging = true (dev.nucleusframework.core.runtime.tools).

Other stores

microsoft-store covers the Microsoft Store only, and MicrosoftStore reports Unsupported on macOS and Linux. Flathub and the Mac App Store have their own sections, Flathub and Mac App Store.

Was this page helpful?
Edit on GitHub

Last updated on