From e6194f028d7650d6e2330749b84f02468bd8fc55 Mon Sep 17 00:00:00 2001 From: jelveh Date: Fri, 20 Dec 2024 06:58:02 -0800 Subject: [PATCH] support `icon_size` in the `apps` module of Puter.js and Dev Center --- src/dev-center/js/dev-center.js | 20 ++++++++++---------- src/puter-js/src/modules/Apps.js | 23 ++++++++++++++++++++--- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/dev-center/js/dev-center.js b/src/dev-center/js/dev-center.js index b01560127..db6bd784d 100644 --- a/src/dev-center/js/dev-center.js +++ b/src/dev-center/js/dev-center.js @@ -144,7 +144,7 @@ $(document).ready(function () { }) } // Get apps - puter.apps.list().then((resp) => { + puter.apps.list({params:{ icon_size: 64}}).then((resp) => { apps = resp; // hide loading @@ -184,7 +184,7 @@ function refresh_app_list(show_loading = false) { // uncheck the select all checkbox $('.select-all-apps').prop('checked', false); - puter.apps.list().then((apps_res) => { + puter.apps.list({params:{ icon_size: 64}}).then((apps_res) => { $('#loading').hide(); apps = apps_res; if (apps.length > 0) { @@ -315,7 +315,7 @@ async function create_app(title, source_path = null, items = null) { background: false, }).then(async (app) => { // refresh app list - puter.apps.list().then(async (resp) => { + puter.apps.list({params:{ icon_size: 64}}).then(async (resp) => { apps = resp; // Close the 'Creting new app...' modal // but make sure it was shown for at least 2 seconds @@ -375,7 +375,7 @@ $(document).on('click', '.delete-app', async function (e) { let app_name = $(this).attr('data-app-name'); // get app - const app_data = await puter.apps.get(app_name); + const app_data = await puter.apps.get(app_name, {params:{ icon_size: 16}}); if(app_data.metadata?.locked){ puter.ui.alert(`${app_data.title} is locked and cannot be deleted.`, [ @@ -758,7 +758,7 @@ async function edit_app_section(cur_app_name) { $('.tab-btn').removeClass('active'); $('.tab-btn[data-tab="apps"]').addClass('active'); - let cur_app = await puter.apps.get(cur_app_name); + let cur_app = await puter.apps.get(cur_app_name, {params: {icon_size: 128}}); currently_editing_app = cur_app; // generate edit app section @@ -1309,7 +1309,7 @@ $(document).on('click', '.delete-app-settings', async function (e) { let app_title = $(this).attr('data-app-title'); // check if app is locked - const app_data = await puter.apps.get(app_name); + const app_data = await puter.apps.get(app_name, {params: {icon_size: 16}}); if(app_data.metadata?.locked){ puter.ui.alert(`${app_data.title} is locked and cannot be deleted.`, [ @@ -1385,7 +1385,7 @@ $(document).on('click', '.back-to-main-btn', function (e) { // get apps $('#loading').show(); setTimeout(function () { - puter.apps.list().then((apps_res) => { + puter.apps.list({params: {icon_size: 64}}).then((apps_res) => { // uncheck the select all checkbox $('.select-all-apps').prop('checked', false); @@ -2174,7 +2174,7 @@ $(document).on('click', '.insta-deploy-to-existing-app', function (e) { $('.insta-deploy-modal').get(0).close(); $('.insta-deploy-existing-app-select').get(0).showModal(); $('.insta-deploy-existing-app-list').html(`
${loading_spinner}
`); - puter.apps.list().then((apps) => { + puter.apps.list({params:{ icon_size: 64}}).then((apps) => { setTimeout(() => { $('.insta-deploy-existing-app-list').html(''); if (apps.length === 0) @@ -2367,7 +2367,7 @@ $('.insta-deploy-existing-app-select').on('close', function (e) { $('.refresh-app-list').on('click', function (e) { $('.loading-modal').get(0)?.showModal(); - puter.apps.list().then((resp) => { + puter.apps.list({params:{ icon_size: 64}}).then((resp) => { setTimeout(() => { apps = resp; @@ -2500,7 +2500,7 @@ $(document).on('click', '.delete-apps-btn', async function (e) { const app_name = $(app).attr('data-app-name'); // get app - const app_data = await puter.apps.get(app_name); + const app_data = await puter.apps.get(app_name, {params: {icon_size: 64}}); if(app_data.metadata?.locked){ if(apps.length === 1){ diff --git a/src/puter-js/src/modules/Apps.js b/src/puter-js/src/modules/Apps.js index c3cf3457d..f0f8059da 100644 --- a/src/puter-js/src/modules/Apps.js +++ b/src/puter-js/src/modules/Apps.js @@ -40,8 +40,13 @@ class Apps{ list = async (...args) => { let options = {}; - options = { "predicate": ['user-can-edit'] }; - + // if args is a single object, assume it is the options object + if (typeof args[0] === 'object' && args[0] !== null) { + options = args[0]; + } + + options.predicate = ['user-can-edit']; + return utils.make_driver_method(['uid'], 'puter-apps', undefined, 'select').call(this, options); } @@ -112,11 +117,23 @@ class Apps{ get = async(...args) => { let options = {}; + // if there is one string argument, assume it is the app name // * allows for: puter.apps.get('example-app') * if (Array.isArray(args) && typeof args[0] === 'string') { - options = { id: {name: args[0]}}; + // if second argument is an object, assume it is the options object + if (typeof args[1] === 'object' && args[1] !== null) { + options = args[1]; + } + // name + options.id = {name: args[0]}; } + + // if first argument is an object, assume it is the options object + if (typeof args[0] === 'object' && args[0] !== null) { + options = args[0]; + } + return utils.make_driver_method(['uid'], 'puter-apps', undefined, 'read').call(this, options); }