Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix: small tauri websocket improvements (#1764)

Peter Chinman284482ede68a
diff --git a/js/app/packages/app/component/split-layout/layoutManager.ts b/js/app/packages/app/component/split-layout/layoutManager.ts
index d3c3fd3cb0..d51f316fd4 100644
--- a/js/app/packages/app/component/split-layout/layoutManager.ts
+++ b/js/app/packages/app/component/split-layout/layoutManager.ts
@@ -684,7 +684,7 @@ export function createSplitLayout(
const s = () => state.splits.find((x) => x.id === id);
const currentSplit = s();
if (!currentSplit) return;
- const content = () => s()!.content;
+ const content = () => currentSplit.content;
return {
id: currentSplit.id,
diff --git a/js/app/packages/core/component/LexicalMarkdown/context/FloatingMenuContext.tsx b/js/app/packages/core/component/LexicalMarkdown/context/FloatingMenuContext.tsx
index 821df86032..1f8ab6c227 100644
--- a/js/app/packages/core/component/LexicalMarkdown/context/FloatingMenuContext.tsx
+++ b/js/app/packages/core/component/LexicalMarkdown/context/FloatingMenuContext.tsx
@@ -93,7 +93,7 @@ export function createMenuOpenSignal(
): Signal<boolean> {
const context = useContext(FloatingMenuContext);
if (!context) {
- console.warn(
+ console.info(
'createMenuOpenSignal called outside of <FloatingMenuGroup>. Falling back to plain signal. This may not be what you want.'
);
return createSignal(initial ?? false);
diff --git a/js/app/packages/websocket/core/websocket.ts b/js/app/packages/websocket/core/websocket.ts
index 8cc8403cfe..bcfba1eb4e 100644
--- a/js/app/packages/websocket/core/websocket.ts
+++ b/js/app/packages/websocket/core/websocket.ts
@@ -699,7 +699,10 @@ export class Websocket<Send = WebsocketData, Receive = WebsocketData> {
return;
}
- if (this.isClosing()) {
+ if (
+ this.isClosing() ||
+ this._underlyingWebsocket.readyState === this._underlyingWebsocket.CLOSED
+ ) {
this.handleEvent(
WebsocketEvent.Close,
new CloseEvent('closed websocket by heartbeat, already closing')
diff --git a/js/app/packages/websocket/platform/tauri-websocket.ts b/js/app/packages/websocket/platform/tauri-websocket.ts
index 02225e22dc..b38d1d6938 100644
--- a/js/app/packages/websocket/platform/tauri-websocket.ts
+++ b/js/app/packages/websocket/platform/tauri-websocket.ts
@@ -1,5 +1,7 @@
import { isTauri } from '@core/util/platform';
-import TauriWebsocket from '@tauri-apps/plugin-websocket';
+import TauriWebsocket, {
+ type Message as TauriMessage,
+} from '@tauri-apps/plugin-websocket';
import type { MinimalWebSocket, WebSocketFactory } from './minimal-websocket';
/**
@@ -50,7 +52,7 @@ export class TauriWebSocketWrapper implements MinimalWebSocket {
this.ws = await TauriWebsocket.connect(url, config);
// Set up message listener
- this.removeListener = this.ws.addListener((message: any) => {
+ this.removeListener = this.ws.addListener((message: TauriMessage) => {
switch (message.type) {
case 'Text':
this.handleMessage(message.data);
@@ -64,11 +66,11 @@ export class TauriWebSocketWrapper implements MinimalWebSocket {
this.handleMessage(data);
break;
case 'Close':
- console.error('received close event');
this._readyState = this.CLOSED;
const closeEvent = new CloseEvent('close', {
code: message.data?.code || 1000,
reason: message.data?.reason || '',
+ wasClean: true,
});
this.handleClose(closeEvent);
break;
@@ -91,6 +93,14 @@ export class TauriWebSocketWrapper implements MinimalWebSocket {
this._readyState = this.CLOSED;
const errorEvent = new Event('error');
this.handleError(errorEvent);
+ // Fire a close event so the Websocket layer can schedule retries,
+ // matching native WebSocket behaviour where error is always followed by close.
+ const closeEvent = new CloseEvent('close', {
+ code: 1006,
+ reason: 'Connection failed',
+ wasClean: false,
+ });
+ this.handleClose(closeEvent);
}
}
@@ -213,6 +223,22 @@ export class TauriWebSocketWrapper implements MinimalWebSocket {
}
}
+ private handleSendRejection(error: unknown) {
+ if (this._readyState === this.CLOSING || this._readyState === this.CLOSED)
+ return;
+ console.error(`Tauri WebSocket send error for ${this._url}:`, error);
+ this._readyState = this.CLOSED;
+ this.removeListener?.();
+ this.handleError(new Event('error'));
+ this.handleClose(
+ new CloseEvent('close', {
+ code: 1006,
+ reason: 'Send failed',
+ wasClean: false,
+ })
+ );
+ }
+
send(data: string | ArrayBufferLike | Blob | ArrayBufferView): void {
if (!this.ws || this._readyState !== this.OPEN) {
throw new Error(
@@ -220,45 +246,44 @@ export class TauriWebSocketWrapper implements MinimalWebSocket {
);
}
- try {
- if (typeof data === 'string') {
- // Send as text message
- this.ws.send({ type: 'Text', data });
+ if (typeof data === 'string') {
+ // Send as text message
+ this.ws
+ .send({ type: 'Text', data })
+ .catch((e: unknown) => this.handleSendRejection(e));
+ } else {
+ // Convert binary data to number array for Tauri
+ let uint8Array: Uint8Array;
+
+ if (data instanceof ArrayBuffer) {
+ uint8Array = new Uint8Array(data);
+ } else if (data instanceof Uint8Array) {
+ uint8Array = data;
+ } else if (data instanceof Blob) {
+ // For Blob, we need to read it first (this is async in real implementation)
+ throw new Error(
+ 'Blob sending requires async handling - convert to ArrayBuffer first'
+ );
+ } else if (
+ 'buffer' in data &&
+ 'byteOffset' in data &&
+ 'byteLength' in data
+ ) {
+ // Handle ArrayBufferView types
+ uint8Array = new Uint8Array(
+ data.buffer,
+ data.byteOffset,
+ data.byteLength
+ );
} else {
- // Convert binary data to number array for Tauri
- let uint8Array: Uint8Array;
-
- if (data instanceof ArrayBuffer) {
- uint8Array = new Uint8Array(data);
- } else if (data instanceof Uint8Array) {
- uint8Array = data;
- } else if (data instanceof Blob) {
- // For Blob, we need to read it first (this is async in real implementation)
- throw new Error(
- 'Blob sending requires async handling - convert to ArrayBuffer first'
- );
- } else if (
- 'buffer' in data &&
- 'byteOffset' in data &&
- 'byteLength' in data
- ) {
- // Handle ArrayBufferView types
- uint8Array = new Uint8Array(
- data.buffer,
- data.byteOffset,
- data.byteLength
- );
- } else {
- // Handle SharedArrayBuffer
- uint8Array = new Uint8Array(data);
- }
-
- // Send as binary message with number array
- this.ws.send({ type: 'Binary', data: Array.from(uint8Array) });
+ // Handle SharedArrayBuffer
+ uint8Array = new Uint8Array(data);
}
- } catch (error) {
- console.error('Error sending message:', error);
- throw error;
+
+ // Send as binary message with number array
+ this.ws
+ .send({ type: 'Binary', data: Array.from(uint8Array) })
+ .catch((e: unknown) => this.handleSendRejection(e));
}
}
}
diff --git a/js/app/tauri/src-tauri/gen/apple/app_iOS/Info.plist b/js/app/tauri/src-tauri/gen/apple/app_iOS/Info.plist
index 3d238fd69c..b05517d8ee 100644
--- a/js/app/tauri/src-tauri/gen/apple/app_iOS/Info.plist
+++ b/js/app/tauri/src-tauri/gen/apple/app_iOS/Info.plist
@@ -17,7 +17,7 @@
<key>CFBundleShortVersionString</key>
<string>2.0.1</string>
<key>CFBundleVersion</key>
- <string>0.1.3</string>
+ <string>100</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>