Skip to content

Commit

Permalink
Fix loading of demos
Browse files Browse the repository at this point in the history
  • Loading branch information
ochafik committed Dec 25, 2024
1 parent 0a99893 commit 38745be
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ window.addEventListener('load', async () => {

registerCustomAppHeightCSSProperty();

const fs = await createEditorFS({prefix: '/', allowPersistence: isInStandaloneMode});
const fs = await createEditorFS({prefix: '/libraries/', allowPersistence: isInStandaloneMode});

await registerOpenSCADLanguage(fs, '/', zipArchives);

Expand Down
5 changes: 5 additions & 0 deletions src/runner/openscad-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ addEventListener('message', async (e) => {
if (inputs) {
for (const source of inputs) {
try {
if (source.path.startsWith('/libraries/')) {
console.log(`Skipping ${source.path}`);
continue;
}
console.log(`Writing ${source.path}`);
instance.FS.writeFile(source.path, await fetchSource(source));
} catch (e) {
console.trace(e);
Expand Down
18 changes: 13 additions & 5 deletions src/state/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,24 @@ export class Model {
}

openFile(path: string) {
// alert(`TODO: open ${path}`);
// console.log(`openFile: ${path}`);
if (this.mutate(s => {
if (s.params.activePath != path) {
s.params.activePath = path;
if (!s.params.sources.find(src => src.path === path)) {
let content = '';
const readSource = (path: string) => {
try {
content = new TextDecoder("utf-8").decode(this.fs.readFileSync(path));
return new TextDecoder("utf-8").decode(this.fs.readFileSync(path));
} catch (e) {
console.error('Error while reading file:', e);
return '';
}
};
// Remove source of previous active path if it's unmodified
const activePathContent = readSource(s.params.activePath);
s.params.sources = s.params.sources.filter(src => src.path !== s.params.activePath || src.content != activePathContent);

s.params.activePath = path;
if (!s.params.sources.find(src => src.path === path)) {
const content = readSource(path);
s.params.sources = [...s.params.sources, {path, content}];
}
s.lastCheckerRun = undefined;
Expand Down Expand Up @@ -307,6 +314,7 @@ export class Model {
}

async render({isPreview, mountArchives, now, retryInOtherDim}: {isPreview: boolean, mountArchives?: boolean, now: boolean, retryInOtherDim?: boolean}) {
// console.log(JSON.stringify(this.state, null, 2));
mountArchives ??= true;
retryInOtherDim ??= true;
const setRendering = (s: State, value: boolean) => {
Expand Down

0 comments on commit 38745be

Please sign in to comment.