Connect saved machines concurrently in the chat workspace
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
import '../../../core/servers/chat/chat_identity.dart';
|
||||
import '../../../core/servers/server_scope.dart';
|
||||
import 'chat_workspace_nodes.dart';
|
||||
import 'chat_workspace_snapshot.dart';
|
||||
import 'chat_workspace_store.dart';
|
||||
|
||||
/// Adopt the previous primary-machine layout once, without altering its copy.
|
||||
/// Thereafter all panes live together independently of the pipelines/run default.
|
||||
class FederatedWorkspaceStore implements ChatWorkspaceStore {
|
||||
FederatedWorkspaceStore({
|
||||
required this.primary,
|
||||
ChatWorkspaceStore? combined,
|
||||
ChatWorkspaceStore? legacy,
|
||||
}) : combined =
|
||||
combined ??
|
||||
const SharedPreferencesChatWorkspaceStore(
|
||||
serverScope: 'all-saved-servers',
|
||||
),
|
||||
legacy =
|
||||
legacy ??
|
||||
SharedPreferencesChatWorkspaceStore(
|
||||
serverScope: serverStorageScope(primary),
|
||||
);
|
||||
final String? primary;
|
||||
final ChatWorkspaceStore combined, legacy;
|
||||
@override
|
||||
Future<ChatWorkspaceSnapshot?> read() async {
|
||||
final saved = await combined.read();
|
||||
if (saved != null || primary == null) return saved;
|
||||
final old = await legacy.read();
|
||||
if (old == null) return null;
|
||||
ChatWorkspaceNode map(ChatWorkspaceNode node) => switch (node) {
|
||||
ChatWorkspacePane() => ChatWorkspacePane(
|
||||
node.id,
|
||||
parseFederatedChatId(node.sessionId) == null
|
||||
? federatedChatId(primary!, node.sessionId)
|
||||
: node.sessionId,
|
||||
),
|
||||
ChatWorkspaceSplit() => ChatWorkspaceSplit(
|
||||
node.id,
|
||||
node.axis,
|
||||
map(node.first),
|
||||
map(node.second),
|
||||
ratio: node.ratio,
|
||||
),
|
||||
};
|
||||
final migrated = ChatWorkspaceSnapshot.fromLayout(
|
||||
old.root == null ? null : map(old.root!),
|
||||
old.activePaneId,
|
||||
sidebarMode: old.sidebarMode,
|
||||
mobilePeekFraction: old.mobilePeekFraction,
|
||||
);
|
||||
if (migrated != null) await combined.write(migrated);
|
||||
return migrated;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> write(ChatWorkspaceSnapshot snapshot) =>
|
||||
combined.write(snapshot);
|
||||
}
|
||||
Reference in New Issue
Block a user