Skip to content

Commit

Permalink
can now toggle worker timers
Browse files Browse the repository at this point in the history
  • Loading branch information
felixroos committed Feb 4, 2025
1 parent f228d19 commit c00e564
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
6 changes: 6 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@ <h3>Panel settings</h3>
Enable strudel highlights
</label>
</p>
<p>
<label>
<input type="checkbox" id="settings-strudel-worker-timers-enabled" />
Enable strudel worker timers
</label>
</p>
</section>
<hr />
<section>
Expand Down
5 changes: 5 additions & 0 deletions src/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const defaultSettings = {
pastingMode: false,
fontFamily: 'monospace',
strudelHighlightsEnabled: true,
workerTimers: false,
};

const usernameInput = document.querySelector('#settings-username');
Expand All @@ -66,6 +67,7 @@ const zenModeCheckbox = document.querySelector('#settings-zen-mode');
const panelModeSelect = document.querySelector('#settings-panel-mode');
const vimModeCheckbox = document.querySelector('#settings-vim-mode');
const lineWrappingCheckbox = document.querySelector('#settings-line-wrapping');
const workerTimersCheckbox = document.querySelector('#settings-strudel-worker-timers-enabled');
const lineNumbersCheckbox = document.querySelector('#settings-line-numbers');
const strudelAutocompleteCheckbox = document.querySelector('#settings-strudel-autocomplete');
const closeBracketsCheckbox = document.querySelector('#settings-close-brackets');
Expand All @@ -86,6 +88,7 @@ function inferSettingsFromDom() {
panelMode: panelModeSelect?.value ?? defaultSettings.panelMode,
vimMode: vimModeCheckbox?.checked ?? defaultSettings.vimMode,
lineWrapping: lineWrappingCheckbox?.checked ?? defaultSettings.lineWrapping,
workerTimers: workerTimersCheckbox?.checked ?? defaultSettings.workerTimers,
lineNumbers: lineNumbersCheckbox?.checked ?? defaultSettings.lineNumbers,
strudelAutocomplete: strudelAutocompleteCheckbox?.checked ?? defaultSettings.strudelAutocomplete,
closeBrackets: closeBracketsCheckbox?.checked ?? defaultSettings.closeBrackets,
Expand All @@ -108,6 +111,7 @@ function inferSettingsFromDom() {
vimModeCheckbox,
welcomeMessageCheckbox,
lineWrappingCheckbox,
workerTimersCheckbox,
lineNumbersCheckbox,
strudelAutocompleteCheckbox,
closeBracketsCheckbox,
Expand Down Expand Up @@ -168,6 +172,7 @@ export async function applySettingsToNudel(settings = getSettings()) {
panelModeSelect.value = next.boxedMode;
vimModeCheckbox.checked = next.vimMode;
lineWrappingCheckbox.checked = next.lineWrapping;
workerTimersCheckbox.checked = next.workerTimers;
lineNumbersCheckbox.checked = next.lineNumbers;
strudelAutocompleteCheckbox.checked = next.strudelAutocomplete;
closeBracketsCheckbox.checked = next.closeBrackets;
Expand Down
18 changes: 9 additions & 9 deletions src/strudel.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ export class StrudelSession {
}

async init() {
// why do we need to await this stuff here?
this.settings = window.parent.getSettings?.() || {};
if (!this.settings) {
console.warn(`Couldn't get nudel settings within strudel`);
}

// why do we need to await this stuff here? i have no clue
this.core = await import('@strudel/core');
this.mini = await import('@strudel/mini');
this.webaudio = await import('@strudel/webaudio');
Expand All @@ -68,8 +73,8 @@ export class StrudelSession {
this.scheduler = new Cyclist({
onTrigger: getTrigger({ defaultOutput: webaudioOutput, getTime }),
getTime,
setInterval,
clearInterval,
setInterval: this.settings.workerTimers ? setInterval : globalThis.setInterval,
clearInterval: this.settings.workerTimers ? clearInterval : globalThis.clearInterval,
});
setTime(() => this.scheduler.now()); // this is cursed

Expand Down Expand Up @@ -114,12 +119,7 @@ export class StrudelSession {
},
);

const settings = window.parent.getSettings?.();
if (!settings) {
throw new Error(`Couldn't get nudel settings within strudel`);
}

if (settings.strudelHighlightsEnabled) {
if (this.settings?.strudelHighlightsEnabled) {
this.framer.start();
}
}
Expand Down

0 comments on commit c00e564

Please sign in to comment.