Skip to content

Commit b21b087

Browse files
committed
Finalize ChatGPT Codex auth widget build
1 parent 5a5cd0e commit b21b087

4 files changed

Lines changed: 27 additions & 17 deletions

File tree

‎.github/workflows/build-codex-quota-apk.yml‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ name: Build Codex Quota APK
33
on:
44
push:
55
branches:
6-
- agent/codex-quota-apk
6+
- agent/codex-quota-auth-v1
7+
pull_request:
78
workflow_dispatch:
89

910
permissions:
@@ -36,12 +37,12 @@ jobs:
3637
with:
3738
gradle-version: '8.9'
3839

39-
- name: Build release APK
40-
run: gradle --no-daemon assembleRelease
40+
- name: Build installable debug APK
41+
run: gradle --no-daemon assembleDebug
4142

4243
- name: Upload APK
4344
uses: actions/upload-artifact@v4
4445
with:
45-
name: codex-quota-widget-release
46-
path: codex-quota-widget/app/build/outputs/apk/release/app-release.apk
46+
name: codex-quota-widget-debug
47+
path: codex-quota-widget/app/build/outputs/apk/debug/app-debug.apk
4748
if-no-files-found: error

‎codex-quota-widget/app/src/main/java/com/mirochill/codexquota/ChatGptAuthClient.java‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import java.net.HttpURLConnection;
1313
import java.net.URL;
1414
import java.nio.charset.StandardCharsets;
15-
import java.util.Locale;
1615

1716
/** Small client for the same ChatGPT auth/rate-limit flow used by Codex. */
1817
public final class ChatGptAuthClient {
@@ -108,7 +107,8 @@ public static QuotaSnapshot sync(Context context) throws Exception {
108107
}
109108
ChatGptAuthStore.Tokens refreshed = refresh(tokens);
110109
ChatGptAuthStore.save(context, refreshed);
111-
return fetchQuota(refreshed);
110+
ChatGptAuthStore.Tokens persisted = ChatGptAuthStore.load(context);
111+
return fetchQuota(persisted == null ? refreshed : persisted);
112112
}
113113
}
114114

@@ -176,8 +176,10 @@ private static JSONObject requestJson(String method, String endpoint, String bod
176176
InputStream stream = status >= 400 ? connection.getErrorStream() : connection.getInputStream();
177177
String responseBody = read(stream);
178178
connection.disconnect();
179-
if (status < 200 || status >= 300) throw new HttpFailure(status,
180-
"Réponse serveur " + status + (responseBody.isEmpty() ? "" : " : " + responseBody));
179+
if (status < 200 || status >= 300) {
180+
// Never surface an authenticated response body in the UI.
181+
throw new HttpFailure(status, "Réponse serveur " + status);
182+
}
181183
try {
182184
return new JSONObject(responseBody);
183185
} catch (Exception parseError) {

‎codex-quota-widget/app/src/main/java/com/mirochill/codexquota/QuotaSnapshot.java‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,22 @@ public static QuotaSnapshot fromUsageJson(String raw) {
5757
JSONObject secondary = rateLimit == null ? null : rateLimit.optJSONObject("secondary_window");
5858

5959
JSONArray additional = root.optJSONArray("additional_rate_limits");
60-
if (secondary == null && additional != null && additional.length() > 0) {
61-
JSONObject first = additional.optJSONObject(0);
62-
JSONObject additionalLimit = first == null ? null : first.optJSONObject("rate_limit");
63-
secondary = additionalLimit == null ? null : additionalLimit.optJSONObject("secondary_window");
64-
if (secondary == null && additionalLimit != null) {
65-
secondary = additionalLimit.optJSONObject("primary_window");
60+
if (secondary == null && additional != null) {
61+
JSONObject fallback = null;
62+
for (int i = 0; i < additional.length(); i++) {
63+
JSONObject entry = additional.optJSONObject(i);
64+
JSONObject additionalLimit = entry == null ? null : entry.optJSONObject("rate_limit");
65+
if (additionalLimit == null) continue;
66+
JSONObject candidate = additionalLimit.optJSONObject("secondary_window");
67+
if (candidate == null) candidate = additionalLimit.optJSONObject("primary_window");
68+
if (candidate == null) continue;
69+
if (fallback == null) fallback = candidate;
70+
if (candidate.optLong("limit_window_seconds", 0L) >= 2L * 24L * 60L * 60L) {
71+
secondary = candidate;
72+
break;
73+
}
6674
}
75+
if (secondary == null) secondary = fallback;
6776
}
6877

6978
String primaryValue = remaining(primary);

‎codex-quota-widget/app/src/main/java/com/mirochill/codexquota/SyncActivity.java‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ public class SyncActivity extends Activity {
1818
private Button openAuth;
1919
private Button refresh;
2020
private ExecutorService executor;
21-
private volatile ChatGptAuthClient.DeviceCode pendingDeviceCode;
2221

2322
@Override
2423
protected void onCreate(Bundle savedInstanceState) {
@@ -48,7 +47,6 @@ private void startSync() {
4847
try {
4948
if (!ChatGptAuthStore.hasTokens(this)) {
5049
ChatGptAuthClient.DeviceCode deviceCode = ChatGptAuthClient.requestDeviceCode();
51-
pendingDeviceCode = deviceCode;
5250
runOnUiThread(() -> showDeviceCode(deviceCode));
5351
// Open the system browser, never a WebView, for the actual ChatGPT login.
5452
runOnUiThread(this::openVerificationPage);

0 commit comments

Comments
 (0)