Keep retrying the connection and say why; never lose a message that didn't send
As the web's connection supervisor and composer: - The first connection retries too, so tui3 opens without a server and connects when it's up. One-off commands still fail fast. - The header says why it couldn't connect and when it retries; r, a click on it, or the palette retries now. - Enter while disconnected keeps the message and says so. - A failed send, or a new thread that doesn't start, puts the message, its attachments and its mentions back in the composer. - Opening a PR in the browser says why it failed and copies the link. - Error notices stay 8s instead of 4s.
This commit is contained in:
1 parent
275a2bcde1
commit
2c5eedc869
9 files changed
+169
-42
No files matched your search
+14
-8
@@ -43,13 +43,15 @@ async function main(argv: string[]) {
|
||||
}
|
||||
}
|
||||
|
||||
/** For one-off commands: fails on the first failed attempt rather than retrying, as the UI does. */
|
||||
async function connectedSession(): Promise<{ session: T3Session; snapshot: OrchestrationV2ShellSnapshot }> {
|
||||
const session = new T3Session();
|
||||
await session.start();
|
||||
const snapshot = await new Promise<OrchestrationV2ShellSnapshot>((resolve, reject) => {
|
||||
const off = session.onShell((shell) => {
|
||||
if (shell.status.type === "error") {
|
||||
if (shell.status.type === "reconnecting") {
|
||||
queueMicrotask(() => off());
|
||||
void session.stop();
|
||||
reject(new Error(shell.status.message));
|
||||
} else if (shell.status.type === "live" && shell.snapshot) {
|
||||
queueMicrotask(() => off());
|
||||
@@ -109,18 +111,22 @@ async function tmuxCommand(args: string[]) {
|
||||
}
|
||||
}
|
||||
};
|
||||
session.onShell((shell) => {
|
||||
if (shell.status.type === "error") fail(shell.status.message);
|
||||
void sync();
|
||||
});
|
||||
// A dropped connection retries by itself; sync runs again once the shell is back.
|
||||
session.onShell(() => void sync());
|
||||
await new Promise(() => {});
|
||||
}
|
||||
|
||||
async function runUi(attachNeedle?: string) {
|
||||
const { session, snapshot } = await connectedSession();
|
||||
let session: T3Session;
|
||||
let attachThreadId: ThreadId | undefined;
|
||||
if (attachNeedle) {
|
||||
const thread = findThread(snapshot, attachNeedle);
|
||||
if (!attachNeedle) {
|
||||
// The UI opens at once and shows the connection, retrying until the server is there.
|
||||
session = new T3Session();
|
||||
void session.start();
|
||||
} else {
|
||||
const connected = await connectedSession();
|
||||
session = connected.session;
|
||||
const thread = findThread(connected.snapshot, attachNeedle);
|
||||
if (!thread) {
|
||||
await session.stop();
|
||||
return fail(`No thread matches "${attachNeedle}".`);
|
||||
|
||||
Reference in new issue
Block a user