feat(marketplace): enhance install logic with download tracking and installation checks

This commit is contained in:
alexsparkes
2026-02-02 13:29:26 +00:00
parent 333a070020
commit 3fc5d736c8
2 changed files with 30 additions and 2 deletions

View File

@@ -10,6 +10,10 @@ export const useMarketplaceInstall = () => {
const controllerRef = useRef(new AbortController());
const installItem = (type, data) => {
// Check if item is already installed before calling install
const installed = JSON.parse(localStorage.getItem('installed') || '[]');
const isNewInstall = !installed.some((item) => item.id === data.id || item.name === data.name);
install(type, data);
toast(variables.getMessage('toasts.installed'));
variables.stats.postEvent('marketplace-item', `${data.display_name || data.name} installed`);

View File

@@ -1,5 +1,6 @@
import EventBus from 'utils/eventbus';
import { clearQueuesOnSettingChange } from 'utils/queueOperations';
import variables from 'config/variables';
// todo: relocate this function
function showReminder() {
@@ -7,9 +8,29 @@ function showReminder() {
localStorage.setItem('showReminder', true);
}
/**
* Track download count in the API
*/
async function trackDownload(itemId) {
if (!itemId) return;
try {
await fetch(`${variables.constants.API_URL}/marketplace/item/${itemId}/download`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
});
} catch (error) {
console.debug('Failed to track download:', error);
}
}
export function install(type, input, sideload, collection) {
let refreshEvent = null;
// Check if item is already installed to determine if we should track download
const installed = JSON.parse(localStorage.getItem('installed') || '[]');
const isNewInstall = !installed.some((item) => item.id === input.id || item.name === input.name);
switch (type) {
case 'settings': {
localStorage.removeItem('backup_settings');
@@ -73,8 +94,6 @@ export function install(type, input, sideload, collection) {
break;
}
const installed = JSON.parse(localStorage.getItem('installed'));
if (sideload) {
input.sideload = true;
}
@@ -83,6 +102,11 @@ export function install(type, input, sideload, collection) {
localStorage.setItem('installed', JSON.stringify(installed));
// Track download for new installs (not re-installs)
if (isNewInstall && input.id) {
trackDownload(input.id);
}
// Emit refresh event after all data is saved
if (refreshEvent) {
EventBus.emit('refresh', refreshEvent);