Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c4713dccbd | ||
|
|
981e94efc3 | ||
|
|
434cb67372 | ||
|
|
10e8139a32 | ||
|
|
f9e465bed5 |
@@ -1,4 +1,4 @@
|
||||
name: Gitea Android APK
|
||||
name: Gitea Android Compile Check
|
||||
|
||||
on: [push]
|
||||
|
||||
@@ -6,7 +6,7 @@ jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Build APK
|
||||
- name: Compile Android APK
|
||||
env:
|
||||
CLONE_TOKEN: ${{ secrets.TMUX_GITEA_TOKEN }}
|
||||
run: |
|
||||
@@ -62,6 +62,8 @@ jobs:
|
||||
|
||||
mkdir -p release
|
||||
APK_PATH="$(find app/build/outputs/apk -name '*.apk' | sort | tail -n 1)"
|
||||
cp "${APK_PATH}" release/tmux-android-gitea.apk
|
||||
ls -lh release/tmux-android-gitea.apk
|
||||
sha256sum release/tmux-android-gitea.apk
|
||||
cp "${APK_PATH}" release/tmux-android-gitea-compile-check.apk
|
||||
ls -lh release/tmux-android-gitea-compile-check.apk
|
||||
sha256sum release/tmux-android-gitea-compile-check.apk
|
||||
echo "Gitea-built APK is a compile check only."
|
||||
echo "Do not publish it as a release asset; release APKs are GitHub-built and mirrored byte-for-byte to Gitea."
|
||||
|
||||
@@ -26,7 +26,10 @@ APIs directly:
|
||||
display
|
||||
- mobile soft-key row for tmux-oriented input, including tmux prefix, detach,
|
||||
new window, previous/next window, Ctrl keys, arrows, page keys, and paste
|
||||
- automatic update checks against the selected release manifest
|
||||
- terminal viewport resize based on the phone's visible text area, including
|
||||
keyboard height changes, so tmux output wraps at the same width the user sees
|
||||
- automatic update checks with Gitea first and GitHub fallback, plus manual
|
||||
source-specific checks
|
||||
- one-download-per-version APK cache, SHA-256 verification, and installer
|
||||
handoff
|
||||
- native Update and About pages for version/build type, protocol, permission,
|
||||
@@ -99,6 +102,15 @@ to reach GitHub reliably. GitHub remains an optional public source. This Gitea
|
||||
instance does not support the GitHub-style `/releases/latest/download/...` URL,
|
||||
so the app uses the Gitea Release API as the stable Gitea update entrypoint.
|
||||
|
||||
Release APKs must be identical on GitHub and Gitea. The canonical APK is the
|
||||
GitHub Release asset built by `.github/workflows/android.yml`; publish to Gitea
|
||||
by mirroring that same `tmux-android.apk` byte-for-byte and uploading a
|
||||
Gitea-specific `latest.json` whose `apkUrl` points at the Gitea asset but whose
|
||||
`versionCode`, `versionName`, and `sha256` match the GitHub manifest. Do not use
|
||||
a separately built Gitea APK as a release asset unless it is proven to have the
|
||||
same SHA-256 as the GitHub APK. This keeps Android signatures and update
|
||||
compatibility identical no matter which platform the phone can reach.
|
||||
|
||||
Plain branch builds only create Actions artifacts; they are useful for CI
|
||||
verification, but releases are the stable download/update channel.
|
||||
|
||||
@@ -161,9 +173,19 @@ manifest is:
|
||||
https://github.com/neatstudio/tmux-browser-android/releases/latest/download/latest.json
|
||||
```
|
||||
|
||||
The app checks only the selected update source. It does not probe GitHub and
|
||||
Gitea during the same update check. Choose the source in the app's `Update`
|
||||
page, or use a custom manifest/API URL.
|
||||
The app has four update checks on the `Update` page:
|
||||
|
||||
- `Auto check` tries Gitea first, then tries GitHub only if Gitea cannot be
|
||||
reached.
|
||||
- `Gitea` checks only the public Gitea release API.
|
||||
- `GitHub` checks only the public GitHub manifest.
|
||||
- `Selected` checks the source chosen with `Source`, including a custom
|
||||
manifest/API URL.
|
||||
|
||||
Each source retries transient network failures before that source is considered
|
||||
failed. The `APK` and `Release page` buttons still resolve from the selected
|
||||
source, so they can be forced to Gitea on phones that cannot reliably reach
|
||||
GitHub.
|
||||
|
||||
Gitea tag-specific assets are also public, for example:
|
||||
|
||||
@@ -174,8 +196,9 @@ https://gitea.neatcn.com/tmux/tmux-browser-android/releases/download/v0.1.7/tmux
|
||||
|
||||
In the app:
|
||||
|
||||
- Open the `Update` page to check `latest.json`, download the APK, verify
|
||||
SHA-256, and open Android's installer.
|
||||
- Open the `Update` page and tap `Auto check` to check `latest.json`, download
|
||||
the APK, verify SHA-256, and open Android's installer. Use `Gitea`, `GitHub`,
|
||||
or `Selected` to force a single update source.
|
||||
- If the same version APK was already downloaded and its SHA-256 still matches,
|
||||
the app reuses that file instead of downloading it again.
|
||||
- If Android sends you to the unknown-app install permission screen, return to
|
||||
|
||||
@@ -26,6 +26,7 @@ import android.text.style.BackgroundColorSpan;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.text.style.StyleSpan;
|
||||
import android.view.Gravity;
|
||||
import android.view.HapticFeedbackConstants;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowInsets;
|
||||
@@ -55,9 +56,17 @@ import java.util.concurrent.Executors;
|
||||
public final class MainActivity extends Activity {
|
||||
private static final int IMAGE_PICK_REQUEST = 2001;
|
||||
private static final long AUTO_UPDATE_INTERVAL_MS = 6L * 60L * 60L * 1000L;
|
||||
private static final int TERMINAL_COLS = 96;
|
||||
private static final int TERMINAL_ROWS = 32;
|
||||
private static final int DEFAULT_TERMINAL_COLS = 80;
|
||||
private static final int DEFAULT_TERMINAL_ROWS = 24;
|
||||
private static final int MIN_TERMINAL_COLS = 36;
|
||||
private static final int MAX_TERMINAL_COLS = 140;
|
||||
private static final int MIN_TERMINAL_ROWS = 8;
|
||||
private static final int MAX_TERMINAL_ROWS = 80;
|
||||
private static final int MAX_TERMINAL_CHARS = 40_000;
|
||||
private static final int STATUS_NORMAL = 0;
|
||||
private static final int STATUS_BUSY = 1;
|
||||
private static final int STATUS_SUCCESS = 2;
|
||||
private static final int STATUS_ERROR = 3;
|
||||
private static final long TERMINAL_RENDER_INTERVAL_MS = 80L;
|
||||
private static final String OLD_LOCAL_DEFAULT_URL = "http://127.0.0.1:3000";
|
||||
private static final String OLD_GITHUB_DEFAULT_UPDATE_URL = "https://github.com/neatstudio/tmux-browser-android/releases/latest/download/latest.json";
|
||||
@@ -98,6 +107,8 @@ public final class MainActivity extends Activity {
|
||||
private boolean terminalConnected;
|
||||
private boolean terminalRenderPending;
|
||||
private long lastTerminalRenderMs;
|
||||
private int terminalCols = DEFAULT_TERMINAL_COLS;
|
||||
private int terminalRows = DEFAULT_TERMINAL_ROWS;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -156,7 +167,6 @@ public final class MainActivity extends Activity {
|
||||
statusText.setTextSize(12);
|
||||
statusText.setGravity(Gravity.CENTER_VERTICAL);
|
||||
statusText.setPadding(dp(10), 0, dp(10), 0);
|
||||
statusText.setBackground(rounded(Color.rgb(22, 27, 34), 0, Color.TRANSPARENT, 0));
|
||||
statusText.setSingleLine(true);
|
||||
setStatus("Ready");
|
||||
applySystemBarInsets(root);
|
||||
@@ -370,7 +380,10 @@ public final class MainActivity extends Activity {
|
||||
));
|
||||
content.addView(sectionTitle("Update"));
|
||||
content.addView(actionPanel(
|
||||
actionButton("Check now", view -> updateManager.check(true)),
|
||||
actionButton("Auto check", view -> updateManager.check(true)),
|
||||
actionButton("Gitea", view -> updateManager.checkGitea(true)),
|
||||
actionButton("GitHub", view -> updateManager.checkGithub(true)),
|
||||
actionButton("Selected", view -> updateManager.checkSelected(true)),
|
||||
actionButton("Source", view -> showUpdateSourcePicker()),
|
||||
actionButton("APK", view -> updateManager.openApkDownload())
|
||||
));
|
||||
@@ -428,7 +441,7 @@ public final class MainActivity extends Activity {
|
||||
"Update policy",
|
||||
"Selected source: " + updateSourceHost() + "\n"
|
||||
+ prefs.getString("update_url", BuildConfig.DEFAULT_UPDATE_URL) + "\n"
|
||||
+ "The app checks only this source. APK downloads are cached by version and reused after Android install permission is granted."
|
||||
+ "Auto check tries Gitea first, then GitHub if Gitea cannot be reached. Manual Gitea/GitHub/Selected checks are also available. APK downloads are cached by version and reused after Android install permission is granted."
|
||||
));
|
||||
content.addView(actionPanel(
|
||||
actionButton("Release page", view -> updateManager.openReleasePage()),
|
||||
@@ -963,6 +976,8 @@ public final class MainActivity extends Activity {
|
||||
terminalConnected = false;
|
||||
terminalRenderPending = false;
|
||||
lastTerminalRenderMs = 0L;
|
||||
terminalCols = DEFAULT_TERMINAL_COLS;
|
||||
terminalRows = DEFAULT_TERMINAL_ROWS;
|
||||
root.removeAllViews();
|
||||
root.addView(createTerminalTopBar(sessionName), matchWrap());
|
||||
|
||||
@@ -983,6 +998,8 @@ public final class MainActivity extends Activity {
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT
|
||||
));
|
||||
terminalScroll.addOnLayoutChangeListener((view, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) ->
|
||||
resizeTerminalToViewport(false));
|
||||
root.addView(terminalScroll, new LinearLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
0,
|
||||
@@ -997,7 +1014,10 @@ public final class MainActivity extends Activity {
|
||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
dp(28)
|
||||
));
|
||||
connectTerminal(sessionName);
|
||||
terminalScroll.post(() -> {
|
||||
resizeTerminalToViewport(false);
|
||||
connectTerminal(sessionName);
|
||||
});
|
||||
}
|
||||
|
||||
private LinearLayout createTerminalTopBar(String sessionName) {
|
||||
@@ -1126,12 +1146,12 @@ public final class MainActivity extends Activity {
|
||||
break;
|
||||
case 3:
|
||||
if (terminalSocket != null) {
|
||||
terminalSocket.scroll(-TERMINAL_ROWS);
|
||||
terminalSocket.scroll(-terminalRows);
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
if (terminalSocket != null) {
|
||||
terminalSocket.scroll(TERMINAL_ROWS);
|
||||
terminalSocket.scroll(terminalRows);
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
@@ -1433,7 +1453,7 @@ public final class MainActivity extends Activity {
|
||||
text.append("Tap Release on the About page. The app resolves the page from the selected update source.\n");
|
||||
text.append('\n');
|
||||
text.append("In-app update:\n");
|
||||
text.append("Tap Check now on the Update page. The app checks only the selected source, downloads one APK per version, verifies SHA-256, then opens Android's installer.\n");
|
||||
text.append("Tap Auto check on the Update page to try Gitea first and GitHub only if Gitea cannot be reached. Use Gitea, GitHub, or Selected to force one source. Each source retries transient network failures before failing. The app downloads one APK per version, verifies SHA-256, then opens Android's installer.\n");
|
||||
text.append("Selected manifest: ")
|
||||
.append(updateSourceHost())
|
||||
.append('\n')
|
||||
@@ -1753,6 +1773,7 @@ public final class MainActivity extends Activity {
|
||||
queuedTerminalInput.setLength(0);
|
||||
terminalConnected = false;
|
||||
setStatus("Connecting " + sessionName);
|
||||
resizeTerminalToViewport(false);
|
||||
appendTerminal("[connecting]\r\n");
|
||||
terminalSocket = new TerminalSocketClient(new TerminalSocketClient.Listener() {
|
||||
@Override
|
||||
@@ -1760,6 +1781,7 @@ public final class MainActivity extends Activity {
|
||||
runOnUiThread(() -> {
|
||||
terminalConnected = true;
|
||||
setStatus("Connected " + sessionName);
|
||||
resizeTerminalToViewport(true);
|
||||
flushQueuedTerminalInput();
|
||||
});
|
||||
}
|
||||
@@ -1785,7 +1807,39 @@ public final class MainActivity extends Activity {
|
||||
});
|
||||
}
|
||||
});
|
||||
terminalSocket.connect(api.getBaseUrl(), sessionName, TERMINAL_COLS, TERMINAL_ROWS);
|
||||
terminalSocket.connect(api.getBaseUrl(), sessionName, terminalCols, terminalRows);
|
||||
}
|
||||
|
||||
private void resizeTerminalToViewport(boolean forceSend) {
|
||||
if (terminalText == null || terminalScroll == null) {
|
||||
return;
|
||||
}
|
||||
int width = terminalScroll.getWidth();
|
||||
int height = terminalScroll.getHeight();
|
||||
if (width <= 0 || height <= 0) {
|
||||
return;
|
||||
}
|
||||
int horizontalPadding = terminalText.getPaddingLeft() + terminalText.getPaddingRight();
|
||||
int verticalPadding = terminalText.getPaddingTop() + terminalText.getPaddingBottom();
|
||||
float charWidth = terminalText.getPaint().measureText("W");
|
||||
if (charWidth <= 0f) {
|
||||
charWidth = dp(8);
|
||||
}
|
||||
int lineHeight = terminalText.getLineHeight();
|
||||
if (lineHeight <= 0) {
|
||||
lineHeight = dp(16);
|
||||
}
|
||||
int cols = clamp((int) Math.floor((width - horizontalPadding) / charWidth), MIN_TERMINAL_COLS, MAX_TERMINAL_COLS);
|
||||
int rows = clamp((height - verticalPadding) / lineHeight, MIN_TERMINAL_ROWS, MAX_TERMINAL_ROWS);
|
||||
if (cols == terminalCols && rows == terminalRows && !forceSend) {
|
||||
return;
|
||||
}
|
||||
terminalCols = cols;
|
||||
terminalRows = rows;
|
||||
TerminalSocketClient socket = terminalSocket;
|
||||
if (socket != null && !socket.isClosed() && terminalConnected) {
|
||||
socket.resize(cols, rows);
|
||||
}
|
||||
}
|
||||
|
||||
private void sendLine() {
|
||||
@@ -1808,6 +1862,7 @@ public final class MainActivity extends Activity {
|
||||
TerminalSocketClient socket = terminalSocket;
|
||||
if (socket != null && !socket.isClosed() && terminalConnected) {
|
||||
socket.sendInput(data);
|
||||
setStatus("Sent input");
|
||||
return;
|
||||
}
|
||||
if (socket != null && !socket.isClosed()) {
|
||||
@@ -1820,6 +1875,7 @@ public final class MainActivity extends Activity {
|
||||
for (int i = 0; i < data.length(); i += 200) {
|
||||
api.sendInput(activeSessionName, data.substring(i, Math.min(i + 200, data.length())));
|
||||
}
|
||||
runOnUiThread(() -> setStatus("Sent input"));
|
||||
} catch (Exception error) {
|
||||
runOnUiThread(() -> showMessage("Input failed: " + error.getMessage()));
|
||||
}
|
||||
@@ -1838,15 +1894,19 @@ public final class MainActivity extends Activity {
|
||||
private void pasteClipboard() {
|
||||
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
if (clipboard == null || !clipboard.hasPrimaryClip()) {
|
||||
showMessage("Clipboard is empty");
|
||||
return;
|
||||
}
|
||||
ClipData clip = clipboard.getPrimaryClip();
|
||||
if (clip == null || clip.getItemCount() == 0) {
|
||||
showMessage("Clipboard is empty");
|
||||
return;
|
||||
}
|
||||
CharSequence text = clip.getItemAt(0).coerceToText(this);
|
||||
if (text != null && text.length() > 0) {
|
||||
sendTerminalInput(text.toString());
|
||||
} else {
|
||||
showMessage("Clipboard is empty");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1889,6 +1949,14 @@ public final class MainActivity extends Activity {
|
||||
while (index < text.length()) {
|
||||
char item = text.charAt(index);
|
||||
if (item == '\r') {
|
||||
deleteCurrentTerminalLine(output);
|
||||
index++;
|
||||
continue;
|
||||
}
|
||||
if (item == '\b') {
|
||||
if (output.length() > 0 && output.charAt(output.length() - 1) != '\n') {
|
||||
output.delete(output.length() - 1, output.length());
|
||||
}
|
||||
index++;
|
||||
continue;
|
||||
}
|
||||
@@ -1903,15 +1971,32 @@ public final class MainActivity extends Activity {
|
||||
fg = state[0];
|
||||
bg = state[1];
|
||||
bold = state[2] == 1;
|
||||
} else if (command == 'K') {
|
||||
String params = text.substring(index + 2, end);
|
||||
if (params.startsWith("2")) {
|
||||
deleteCurrentTerminalLine(output);
|
||||
}
|
||||
} else if (command == 'J') {
|
||||
String params = text.substring(index + 2, end);
|
||||
if (params.startsWith("2") || params.startsWith("3")) {
|
||||
output.clear();
|
||||
}
|
||||
}
|
||||
index = end + 1;
|
||||
continue;
|
||||
}
|
||||
if (item == '\u001b') {
|
||||
int skipped = skipNonCsiEscape(text, index);
|
||||
if (skipped > index) {
|
||||
index = skipped;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
int runStart = index;
|
||||
while (index < text.length()) {
|
||||
char runItem = text.charAt(index);
|
||||
if (runItem == '\r' || (runItem == '\u001b' && index + 1 < text.length() && text.charAt(index + 1) == '[')) {
|
||||
if (runItem == '\r' || runItem == '\b' || runItem == '\u001b') {
|
||||
break;
|
||||
}
|
||||
index++;
|
||||
@@ -1921,6 +2006,41 @@ public final class MainActivity extends Activity {
|
||||
return output;
|
||||
}
|
||||
|
||||
private void deleteCurrentTerminalLine(SpannableStringBuilder output) {
|
||||
int start = output.length();
|
||||
while (start > 0 && output.charAt(start - 1) != '\n') {
|
||||
start--;
|
||||
}
|
||||
if (start < output.length()) {
|
||||
output.delete(start, output.length());
|
||||
}
|
||||
}
|
||||
|
||||
private int skipNonCsiEscape(String text, int index) {
|
||||
if (index + 1 >= text.length()) {
|
||||
return index + 1;
|
||||
}
|
||||
char next = text.charAt(index + 1);
|
||||
if (next == ']' || next == 'P' || next == '^' || next == '_') {
|
||||
int cursor = index + 2;
|
||||
while (cursor < text.length()) {
|
||||
char item = text.charAt(cursor);
|
||||
if (item == '\u0007') {
|
||||
return cursor + 1;
|
||||
}
|
||||
if (item == '\u001b' && cursor + 1 < text.length() && text.charAt(cursor + 1) == '\\') {
|
||||
return cursor + 2;
|
||||
}
|
||||
cursor++;
|
||||
}
|
||||
return text.length();
|
||||
}
|
||||
if (next == '(' || next == ')' || next == '*' || next == '+' || next == '-' || next == '.') {
|
||||
return Math.min(index + 3, text.length());
|
||||
}
|
||||
return Math.min(index + 2, text.length());
|
||||
}
|
||||
|
||||
private void appendTerminalRun(SpannableStringBuilder output, String text, int fg, int bg, boolean bold) {
|
||||
if (text.isEmpty()) {
|
||||
return;
|
||||
@@ -2078,7 +2198,20 @@ public final class MainActivity extends Activity {
|
||||
button.setPadding(dp(10), 0, dp(10), 0);
|
||||
button.setBackground(buttonBackground());
|
||||
button.setGravity(Gravity.CENTER);
|
||||
button.setOnClickListener(listener);
|
||||
button.setHapticFeedbackEnabled(true);
|
||||
button.setOnClickListener(view -> {
|
||||
view.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
|
||||
view.animate().cancel();
|
||||
view.setScaleX(0.96f);
|
||||
view.setScaleY(0.96f);
|
||||
view.animate()
|
||||
.scaleX(1f)
|
||||
.scaleY(1f)
|
||||
.setDuration(120L)
|
||||
.start();
|
||||
setStatus(label);
|
||||
listener.onClick(view);
|
||||
});
|
||||
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||
dp(42)
|
||||
@@ -2099,6 +2232,7 @@ public final class MainActivity extends Activity {
|
||||
|
||||
private StateListDrawable buttonBackground() {
|
||||
StateListDrawable states = new StateListDrawable();
|
||||
states.addState(new int[]{-android.R.attr.state_enabled}, rounded(Color.rgb(24, 30, 37), 8, Color.rgb(35, 42, 50), 1));
|
||||
states.addState(new int[]{android.R.attr.state_pressed}, rounded(Color.rgb(64, 78, 94), 8, Color.rgb(91, 108, 128), 1));
|
||||
states.addState(new int[]{android.R.attr.state_focused}, rounded(Color.rgb(48, 61, 76), 8, Color.rgb(98, 128, 164), 1));
|
||||
states.addState(new int[]{}, rounded(Color.rgb(34, 43, 53), 8, Color.rgb(55, 66, 80), 1));
|
||||
@@ -2153,16 +2287,91 @@ public final class MainActivity extends Activity {
|
||||
}
|
||||
|
||||
private void showMessage(String message) {
|
||||
if (message == null || message.trim().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
|
||||
setStatus(message);
|
||||
}
|
||||
|
||||
private void setStatus(String message) {
|
||||
setStatus(message, inferStatusTone(message));
|
||||
}
|
||||
|
||||
private void setStatus(String message, int tone) {
|
||||
if (statusText != null) {
|
||||
statusText.setText(message);
|
||||
String value = message == null || message.trim().isEmpty() ? "Ready" : message.trim();
|
||||
statusText.setText(value);
|
||||
int bg = Color.rgb(22, 27, 34);
|
||||
int stroke = Color.TRANSPARENT;
|
||||
int text = Color.rgb(210, 215, 224);
|
||||
if (tone == STATUS_BUSY) {
|
||||
bg = Color.rgb(20, 44, 68);
|
||||
stroke = Color.rgb(44, 96, 142);
|
||||
text = Color.rgb(220, 238, 255);
|
||||
} else if (tone == STATUS_SUCCESS) {
|
||||
bg = Color.rgb(20, 56, 40);
|
||||
stroke = Color.rgb(42, 118, 78);
|
||||
text = Color.rgb(218, 245, 228);
|
||||
} else if (tone == STATUS_ERROR) {
|
||||
bg = Color.rgb(72, 28, 31);
|
||||
stroke = Color.rgb(154, 66, 72);
|
||||
text = Color.rgb(255, 226, 226);
|
||||
}
|
||||
statusText.setTextColor(text);
|
||||
statusText.setBackground(rounded(bg, 0, stroke, tone == STATUS_NORMAL ? 0 : 1));
|
||||
}
|
||||
}
|
||||
|
||||
private int inferStatusTone(String message) {
|
||||
if (message == null) {
|
||||
return STATUS_NORMAL;
|
||||
}
|
||||
String value = message.toLowerCase(java.util.Locale.ROOT);
|
||||
if (value.contains("failed")
|
||||
|| value.contains("error")
|
||||
|| value.contains("invalid")
|
||||
|| value.contains("cannot")
|
||||
|| value.contains("mismatch")
|
||||
|| value.contains("disconnected")
|
||||
|| value.contains("empty")
|
||||
|| value.contains("no package")
|
||||
|| value.contains("no app")) {
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
if (value.contains("loading")
|
||||
|| value.contains("checking")
|
||||
|| value.contains("connecting")
|
||||
|| value.contains("probing")
|
||||
|| value.contains("downloading")
|
||||
|| value.contains("preparing")
|
||||
|| value.contains("verifying")
|
||||
|| value.contains("retrying")
|
||||
|| value.contains("queued")
|
||||
|| value.contains("resolving")) {
|
||||
return STATUS_BUSY;
|
||||
}
|
||||
if (value.contains("done")
|
||||
|| value.contains("loaded")
|
||||
|| value.contains("connected")
|
||||
|| value.contains("created")
|
||||
|| value.contains("killed")
|
||||
|| value.contains("opened")
|
||||
|| value.contains("sent")
|
||||
|| value.contains("selected")
|
||||
|| value.contains("saved")
|
||||
|| value.contains("using downloaded")
|
||||
|| value.contains("update found")
|
||||
|| value.contains("already up to date")) {
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
return STATUS_NORMAL;
|
||||
}
|
||||
|
||||
private int clamp(int value, int min, int max) {
|
||||
return Math.max(min, Math.min(max, value));
|
||||
}
|
||||
|
||||
private int dp(int value) {
|
||||
return Math.round(value * getResources().getDisplayMetrics().density);
|
||||
}
|
||||
|
||||
@@ -26,6 +26,8 @@ import java.util.concurrent.Executors;
|
||||
|
||||
final class UpdateManager {
|
||||
private static final String PREF_PENDING_INSTALL_APK = "pending_install_apk";
|
||||
private static final int NETWORK_ATTEMPTS = 3;
|
||||
private static final long RETRY_DELAY_MS = 1200L;
|
||||
|
||||
interface Callback {
|
||||
void onChecking(boolean checking);
|
||||
@@ -51,25 +53,77 @@ final class UpdateManager {
|
||||
}
|
||||
|
||||
void check(boolean userInitiated) {
|
||||
checkWithFallback(userInitiated);
|
||||
}
|
||||
|
||||
void checkSelected(boolean userInitiated) {
|
||||
startUpdateCheck(
|
||||
userInitiated,
|
||||
"selected source",
|
||||
new String[]{getUpdateManifestUrl()}
|
||||
);
|
||||
}
|
||||
|
||||
void checkGitea(boolean userInitiated) {
|
||||
startUpdateCheck(
|
||||
userInitiated,
|
||||
"Gitea",
|
||||
new String[]{BuildConfig.DEFAULT_GITEA_UPDATE_URL}
|
||||
);
|
||||
}
|
||||
|
||||
void checkGithub(boolean userInitiated) {
|
||||
startUpdateCheck(
|
||||
userInitiated,
|
||||
"GitHub",
|
||||
new String[]{BuildConfig.DEFAULT_GITHUB_UPDATE_URL}
|
||||
);
|
||||
}
|
||||
|
||||
void checkWithFallback(boolean userInitiated) {
|
||||
startUpdateCheck(
|
||||
userInitiated,
|
||||
"Gitea, then GitHub",
|
||||
new String[]{BuildConfig.DEFAULT_GITEA_UPDATE_URL, BuildConfig.DEFAULT_GITHUB_UPDATE_URL}
|
||||
);
|
||||
}
|
||||
|
||||
private void startUpdateCheck(boolean userInitiated, String label, String[] manifestUrls) {
|
||||
if (checkInProgress) {
|
||||
postMessage("Update check already running");
|
||||
return;
|
||||
}
|
||||
String manifestUrl = getUpdateManifestUrl();
|
||||
checkInProgress = true;
|
||||
callback.onChecking(true);
|
||||
postMessage("Checking update from " + hostLabel(manifestUrl) + "...");
|
||||
postMessage("Checking update: " + label + "...");
|
||||
executor.execute(() -> {
|
||||
Exception lastError = null;
|
||||
try {
|
||||
ReleaseInfo info = fetchReleaseInfo(manifestUrl);
|
||||
if (info.versionCode <= BuildConfig.VERSION_CODE) {
|
||||
postMessage("Already up to date: " + BuildConfig.VERSION_NAME);
|
||||
return;
|
||||
for (int index = 0; index < manifestUrls.length; index++) {
|
||||
String manifestUrl = manifestUrls[index];
|
||||
try {
|
||||
postMessage("Checking " + hostLabel(manifestUrl) + "...");
|
||||
ReleaseInfo info = fetchReleaseInfo(manifestUrl);
|
||||
if (info.versionCode <= BuildConfig.VERSION_CODE) {
|
||||
postMessage("Already up to date: " + BuildConfig.VERSION_NAME + " from " + hostLabel(manifestUrl));
|
||||
return;
|
||||
}
|
||||
postMessage("Update found: " + info.versionName + " from " + hostLabel(manifestUrl));
|
||||
activity.runOnUiThread(() -> showUpdateDialog(info));
|
||||
return;
|
||||
} catch (Exception error) {
|
||||
lastError = error;
|
||||
if (index + 1 < manifestUrls.length) {
|
||||
postMessage(hostLabel(manifestUrl) + " failed; trying " + hostLabel(manifestUrls[index + 1]) + "...");
|
||||
}
|
||||
}
|
||||
}
|
||||
postMessage("Update found: " + info.versionName);
|
||||
activity.runOnUiThread(() -> showUpdateDialog(info));
|
||||
} catch (Exception error) {
|
||||
postMessage(userInitiated ? "Update check failed: " + error.getMessage() : null);
|
||||
if (lastError != null) {
|
||||
throw lastError;
|
||||
}
|
||||
throw new IllegalStateException("No update sources configured");
|
||||
} catch (Exception finalError) {
|
||||
postMessage(userInitiated ? "Update check failed: " + finalError.getMessage() : null);
|
||||
} finally {
|
||||
checkInProgress = false;
|
||||
activity.runOnUiThread(() -> callback.onChecking(false));
|
||||
@@ -177,6 +231,22 @@ final class UpdateManager {
|
||||
}
|
||||
|
||||
private String readText(String url) throws Exception {
|
||||
Exception lastError = null;
|
||||
for (int attempt = 1; attempt <= NETWORK_ATTEMPTS; attempt++) {
|
||||
try {
|
||||
return readTextOnce(url);
|
||||
} catch (Exception error) {
|
||||
lastError = error;
|
||||
if (attempt < NETWORK_ATTEMPTS) {
|
||||
postMessage("Retrying " + hostLabel(url) + " (" + (attempt + 1) + "/" + NETWORK_ATTEMPTS + ")...");
|
||||
waitBeforeRetry();
|
||||
}
|
||||
}
|
||||
}
|
||||
throw lastError == null ? new IllegalStateException("Request failed") : lastError;
|
||||
}
|
||||
|
||||
private String readTextOnce(String url) throws Exception {
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
|
||||
connection.setConnectTimeout(12000);
|
||||
connection.setReadTimeout(12000);
|
||||
@@ -238,7 +308,36 @@ final class UpdateManager {
|
||||
}
|
||||
|
||||
postMessage("Downloading " + info.versionName + "...");
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL(info.apkUrl).openConnection();
|
||||
File partial = new File(dir, "tmux-android-" + info.versionCode + ".apk.tmp");
|
||||
if (partial.exists()) {
|
||||
partial.delete();
|
||||
}
|
||||
if (apk.exists()) {
|
||||
apk.delete();
|
||||
}
|
||||
|
||||
Exception lastError = null;
|
||||
for (int attempt = 1; attempt <= NETWORK_ATTEMPTS; attempt++) {
|
||||
try {
|
||||
downloadApkOnce(info.apkUrl, partial);
|
||||
if (!partial.renameTo(apk)) {
|
||||
throw new IllegalStateException("Cannot finalize APK download");
|
||||
}
|
||||
return apk;
|
||||
} catch (Exception error) {
|
||||
lastError = error;
|
||||
partial.delete();
|
||||
if (attempt < NETWORK_ATTEMPTS) {
|
||||
postMessage("Retrying APK download (" + (attempt + 1) + "/" + NETWORK_ATTEMPTS + ")...");
|
||||
waitBeforeRetry();
|
||||
}
|
||||
}
|
||||
}
|
||||
throw lastError == null ? new IllegalStateException("APK download failed") : lastError;
|
||||
}
|
||||
|
||||
private void downloadApkOnce(String apkUrl, File apk) throws Exception {
|
||||
HttpURLConnection connection = (HttpURLConnection) new URL(apkUrl).openConnection();
|
||||
connection.setConnectTimeout(12000);
|
||||
connection.setReadTimeout(60000);
|
||||
try (InputStream input = new BufferedInputStream(connection.getInputStream());
|
||||
@@ -251,7 +350,6 @@ final class UpdateManager {
|
||||
} finally {
|
||||
connection.disconnect();
|
||||
}
|
||||
return apk;
|
||||
}
|
||||
|
||||
private boolean isCachedApkValid(File apk, ReleaseInfo info) throws Exception {
|
||||
@@ -366,4 +464,8 @@ final class UpdateManager {
|
||||
}
|
||||
activity.runOnUiThread(() -> callback.onMessage(message));
|
||||
}
|
||||
|
||||
private void waitBeforeRetry() throws InterruptedException {
|
||||
Thread.sleep(RETRY_DELAY_MS);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,10 +87,12 @@ Implemented now:
|
||||
preview display
|
||||
- GitHub Actions APK build
|
||||
- release manifest `latest.json`
|
||||
- selected-source update checks; Gitea and GitHub are not probed in the same
|
||||
update check
|
||||
- Auto/Gitea/GitHub/Selected update checks, with Auto falling back from Gitea
|
||||
to GitHub
|
||||
- one-download-per-version APK cache, SHA-256 verification, and installer
|
||||
handoff
|
||||
- terminal viewport resize derived from the Android text area, including
|
||||
keyboard height changes, to avoid fixed-width tmux output wrapping on phones
|
||||
- permission/about surfaces for unknown-app install status, notification status,
|
||||
app settings, app version/build type, package name, selected update source, and
|
||||
HTTP/WebSocket API/protocol summary
|
||||
@@ -101,11 +103,11 @@ The Android app cannot silently replace itself. It may download a newer APK and
|
||||
open Android's package installer, but the user must approve the install. On
|
||||
Android 8+, the user may also need to allow this app to install unknown apps.
|
||||
|
||||
The app checks exactly one update source per run: the selected manifest/API URL.
|
||||
Gitea is the default public source because phones may not reach GitHub reliably.
|
||||
GitHub is available as an optional public source, but the app does not fall back
|
||||
across both providers during a normal check. This keeps update behavior
|
||||
predictable on mobile networks and avoids duplicate provider checks.
|
||||
The app provides explicit update checks for Auto, Gitea, GitHub, and Selected.
|
||||
Auto checks Gitea first because phones may not reach GitHub reliably, then tries
|
||||
GitHub only if Gitea cannot be reached. The manual Gitea, GitHub, and Selected
|
||||
buttons force one source. Transient network failures are retried against the
|
||||
current source before a source is considered failed.
|
||||
|
||||
Downloaded APKs are cached by `versionCode`. If a cached APK exists and its
|
||||
SHA-256 matches the manifest, the app reuses it instead of downloading the same
|
||||
@@ -119,6 +121,14 @@ runs are for CI artifacts and should be used to validate grouped changes. Do not
|
||||
publish a new tag for every small UI copy or layout change; publish when there
|
||||
is a useful feature or test batch for phone-side validation.
|
||||
|
||||
Release APKs must be identical across the public GitHub and Gitea download
|
||||
channels. Treat the GitHub Release APK as the canonical build artifact, then
|
||||
mirror that same APK byte-for-byte to the matching Gitea Release. The Gitea
|
||||
`latest.json` should point to the Gitea APK URL, but it must keep the same
|
||||
`versionCode`, `versionName`, and `sha256` as the GitHub manifest. A Gitea-built
|
||||
APK is only a compile check unless its SHA-256 exactly matches the GitHub
|
||||
release APK.
|
||||
|
||||
## Native Roadmap
|
||||
|
||||
To converge with the upstream mobile design, the next implementation should add
|
||||
|
||||
Reference in New Issue
Block a user