Skip to content

Commit

Permalink
Cd into /files if it exists
Browse files Browse the repository at this point in the history
  • Loading branch information
martinRenou committed Jan 25, 2024
1 parent f27f104 commit cd00e3f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/web_worker_kernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ interface IXeusKernel {

cd(path: string): Promise<void>;

isDir(path: string): Promise<boolean>;

processMessage(msg: any): Promise<void>;
}

Expand Down Expand Up @@ -183,6 +185,11 @@ export class WebWorkerKernel implements IKernel {

if (options.mountDrive) {
await this._remote.mount(driveName, '/drive', PageConfig.getBaseUrl());
}

if (await this._remote.isDir('/files')) {
await this._remote.cd('/files');
} else if (options.mountDrive) {
await this._remote.cd(localPath);
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@ class XeusKernel {
globalThis.Module.FS.chdir(path);
}

isDir(path: string) {
try {
const lookup = globalThis.Module.FS.lookupPath(path);
return globalThis.Module.FS.isDir(lookup.node.mode);
} catch (e) {
return false;
}
}

async processMessage(event: any): Promise<void> {
const msg_type = event.msg.header.msg_type;

Expand Down

0 comments on commit cd00e3f

Please sign in to comment.