Fix: 修复在线版python_pyodide板卡本地文件管理下文件编辑后无法保存

This commit is contained in:
王立帮
2024-12-22 10:05:11 +08:00
parent c2edffa8a3
commit 1bf7ec2e93
3 changed files with 10 additions and 5 deletions

File diff suppressed because one or more lines are too long

View File

@@ -22,6 +22,7 @@ class WebAccessFSExt extends WebAccessFS {
export default class FileSystemFS extends FS {
#fs_ = null;
#encoder_ = new TextEncoder();
constructor() {
super();
@@ -68,7 +69,8 @@ export default class FileSystemFS extends FS {
}
async writeFile(path, data) {
return this.#fs_.writeFile(path, data, 'utf8');
const encodedArray = this.#encoder_.encode(data);
return this.#fs_.writeFile(path, encodedArray);
}
async isFile(path) {

View File

@@ -330,10 +330,13 @@ export default class StatusBarFileSystem extends PageBase {
this.#fileTree_.showProgress();
const id = this.#fileTree_.getSelectedNodeId();
const fs = this.#fileTree_.getFS();
const [error,] = await fs.writeFile(id, this.#editor_.getValue());
this.#fileTree_.hideProgress();
if (!error) {
try {
await fs.writeFile(id, this.#editor_.getValue());
this.setStatus(false);
} catch (error) {
Debug.error(error);
} finally {
this.#fileTree_.hideProgress();
}
}