Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,17 @@ <h3>Settings & Preferences</h3>
</label>
</div>

<div class="pref-item">
<div class="pref-info">
<span class="pref-title">Remember active files</span>
<span class="pref-desc">Remember recently viewed files.</span>
</div>
<label class="switch">
<input type="checkbox" id="pref-remember-files" checked />
<span class="slider-round"></span>
</label>
</div>

<div class="pref-item">
<div class="pref-info">
<span class="pref-title">Show Area Fills</span>
Expand Down
2 changes: 2 additions & 0 deletions src/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { PaletteManager } from './palettemanager.js';
import { xyAnalysis } from './xyanalysis.js';
import { Histogram } from './histogram.js';
import { mathChannels } from './mathchannels.js';
import { projectManager } from './projectmanager.js';

window.onload = async function () {
await dataProcessor.loadConfiguration();
Expand All @@ -29,6 +30,7 @@ window.onload = async function () {
PaletteManager.init();
xyAnalysis.init();
Histogram.init();
projectManager.init();

const fileInput = DOM.get('fileInput');
if (fileInput) {
Expand Down
2 changes: 2 additions & 0 deletions src/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const Preferences = {
'pref-show-area-fills': 'showAreaFills',
'pref-smooth-lines': 'smoothLines',
'pref-load-map': 'loadMap',
'pref-remember-files': 'rememberFiles',
},

defaultPrefs: {
Expand All @@ -29,6 +30,7 @@ export const Preferences = {
showAreaFills: true,
smoothLines: false,
loadMap: false,
rememberFiles: true,
},

get prefs() {
Expand Down
45 changes: 40 additions & 5 deletions src/projectmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@
import { mathChannels } from './mathchannels.js';
import { messenger } from './bus.js';
import { dbManager } from './dbmanager.js';
import { Preferences } from './preferences.js';

class ProjectManager {
#currentProject;
#isReplaying;
#libraryContainer;

constructor() {
this.#currentProject =
this.#loadFromStorage() || this.#createEmptyProject();
this.#isReplaying = false;
this.#libraryContainer = null;
this.#currentProject = this.#createEmptyProject();
}

init() {
this.#currentProject =
this.#loadFromStorage() || this.#createEmptyProject();

dbManager.init().then(async () => {
await this.#hydrateActiveFiles();
Expand Down Expand Up @@ -185,6 +190,8 @@

messenger.emit('ui:set-loading', { message: 'Restoring Session...' });

let actuallyLoaded = false;

for (const res of activeResources) {
if (res.dbId && !AppState.files.some((f) => f.dbId === res.dbId)) {
const signals = await dbManager.getFileSignals(res.dbId);
Expand All @@ -202,13 +209,26 @@
size: meta.size,
metadata: meta.metadata,
});
actuallyLoaded = true;
} else {
res.isActive = false;
}
}
}

if (AppState.files.length > 0) {
if (actuallyLoaded) {
messenger.emit('dataprocessor:batch-load-completed', {});

requestAnimationFrame(() => {
this.replayHistory();
});
} else {
messenger.emit('dataprocessor:batch-load-completed', {});
messenger.emit('ui:updateDataLoadedState', { status: false });
}
messenger.emit('dataprocessor:batch-load-completed', {});

this.#saveToStorage();
}

registerFile(file) {
Expand Down Expand Up @@ -284,8 +304,23 @@
}

#loadFromStorage() {
const data = localStorage.getItem('current_project');
return data ? JSON.parse(data) : null;
if (Preferences.prefs.rememberFiles) {
const data = localStorage.getItem('current_project');
return data ? JSON.parse(data) : null;
} else {
const data = localStorage.getItem('current_project');
if (data) {
const project = JSON.parse(data);

if (project && project.resources) {
project.resources.forEach((resource) => {
resource.isActive = false;
});
}

return project;
}
}
}

#saveToStorage() {
Expand Down Expand Up @@ -364,11 +399,11 @@
action.payload.channelName,
{ ...action.payload.options, isReplay: true }
);
successCount++;

Check warning on line 402 in src/projectmanager.js

View workflow job for this annotation

GitHub Actions / validate_and_build

'successCount' is assigned a value but never used

Check warning on line 402 in src/projectmanager.js

View workflow job for this annotation

GitHub Actions / validate_and_build

'successCount' is assigned a value but never used
}
} catch (e) {
console.warn(e);
skipCount++;

Check warning on line 406 in src/projectmanager.js

View workflow job for this annotation

GitHub Actions / validate_and_build

'skipCount' is assigned a value but never used

Check warning on line 406 in src/projectmanager.js

View workflow job for this annotation

GitHub Actions / validate_and_build

'skipCount' is assigned a value but never used
}
}
this.#isReplaying = false;
Expand Down
4 changes: 1 addition & 3 deletions src/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@ export const UI = {
UI.setLoading(true, event.message);
});

messenger.on('dataprocessor:batch-load-completed', (event) => {
messenger.on('dataprocessor:batch-load-completed', () => {
UI.renderSignalList();

// 1. Reveal the container first
UI.updateDataLoadedState(true);
UI.setLoading(false);

Expand All @@ -51,7 +50,6 @@ export const UI = {
fileInfo.innerText = `${AppState.files.length} logs loaded`;
}

// 2. Wait for DOM reflow before rendering chart.
if (AppState.files.length > 0) {
requestAnimationFrame(() => {
ChartManager.render();
Expand Down
17 changes: 8 additions & 9 deletions tests/preferences.test.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import { jest, describe, test, expect, beforeEach } from '@jest/globals';

import { Preferences } from '../src/preferences.js';
import { UI } from '../src/ui.js';
await jest.unstable_mockModule('../src/ui.js', () => ({
UI: {
setTheme: jest.fn(),
},
}));

UI.setTheme = jest.fn();
const { Preferences } = await import('../src/preferences.js');
const { UI } = await import('../src/ui.js');

describe('Preferences Module', () => {
beforeEach(() => {
// 2. Set up the DOM structure expected by Preferences
document.body.innerHTML = `
<div class="preferences-list">
<input type="checkbox" id="pref-persistence" />
<input type="checkbox" id="pref-performance" />
<input type="checkbox" id="pref-theme-dark" />
<input type="checkbox" id="pref-custom-palette" />
<input type="checkbox" id="pref-remember-files" />
</div>
`;
localStorage.clear();
Expand Down Expand Up @@ -41,7 +45,6 @@ describe('Preferences Module', () => {
});

test('init sets theme and attaches listeners', () => {
// 1. Setup localStorage so loadPreferences() sees the dark theme as active
localStorage.setItem(
Preferences.PREFS_KEY,
JSON.stringify({
Expand All @@ -52,15 +55,11 @@ describe('Preferences Module', () => {

const themeToggle = document.getElementById('pref-theme-dark');

// 2. Run init
Preferences.init();

// Now it should be checked because loadPreferences() set it
expect(themeToggle.checked).toBe(true);
// And UI.setTheme should be called with 'dark'
expect(UI.setTheme).toHaveBeenCalledWith('dark');

// 3. Test the toggle listener
themeToggle.checked = false;
themeToggle.dispatchEvent(new Event('change'));

Expand Down
Loading
Loading