// A simple plugin that stores the history of scan durations
function init() {
$app.onScanCompleted((e) => {
// Store the scanning duration (in ms)
$store.set("scan-completed", e.duration)
e.next()
})
$ui.register((ctx) => {
// Callback is triggered when the value is updated
$store.watch<number>("scan-completed", (value) => {
const date = new Date()
const now = date.toISOString().replaceall(".", "_")
// Add the value to the history
$storage.set("scan-duration-history."+now, {
duration: value,
durationInSeconds: value/1000,
addedAt: date,
})
ctx.toast.info(`Scanning took ${value/1000} seconds!`)
})
function deleteHistory() {
$storage.remove("scan-duration-history")
}
})
}
Make sure your storage doesn't grow too big by doing some cleanup.
Good to know
The plugin storage is deleted when the plugin is uninstalled.