Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/lib/auth.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import toast from "components/toast";
import { addIntentHandler } from "handlers/intent";
import constants from "./constants";

const loginEvents = {
listeners: new Set(),
Expand Down Expand Up @@ -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) => {
Expand Down
3 changes: 3 additions & 0 deletions src/lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
49 changes: 16 additions & 33 deletions src/lib/installPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
60 changes: 52 additions & 8 deletions src/pages/plugin/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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}`);
}
Comment thread
RohitKushvaha01 marked this conversation as resolved.
} 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);
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions src/pages/plugin/plugin.view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -330,6 +332,7 @@ function Buttons({
}

if (isPaid && !purchased && price) {
//console.log(`[Buttons] Showing BUY button - isPaid: true, !purchased: true, price: ${price}`);
return (
<button data-type="buy" className="btn btn-install" onclick={buy}>
<i className="icon cart"></i>
Expand All @@ -339,6 +342,7 @@ function Buttons({
}

if (isPaid && !purchased && !price) {
//console.log(`[Buttons] Showing PRODUCT NOT AVAILABLE - isPaid: true, !purchased: true, !price: true`);
return (
<div style={{ margin: "auto" }} className="flex-center">
<span
Expand All @@ -350,6 +354,7 @@ function Buttons({
);
}

//console.log(`[Buttons] Showing INSTALL button - falling through to default`);
return (
<button data-type="install" className="btn btn-install" onclick={install}>
<i className="icon save_alt"></i>
Expand Down
Loading