mirror of
https://github.com/mue/mue.git
synced 2026-07-23 16:57:25 +02:00
feat(marketplace): enhance install logic with download tracking and installation checks
This commit is contained in:
@@ -10,6 +10,10 @@ export const useMarketplaceInstall = () => {
|
|||||||
const controllerRef = useRef(new AbortController());
|
const controllerRef = useRef(new AbortController());
|
||||||
|
|
||||||
const installItem = (type, data) => {
|
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);
|
install(type, data);
|
||||||
toast(variables.getMessage('toasts.installed'));
|
toast(variables.getMessage('toasts.installed'));
|
||||||
variables.stats.postEvent('marketplace-item', `${data.display_name || data.name} installed`);
|
variables.stats.postEvent('marketplace-item', `${data.display_name || data.name} installed`);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import EventBus from 'utils/eventbus';
|
import EventBus from 'utils/eventbus';
|
||||||
import { clearQueuesOnSettingChange } from 'utils/queueOperations';
|
import { clearQueuesOnSettingChange } from 'utils/queueOperations';
|
||||||
|
import variables from 'config/variables';
|
||||||
|
|
||||||
// todo: relocate this function
|
// todo: relocate this function
|
||||||
function showReminder() {
|
function showReminder() {
|
||||||
@@ -7,9 +8,29 @@ function showReminder() {
|
|||||||
localStorage.setItem('showReminder', true);
|
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) {
|
export function install(type, input, sideload, collection) {
|
||||||
let refreshEvent = null;
|
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) {
|
switch (type) {
|
||||||
case 'settings': {
|
case 'settings': {
|
||||||
localStorage.removeItem('backup_settings');
|
localStorage.removeItem('backup_settings');
|
||||||
@@ -73,8 +94,6 @@ export function install(type, input, sideload, collection) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const installed = JSON.parse(localStorage.getItem('installed'));
|
|
||||||
|
|
||||||
if (sideload) {
|
if (sideload) {
|
||||||
input.sideload = true;
|
input.sideload = true;
|
||||||
}
|
}
|
||||||
@@ -83,6 +102,11 @@ export function install(type, input, sideload, collection) {
|
|||||||
|
|
||||||
localStorage.setItem('installed', JSON.stringify(installed));
|
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
|
// Emit refresh event after all data is saved
|
||||||
if (refreshEvent) {
|
if (refreshEvent) {
|
||||||
EventBus.emit('refresh', refreshEvent);
|
EventBus.emit('refresh', refreshEvent);
|
||||||
|
|||||||
Reference in New Issue
Block a user