mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-21 16:38:23 +01:00
Fix Preview for Uninitialized Connections (#1473)
If a connection had not been previously initialized, selecting it in the preview dropdown was bug-prone. This ensures the connection is complete before checking the mimetype and selecting the type of preview.
This commit is contained in:
parent
9e7293d98a
commit
e49480e628
@ -24,6 +24,7 @@ Wave Terminal v0.10.0 introduces workspaces, making it easier to manage multiple
|
|||||||
- [bugfix] Fixed tab flickering issues during tab switches
|
- [bugfix] Fixed tab flickering issues during tab switches
|
||||||
- [bugfix] Corrected WaveAI text area resize behavior
|
- [bugfix] Corrected WaveAI text area resize behavior
|
||||||
- [bugfix] Fixed concurrent block controller start issues
|
- [bugfix] Fixed concurrent block controller start issues
|
||||||
|
- [bugfix] Fixed Preview Blocks for uninitialized connections
|
||||||
- Upgraded Go toolchain to 1.23.4
|
- Upgraded Go toolchain to 1.23.4
|
||||||
- Other bug fixes, performance improvements, and dependency updates
|
- Other bug fixes, performance improvements, and dependency updates
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ export class PreviewModel implements ViewModel {
|
|||||||
normFilePath: Atom<Promise<string>>;
|
normFilePath: Atom<Promise<string>>;
|
||||||
loadableStatFilePath: Atom<Loadable<string>>;
|
loadableStatFilePath: Atom<Loadable<string>>;
|
||||||
loadableFileInfo: Atom<Loadable<FileInfo>>;
|
loadableFileInfo: Atom<Loadable<FileInfo>>;
|
||||||
connection: Atom<string>;
|
connection: Atom<Promise<string>>;
|
||||||
statFile: Atom<Promise<FileInfo>>;
|
statFile: Atom<Promise<FileInfo>>;
|
||||||
fullFile: Atom<Promise<FullFile>>;
|
fullFile: Atom<Promise<FullFile>>;
|
||||||
fileMimeType: Atom<Promise<string>>;
|
fileMimeType: Atom<Promise<string>>;
|
||||||
@ -136,6 +136,7 @@ export class PreviewModel implements ViewModel {
|
|||||||
fileContentSaved: PrimitiveAtom<string | null>;
|
fileContentSaved: PrimitiveAtom<string | null>;
|
||||||
fileContent: WritableAtom<Promise<string>, [string], void>;
|
fileContent: WritableAtom<Promise<string>, [string], void>;
|
||||||
newFileContent: PrimitiveAtom<string | null>;
|
newFileContent: PrimitiveAtom<string | null>;
|
||||||
|
connectionError: PrimitiveAtom<string>;
|
||||||
|
|
||||||
openFileModal: PrimitiveAtom<boolean>;
|
openFileModal: PrimitiveAtom<boolean>;
|
||||||
openFileError: PrimitiveAtom<string>;
|
openFileError: PrimitiveAtom<string>;
|
||||||
@ -167,6 +168,7 @@ export class PreviewModel implements ViewModel {
|
|||||||
this.markdownShowToc = atom(false);
|
this.markdownShowToc = atom(false);
|
||||||
this.filterOutNowsh = atom(true);
|
this.filterOutNowsh = atom(true);
|
||||||
this.monacoRef = createRef();
|
this.monacoRef = createRef();
|
||||||
|
this.connectionError = atom("");
|
||||||
this.viewIcon = atom((get) => {
|
this.viewIcon = atom((get) => {
|
||||||
const blockData = get(this.blockAtom);
|
const blockData = get(this.blockAtom);
|
||||||
if (blockData?.meta?.icon) {
|
if (blockData?.meta?.icon) {
|
||||||
@ -359,15 +361,22 @@ export class PreviewModel implements ViewModel {
|
|||||||
return fileInfo.dir + "/" + fileInfo.name;
|
return fileInfo.dir + "/" + fileInfo.name;
|
||||||
});
|
});
|
||||||
this.loadableStatFilePath = loadable(this.statFilePath);
|
this.loadableStatFilePath = loadable(this.statFilePath);
|
||||||
this.connection = atom<string>((get) => {
|
this.connection = atom<Promise<string>>(async (get) => {
|
||||||
return get(this.blockAtom)?.meta?.connection;
|
const connName = get(this.blockAtom)?.meta?.connection;
|
||||||
|
try {
|
||||||
|
await RpcApi.ConnEnsureCommand(TabRpcClient, connName, { timeout: 60000 });
|
||||||
|
globalStore.set(this.connectionError, "");
|
||||||
|
} catch (e) {
|
||||||
|
globalStore.set(this.connectionError, e as string);
|
||||||
|
}
|
||||||
|
return connName;
|
||||||
});
|
});
|
||||||
this.statFile = atom<Promise<FileInfo>>(async (get) => {
|
this.statFile = atom<Promise<FileInfo>>(async (get) => {
|
||||||
const fileName = get(this.metaFilePath);
|
const fileName = get(this.metaFilePath);
|
||||||
if (fileName == null) {
|
if (fileName == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const conn = get(this.connection) ?? "";
|
const conn = (await get(this.connection)) ?? "";
|
||||||
const statFile = await services.FileService.StatFile(conn, fileName);
|
const statFile = await services.FileService.StatFile(conn, fileName);
|
||||||
return statFile;
|
return statFile;
|
||||||
});
|
});
|
||||||
@ -384,7 +393,7 @@ export class PreviewModel implements ViewModel {
|
|||||||
if (fileName == null) {
|
if (fileName == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const conn = get(this.connection) ?? "";
|
const conn = (await get(this.connection)) ?? "";
|
||||||
const file = await services.FileService.ReadFile(conn, fileName);
|
const file = await services.FileService.ReadFile(conn, fileName);
|
||||||
return file;
|
return file;
|
||||||
});
|
});
|
||||||
@ -434,10 +443,14 @@ export class PreviewModel implements ViewModel {
|
|||||||
const mimeType = await getFn(this.fileMimeType);
|
const mimeType = await getFn(this.fileMimeType);
|
||||||
const fileInfo = await getFn(this.statFile);
|
const fileInfo = await getFn(this.statFile);
|
||||||
const fileName = await getFn(this.statFilePath);
|
const fileName = await getFn(this.statFilePath);
|
||||||
|
const connErr = getFn(this.connectionError);
|
||||||
const editMode = getFn(this.editMode);
|
const editMode = getFn(this.editMode);
|
||||||
const parentFileInfo = await this.getParentInfo(fileInfo);
|
const parentFileInfo = await this.getParentInfo(fileInfo);
|
||||||
console.log(parentFileInfo);
|
console.log(parentFileInfo);
|
||||||
|
|
||||||
|
if (connErr != "") {
|
||||||
|
return { errorStr: `Connection Error: ${connErr}` };
|
||||||
|
}
|
||||||
if (parentFileInfo?.notfound ?? false) {
|
if (parentFileInfo?.notfound ?? false) {
|
||||||
return { errorStr: `Parent Directory Not Found: ${fileInfo.path}` };
|
return { errorStr: `Parent Directory Not Found: ${fileInfo.path}` };
|
||||||
}
|
}
|
||||||
@ -505,7 +518,7 @@ export class PreviewModel implements ViewModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getParentInfo(fileInfo: FileInfo): Promise<FileInfo | undefined> {
|
async getParentInfo(fileInfo: FileInfo): Promise<FileInfo | undefined> {
|
||||||
const conn = globalStore.get(this.connection);
|
const conn = await globalStore.get(this.connection);
|
||||||
try {
|
try {
|
||||||
const parentFileInfo = await RpcApi.RemoteFileJoinCommand(TabRpcClient, [fileInfo.path, ".."], {
|
const parentFileInfo = await RpcApi.RemoteFileJoinCommand(TabRpcClient, [fileInfo.path, ".."], {
|
||||||
route: makeConnRoute(conn),
|
route: makeConnRoute(conn),
|
||||||
@ -526,7 +539,7 @@ export class PreviewModel implements ViewModel {
|
|||||||
this.updateOpenFileModalAndError(false);
|
this.updateOpenFileModalAndError(false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
const conn = globalStore.get(this.connection);
|
const conn = await globalStore.get(this.connection);
|
||||||
try {
|
try {
|
||||||
const newFileInfo = await RpcApi.RemoteFileJoinCommand(TabRpcClient, [fileInfo.path, ".."], {
|
const newFileInfo = await RpcApi.RemoteFileJoinCommand(TabRpcClient, [fileInfo.path, ".."], {
|
||||||
route: makeConnRoute(conn),
|
route: makeConnRoute(conn),
|
||||||
@ -586,7 +599,7 @@ export class PreviewModel implements ViewModel {
|
|||||||
console.log("not saving file, newFileContent is null");
|
console.log("not saving file, newFileContent is null");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const conn = globalStore.get(this.connection) ?? "";
|
const conn = (await globalStore.get(this.connection)) ?? "";
|
||||||
try {
|
try {
|
||||||
await services.FileService.SaveFile(conn, filePath, stringToBase64(newFileContent));
|
await services.FileService.SaveFile(conn, filePath, stringToBase64(newFileContent));
|
||||||
globalStore.set(this.fileContent, newFileContent);
|
globalStore.set(this.fileContent, newFileContent);
|
||||||
@ -609,7 +622,7 @@ export class PreviewModel implements ViewModel {
|
|||||||
this.updateOpenFileModalAndError(false);
|
this.updateOpenFileModalAndError(false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
const conn = globalStore.get(this.connection);
|
const conn = await globalStore.get(this.connection);
|
||||||
try {
|
try {
|
||||||
const newFileInfo = await RpcApi.RemoteFileJoinCommand(TabRpcClient, [fileInfo.dir, filePath], {
|
const newFileInfo = await RpcApi.RemoteFileJoinCommand(TabRpcClient, [fileInfo.dir, filePath], {
|
||||||
route: makeConnRoute(conn),
|
route: makeConnRoute(conn),
|
||||||
|
Loading…
Reference in New Issue
Block a user