diff --git a/src/lib/auth.js b/src/lib/auth.js index c8911be88..a40ad605b 100644 --- a/src/lib/auth.js +++ b/src/lib/auth.js @@ -1,5 +1,6 @@ import toast from "components/toast"; import { addIntentHandler } from "handlers/intent"; +import constants from "./constants"; const loginEvents = { listeners: new Set(), @@ -50,7 +51,7 @@ class AuthService { } async openLoginUrl() { - const url = "https://acode.app/login?redirect=app"; + const url = `${constants.BASE_URL}/login?redirect=app`; try { await new Promise((resolve, reject) => { diff --git a/src/lib/constants.js b/src/lib/constants.js index f1315999a..8e1e1f562 100644 --- a/src/lib/constants.js +++ b/src/lib/constants.js @@ -19,6 +19,9 @@ export default { get PLAY_STORE_URL() { return `https://play.google.com/store/apps/details?id=${BuildInfo.packageName}`; }, + + //changing url here is not enough, also change in src/plugins/auth/src/android/Authenticator.java + BASE_URL: "https://acode.app", API_BASE: "https://acode.app/api", // API_BASE: 'https://192.168.0.102:3001/api', // test api SKU_LIST: ["crystal", "bronze", "silver", "gold", "platinum", "titanium"], diff --git a/src/lib/installPlugin.js b/src/lib/installPlugin.js index 5488d9131..ffabfeeb8 100644 --- a/src/lib/installPlugin.js +++ b/src/lib/installPlugin.js @@ -66,40 +66,23 @@ export default async function installPlugin( try { if (!isDependency) loaderDialog.show(); - let plugin; - if ( - pluginUrl.includes(constants.API_BASE) || - pluginUrl.startsWith("file:") || - pluginUrl.startsWith("content:") - ) { - // Use fsOperation for Acode registry URL - plugin = await fsOperation(pluginUrl).readFile( - undefined, - (loaded, total) => { - loaderDialog.setMessage( - `${strings.loading} ${((loaded / total) * 100).toFixed(2)}%`, - ); - }, - ); - } else { - // cordova http plugin for others - plugin = await new Promise((resolve, reject) => { - cordova.plugin.http.sendRequest( - pluginUrl, - { - method: "GET", - responseType: "arraybuffer", - }, - (response) => { - resolve(response.data); - loaderDialog.setMessage(`${strings.loading} 100%`); - }, - (error) => { - reject(error); - }, + const tempPath = cordova.file.cacheDirectory + "plugin_download.zip"; + + await new Promise((resolve, reject) => { + cordova.exec(resolve, reject, "Authenticator", "downloadPlugin", [ + pluginUrl, + tempPath, + ]); + }); + + let plugin = await fsOperation(tempPath).readFile( + undefined, + (loaded, total) => { + loaderDialog.setMessage( + `${strings.loading} ${((loaded / total) * 100).toFixed(2)}%`, ); - }); - } + }, + ); if (plugin) { const zip = new JSZip(); diff --git a/src/pages/plugin/plugin.js b/src/pages/plugin/plugin.js index 56f7f7f86..1d1d2cf8a 100644 --- a/src/pages/plugin/plugin.js +++ b/src/pages/plugin/plugin.js @@ -139,12 +139,35 @@ export default async function PluginInclude( try { loader.showTitleLoader(); if ((await helpers.checkAPIStatus()) && isValidSource(plugin.source)) { - const remotePlugin = await fsOperation( - constants.API_BASE, - `plugin/${id}`, - ) - .readFile("json") - .catch(() => null); + const remotePlugin = await new Promise((resolve) => { + cordova.exec( + (result) => { + if (!result) return resolve(null); + if (typeof result === "string") { + try { + return resolve(JSON.parse(result)); + } catch (err) { + console.warn( + "[Plugin Debug] fetchWithToken invalid JSON:", + result.slice(0, 120), + ); + return resolve(null); + } + } + resolve(result); + }, + (err) => { + console.warn( + "[Plugin Debug] fetchWithToken native error:", + err, + ); + resolve(null); + }, + "Authenticator", + "fetchWithToken", + [Url.join(constants.API_BASE, "plugin", id)], + ); + }).catch(() => null); if (cancelled || !remotePlugin) return; @@ -159,22 +182,41 @@ export default async function PluginInclude( plugin = Object.assign({}, remotePlugin); - if (!Number.parseFloat(remotePlugin.price)) return; + if (!Number.parseFloat(remotePlugin.price) && !remotePlugin.owned) + return; isPaid = remotePlugin.price > 0; + //console.log(`[Plugin Debug] Fetched remotePlugin - id: ${remotePlugin.id}, owned: ${remotePlugin.owned}, price: ${remotePlugin.price}, sku: ${remotePlugin.sku}, isPaid: ${isPaid}`); + try { [product] = await helpers.promisify(iap.getProducts, [ remotePlugin.sku, ]); + //console.log(`[Plugin Debug] IAP getProducts result - product:`, product); + if (product) { const purchase = await getPurchase(product.productId); - purchased = !!purchase; + purchased = !!purchase || remotePlugin.owned; price = product.price; purchaseToken = purchase?.purchaseToken; + //console.log(`[Plugin Debug] IAP path - purchase found: ${!!purchase}, purchased: ${purchased}, price: ${price}`); + } else if (remotePlugin.owned) { + purchased = true; + price = remotePlugin.price; + //console.log(`[Plugin Debug] No IAP product but owned=true - purchased: ${purchased}, price: ${price}`); } } catch (error) { + //console.log(`[Plugin Debug] IAP error:`, error.message); helpers.error(error); + // If IAP fails but plugin is owned via Razorpay, mark as purchased + if (remotePlugin.owned) { + purchased = true; + price = remotePlugin.price; + //console.log(`[Plugin Debug] IAP failed but owned=true - purchased: ${purchased}, price: ${price}`); + } } + + //console.log(`[Plugin Debug] Final state before render - isPaid: ${isPaid}, purchased: ${purchased}, price: ${price}, installed: ${installed}`); } } catch (error) { console.error(error); @@ -321,6 +363,8 @@ export default async function PluginInclude( } async function render() { + //console.log(`[Plugin Render Debug] Values being rendered - isPaid: ${isPaid}, purchased: ${purchased}, price: ${price}, installed: ${installed}, id: ${plugin.id}`); + const pluginSettings = settings.uiSettings[`plugin-${plugin.id}`]; $page.body = view({ ...plugin, diff --git a/src/pages/plugin/plugin.view.js b/src/pages/plugin/plugin.view.js index 3ae08a9c4..fa90d55e6 100644 --- a/src/pages/plugin/plugin.view.js +++ b/src/pages/plugin/plugin.view.js @@ -281,6 +281,8 @@ function Buttons({ buy, minVersionCode, }) { + //console.log(`[Buttons Debug] isPaid: ${isPaid}, installed: ${installed}, update: ${update}, purchased: ${purchased}, price: ${price}, minVersionCode: ${minVersionCode}`); + if ( typeof minVersionCode === "number" && minVersionCode > BuildInfo.versionCode @@ -330,6 +332,7 @@ function Buttons({ } if (isPaid && !purchased && price) { + //console.log(`[Buttons] Showing BUY button - isPaid: true, !purchased: true, price: ${price}`); return (