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
2 changes: 1 addition & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"expo": {
"name": "Termix",
"slug": "termix",
"version": "1.3.0",
"version": "1.3.1",
"orientation": "default",
"icon": "./assets/images/icon.png",
"scheme": "termix-mobile",
Expand Down
1 change: 1 addition & 0 deletions app/tabs/sessions/Sessions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,7 @@ export default function Sessions() {
finalKey = `\x1b${key}`;
} else {
finalKey = key;
dictationSentRef.current = hiddenInputValue + key;
}
}
}
Expand Down
71 changes: 60 additions & 11 deletions app/tabs/sessions/terminal/NativeWebSocketManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ export class NativeWebSocketManager {
private cols = 80;
private rows = 24;
private wsUrl: string | null = null;
private serverSessionId: string | null = null;
private pendingReattach = false;

constructor(config: NativeWSConfig) {
this.config = config;
Expand Down Expand Up @@ -105,6 +107,12 @@ export class NativeWebSocketManager {
destroy(): void {
this.destroyed = true;
this.shouldNotReconnect = true;
if (this.ws && this.ws.readyState === WebSocket.OPEN) {
try {
this.ws.send(JSON.stringify({ type: "disconnect" }));
} catch (_) {}
}
this.serverSessionId = null;
this.clearAllTimers();
if (this.ws) {
try {
Expand Down Expand Up @@ -309,16 +317,30 @@ export class NativeWebSocketManager {
this.currentConnectionFromBackground = this.isReconnectFromBackground;
this.isReconnectFromBackground = false;

ws.send(
JSON.stringify({
type: "connectToHost",
data: {
cols: this.cols,
rows: this.rows,
hostConfig: this.config.hostConfig,
},
}),
);
if (this.serverSessionId) {
this.pendingReattach = true;
ws.send(
JSON.stringify({
type: "attachSession",
data: {
sessionId: this.serverSessionId,
cols: this.cols,
rows: this.rows,
},
}),
);
} else {
ws.send(
JSON.stringify({
type: "connectToHost",
data: {
cols: this.cols,
rows: this.rows,
hostConfig: this.config.hostConfig,
},
}),
);
}

this.startPingInterval();
};
Expand Down Expand Up @@ -381,17 +403,44 @@ export class NativeWebSocketManager {
return;
}
} else if (msg.type === "connected") {
const isReattach = this.pendingReattach;
this.pendingReattach = false;
this.config.onStateChange("connected", {
hostName: this.config.hostConfig.name,
fromBackground: this.currentConnectionFromBackground,
isReattach,
});
if (!this.currentConnectionFromBackground) {
if (!this.currentConnectionFromBackground && !isReattach) {
this.config.onPostConnectionSetup();
}
} else if (msg.type === "disconnected") {
this.serverSessionId = null;
this.config.onDisconnected(this.config.hostConfig.name);
} else if (msg.type === "pong") {
} else if (msg.type === "resized") {
} else if (msg.type === "sessionCreated") {
this.serverSessionId = msg.sessionId as string;
} else if (msg.type === "sessionAttached") {
this.serverSessionId = msg.sessionId as string;
} else if (msg.type === "sessionExpired") {
this.serverSessionId = null;
this.pendingReattach = false;
if (this.ws && this.ws.readyState === WebSocket.OPEN) {
this.ws.send(
JSON.stringify({
type: "connectToHost",
data: {
cols: this.cols,
rows: this.rows,
hostConfig: this.config.hostConfig,
},
}),
);
}
} else if (msg.type === "sessionTakenOver") {
this.serverSessionId = null;
this.shouldNotReconnect = true;
this.config.onDisconnected(this.config.hostConfig.name);
}
} catch (_) {
this.config.onData(event.data as string);
Expand Down
15 changes: 10 additions & 5 deletions app/tabs/sessions/terminal/Terminal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -403,10 +403,14 @@ const TerminalComponent = forwardRef<TerminalHandle, TerminalProps>(
try { terminal.write(data); } catch(e) {}
};

window.notifyConnected = function(fromBackground) {
window.notifyConnected = function(fromBackground, isReattach) {
terminal.clear();
terminal.reset();
terminal.write('\\x1b[2J\\x1b[H');
if (isReattach) {
terminal.write('\\x1b[2J\\x1b[H');
} else {
terminal.reset();
terminal.write('\\x1b[2J\\x1b[H');
}
};

const terminalElement = document.getElementById('terminal');
Expand Down Expand Up @@ -746,13 +750,14 @@ const TerminalComponent = forwardRef<TerminalHandle, TerminalProps>(
break;
case "connected": {
const fromBackground = data?.fromBackground as boolean;
const isReattach = data?.isReattach as boolean;
setConnectionState("connected");
setRetryCount(0);
if (!fromBackground) {
if (!isReattach) {
setHasReceivedData(false);
}
webViewRef.current?.injectJavaScript(
`window.notifyConnected(${fromBackground}); true;`,
`window.notifyConnected(${fromBackground}, ${isReattach}); true;`,
);
logActivity("terminal", hostConfig.id, hostConfig.name).catch(
() => {},
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "termix-mobile",
"main": "expo-router/entry",
"version": "1.3.0",
"version": "1.3.1",
"scripts": {
"start": "expo start",
"android": "expo run:android",
Expand Down
Loading