Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ jobs:
distribution: temurin
java-version: '26'

- name: Install native unit test dependencies
run: |
sudo apt-get update
sudo apt-get install --no-install-recommends -y clang libsqlite3-dev

- name: Run unit tests
run: npm run test

Expand Down
20 changes: 19 additions & 1 deletion .github/workflows/native-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ on:
schedule:
- cron: "0 5 * * *"
workflow_dispatch:
inputs:
alpine_node_tests:
description: 'Run Alpine Node/Vite integration tests (npm access; may hit hosted-runner process exits)'
type: boolean
default: false
sponsor_privacy_tests:
description: 'Run StoreKit sponsorship and privacy bridge UI integration tests'
type: boolean
default: false

permissions:
contents: read
Expand Down Expand Up @@ -152,13 +161,17 @@ jobs:
}
JS
- name: Build and run simulator tests with SSH and FTP fixtures
env:
RUN_ALPINE_NODE_TESTS: ${{ inputs.alpine_node_tests || false }}
RUN_SPONSOR_PRIVACY_TESTS: ${{ inputs.sponsor_privacy_tests || false }}
run: |
python3 -m venv .ios-build/ssh-fixture-venv
.ios-build/ssh-fixture-venv/bin/pip install -r tests/fixtures/ssh/requirements.txt
# Temporarily exclude Alpine process exits on hosted runners (run 41789669396).
# Local runs retain these tests; InAppRunnerTests also starts Alpine.
skips=()
for test in AlpineInteractionTests AlpineLspTests AlpinePackageTests AlpineSignalTests AlpineSimdTests AlpineTerminalServerTests AlpineTerminalTests InAppRunnerTests; do
for test in AlpineInteractionTests AlpineLspTests AlpineNodeTests AlpinePackageTests AlpineSignalTests AlpineSimdTests AlpineTerminalServerTests AlpineTerminalTests InAppRunnerTests; do
if [[ "$test" == AlpineNodeTests && "$RUN_ALPINE_NODE_TESTS" == true ]]; then continue; fi
skips+=("-skip-testing:runnerTests/$test")
done
# StoreKit test sessions and these web UI interactions fail on every hosted run
Expand All @@ -174,6 +187,11 @@ jobs:
runnerUITests/WebContextMenuUITests; do
skips+=("-skip-testing:$test")
done
if [[ "$RUN_SPONSOR_PRIVACY_TESTS" != true ]]; then
skips+=("-skip-testing:runnerTests/SponsorPurchaseTests")
skips+=("-skip-testing:runnerTests/AdsBridgeTests/testPrivacyBridgeReturnsOnlyCurrentIabSignals")
skips+=("-skip-testing:runnerTests/AdsBridgeTests/testPrivacySnapshotReflectsWithdrawalAndRemovedSignals")
fi
.ios-build/ssh-fixture-venv/bin/python tests/fixtures/ssh/server.py -- npm run test:ios -- --target=${{ steps.simulator.outputs.id }} "${skips[@]}"
- name: Run iPad startup and native UI checks
run: |
Expand Down
1,312 changes: 669 additions & 643 deletions CHANGELOG.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "acode-app",
"displayName": "Acode",
"version": "1.13.6",
"versionCode": 1023,
"version": "1.13.7",
"versionCode": 1024,
"androidPackageId": "com.foxdebug.acode",
"appleAppId": "app.acode",
"description": "Powerful code editor and terminal for IOS and Android",
Expand Down
19 changes: 19 additions & 0 deletions platforms/android/app/src/main/assets/init-alpine.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,25 @@ fi
required_packages="bash command-not-found tzdata wget curl libstdc++"
if [ "$ALPINE_ROOT" = "/" ]; then
required_packages="$required_packages procps-ng tar gzip"
# Optional defaults must not prevent terminal setup, including under set -e.
(
npm_config_file="$PREFIX/npmrc"
if [ ! -e "$npm_config_file" ]; then
for legacy_config in "/etc/npmrc" "/usr/etc/npmrc"; do
if [ -f "$legacy_config" ]; then
cp "$legacy_config" "$npm_config_file" || exit 1
break
fi
done
fi
# Project/user npmrc files and CLI flags can override these defaults.
for setting in loglevel=info foreground-scripts=true; do
key=${setting%%=*}
if ! grep -Eq "^[[:space:]]*$key[[:space:]]*=" "$npm_config_file" 2>/dev/null; then
printf '\n%s\n' "$setting" >> "$npm_config_file" || exit 1
fi
done
) || echo "Unable to configure optional npm defaults; continuing terminal setup." >&2
fi
missing_packages=""

Expand Down
102 changes: 75 additions & 27 deletions platforms/android/app/src/store/java/com/foxdebug/iap/Iap.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class Iap extends Service {
private WeakReference<Context> contextRef;
private WeakReference<Activity> activityRef;
private Callback purchaseUpdated;
private final PurchaseFlow purchaseFlow = new PurchaseFlow();

public void initialize(BridgeContext bridgeContext) {
super.initialize(bridgeContext);
Expand All @@ -47,6 +48,16 @@ public void initialize(BridgeContext bridgeContext) {
billingClient = getBillingClient();
}

@Override
public void onPause(boolean multitasking) {
purchaseFlow.onPause();
}

@Override
public void onResume(boolean multitasking) {
purchaseFlow.onResume();
}

@Override
public boolean execute(
String action,
Expand Down Expand Up @@ -113,12 +124,20 @@ public void onPurchasesUpdated(
BillingResult billingResult,
List<Purchase> purchases
) {
List<String> updatedProducts = null;
try {
int responseCode = billingResult.getResponseCode();
if (responseCode == BillingResponseCode.OK && (purchases == null || purchases.isEmpty())) {
responseCode = BillingResponseCode.ERROR;
}
if (responseCode == BillingResponseCode.OK) {
updatedProducts = new ArrayList<>();
JSONArray result = new JSONArray();
for (Purchase purchase : purchases) {
result.put(purchaseToJson(purchase));
if (purchases != null) {
for (Purchase purchase : purchases) {
updatedProducts.addAll(purchase.getProducts());
result.put(purchaseToJson(purchase));
}
}
sendPurchasePluginResult(
new Payload(Payload.Status.OK, result)
Expand All @@ -129,9 +148,13 @@ public void onPurchasesUpdated(
);
}
} catch (JSONException e) {
updatedProducts = null;
sendPurchasePluginResult(
new Payload(Payload.Status.ERROR, e.getMessage())
);
} finally {
// Queue the outcome before allowing another flow to own JS errors.
purchaseFlow.finishUpdate(updatedProducts);
}
}
}
Expand Down Expand Up @@ -258,11 +281,17 @@ public void onProductDetailsResponse(
}

private void purchase(String productIdOrJson, Callback callbackContext) {
if (productIdOrJson == null || productIdOrJson.trim().isEmpty()) {
callbackContext.error("Product ID cannot be null or empty");
return;
}
Activity activity = activityRef.get();
final PurchaseFlow.Attempt attempt = purchaseFlow.begin(productIdOrJson, activity != null && activity.hasWindowFocus());
if (attempt == null) {
callbackContext.error(BillingResponseCode.DEVELOPER_ERROR);
return;
}
try {
if (productIdOrJson == null || productIdOrJson.trim().isEmpty()) {
callbackContext.error("Product ID cannot be null or empty");
return;
}

final String productId = productIdOrJson;

Expand All @@ -284,37 +313,50 @@ public void onProductDetailsResponse(
BillingResult billingResult,
QueryProductDetailsResult queryProductDetailsResult
) {
if (billingResult.getResponseCode() == BillingResponseCode.OK) {
List<ProductDetails> productDetailsList = queryProductDetailsResult.getProductDetailsList();
if (!productDetailsList.isEmpty()) {
ProductDetails productDetails = productDetailsList.get(0);
BillingResult result = billingClient.launchBillingFlow(
activityRef.get(),
BillingFlowParams.newBuilder().setProductDetailsParamsList(
Arrays.asList(
BillingFlowParams.ProductDetailsParams.newBuilder()
.setProductDetails(productDetails)
.build()
)
).build()
);
int responseCode = result.getResponseCode();
if (responseCode == BillingResponseCode.OK) {
callbackContext.success();
boolean launched = false;
try {
if (billingResult.getResponseCode() == BillingResponseCode.OK) {
List<ProductDetails> productDetailsList = queryProductDetailsResult.getProductDetailsList();
if (!productDetailsList.isEmpty()) {
ProductDetails productDetails = productDetailsList.get(0);
if (!purchaseFlow.launch(attempt)) {
callbackContext.error(BillingResponseCode.ERROR);
return;
}
BillingResult result = billingClient.launchBillingFlow(
activityRef.get(),
BillingFlowParams.newBuilder().setProductDetailsParamsList(
Arrays.asList(
BillingFlowParams.ProductDetailsParams.newBuilder()
.setProductDetails(productDetails)
.build()
)
).build()
);
int responseCode = result.getResponseCode();
if (responseCode == BillingResponseCode.OK) {
launched = true;
callbackContext.success();
} else {
callbackContext.error(responseCode);
}
} else {
callbackContext.error(responseCode);
callbackContext.error("No product details found for: " + productId);
}
} else {
callbackContext.error("No product details found for: " + productId);
callbackContext.error(billingResult.getResponseCode());
}
} else {
callbackContext.error(billingResult.getResponseCode());
} catch (Exception e) {
callbackContext.error("Purchase error: " + e.getMessage());
} finally {
if (!launched) purchaseFlow.finish(attempt);
}
}
}
);
} catch (Exception e) {
callbackContext.error("Purchase error: " + e.getMessage());
purchaseFlow.finish(attempt);
}
}

Expand All @@ -325,6 +367,7 @@ private void getPurchases(Callback callbackContext) {
return;
}

final PurchaseFlow.Attempt recoveryAttempt = purchaseFlow.recoveryAttempt();
QueryPurchasesParams params = QueryPurchasesParams.newBuilder()
.setProductType(BillingClient.ProductType.INAPP)
.build();
Expand All @@ -342,6 +385,11 @@ public void onQueryPurchasesResponse(
for (Purchase purchase : purchasesList) {
purchases.put(purchaseToJson(purchase));
}
Activity activity = activityRef.get();
// Reconcile a lost outcome only after returning from the store UI.
if (recoveryAttempt != null) {
purchaseFlow.finishRecovery(recoveryAttempt, activity != null && activity.hasWindowFocus());
}
callbackContext.success(purchases);
} else {
callbackContext.error(responseCode);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.foxdebug.iap

class PurchaseFlow(private val now: () -> Long = { System.nanoTime() / 1_000_000 }) {
class Attempt(val productId: String, val startedAt: Long)

private enum class Stage { QUERYING, LAUNCHED, LEFT_APP, RETURNED }

private var active: Attempt? = null
private var reconciled: Attempt? = null
private var stage = Stage.QUERYING

@Synchronized
fun begin(productId: String, hasWindowFocus: Boolean = false): Attempt? {
if (hasWindowFocus && stage == Stage.RETURNED && reconciled === active) active = null
if (lookupExpired()) active = null
if (active != null) return null
reconciled = null
stage = Stage.QUERYING
return Attempt(productId, now()).also { active = it }
}

@Synchronized
fun isActive(attempt: Attempt): Boolean = active === attempt

@Synchronized
fun launch(attempt: Attempt): Boolean {
if (active !== attempt) return false
if (lookupExpired()) {
active = null
return false
}
stage = Stage.LAUNCHED
return true
}

@Synchronized
fun onPause() {
reconciled = null
if (stage == Stage.LAUNCHED || stage == Stage.RETURNED) stage = Stage.LEFT_APP
}

@Synchronized
fun onResume() {
if (stage == Stage.LEFT_APP) stage = Stage.RETURNED
}

@Synchronized
fun recoveryAttempt(): Attempt? = active?.takeIf { stage == Stage.RETURNED }

@Synchronized
fun finishRecovery(attempt: Attempt, hasWindowFocus: Boolean) {
if (active !== attempt || stage != Stage.RETURNED) return
if (hasWindowFocus) active = null
else reconciled = attempt
}

@Synchronized
fun finish(attempt: Attempt) {
if (active === attempt) active = null
}

@Synchronized
fun finishUpdate(productIds: List<String>?) {
if (productIds.isNullOrEmpty() || active?.productId in productIds) active = null
}

// A lookup can expire; an open store sheet must never be unlocked by a timer.
private fun lookupExpired(): Boolean =
stage == Stage.QUERYING && active?.let { now() - it.startedAt >= 30_000 } == true
}
Loading
Loading