bug: Stage 4 Custom Spectrum (.sp) Browse throws TypeError due to undefined window.__TAURI__.dialog #210

Closed
opened 2026-09-06 12:35:09 +01:00 by gronod · 1 comment
Owner

Summary

In Stage 4 (Profile Calculation), selecting "Custom (.sp)" under Substrate OBA / FWA Compensation and clicking the "Browse..." button (btnBrowseCustomSp) throws an unhandled JavaScript exception and fails to open a file picker dialog.

Details & Root Cause

In src/js/colprof.js (lines 54–66):

if (btnBrowseCustomSp && colprofCustomSpPath) {
  btnBrowseCustomSp.addEventListener("click", async () => {
    try {
      const selected = await window.__TAURI__.dialog.open({
        filters: [{ name: 'Spectrum', extensions: ['sp'] }]
      });
      if (selected) {
        colprofCustomSpPath.value = selected;
      }
    } catch (err) {
      console.error("Failed to open dialog:", err);
    }
  });
}

In Tauri v2 with withGlobalTauri: true, window.__TAURI__.dialog is undefined because @tauri-apps/plugin-dialog is not exposed as a frontend global. File picker dialogs in ICCery are handled via backend IPC commands using app.dialog().file() (e.g. select_profile_file, select_target_file, select_csv_save_path). There is currently no backend command for selecting .sp spectrum files.

Steps to Reproduce

  1. Launch ICCery and proceed to Stage 4 (Create Profile).
  2. Set "Substrate OBA / FWA Compensation" to "Custom (.sp)".
  3. Click "Browse...".
  4. Observe that no dialog opens, and devtools console logs: TypeError: Cannot read properties of undefined (reading 'open').

Proposed Remediation

  1. Add a Tauri command select_spectrum_file in src-tauri/src/commands.rs calling app.dialog().file().add_filter("Spectrum File (.sp)", &["sp"]).pick_file(...).
  2. Register select_spectrum_file in src-tauri/src/lib.rs.
  3. Update src/js/colprof.js to invoke select_spectrum_file.
### Summary In Stage 4 (Profile Calculation), selecting "Custom (.sp)" under Substrate OBA / FWA Compensation and clicking the "Browse..." button (`btnBrowseCustomSp`) throws an unhandled JavaScript exception and fails to open a file picker dialog. ### Details & Root Cause In `src/js/colprof.js` (lines 54–66): ```javascript if (btnBrowseCustomSp && colprofCustomSpPath) { btnBrowseCustomSp.addEventListener("click", async () => { try { const selected = await window.__TAURI__.dialog.open({ filters: [{ name: 'Spectrum', extensions: ['sp'] }] }); if (selected) { colprofCustomSpPath.value = selected; } } catch (err) { console.error("Failed to open dialog:", err); } }); } ``` In Tauri v2 with `withGlobalTauri: true`, `window.__TAURI__.dialog` is undefined because `@tauri-apps/plugin-dialog` is not exposed as a frontend global. File picker dialogs in ICCery are handled via backend IPC commands using `app.dialog().file()` (e.g. `select_profile_file`, `select_target_file`, `select_csv_save_path`). There is currently no backend command for selecting `.sp` spectrum files. ### Steps to Reproduce 1. Launch ICCery and proceed to Stage 4 (Create Profile). 2. Set "Substrate OBA / FWA Compensation" to "Custom (.sp)". 3. Click "Browse...". 4. Observe that no dialog opens, and devtools console logs: `TypeError: Cannot read properties of undefined (reading 'open')`. ### Proposed Remediation 1. Add a Tauri command `select_spectrum_file` in `src-tauri/src/commands.rs` calling `app.dialog().file().add_filter("Spectrum File (.sp)", &["sp"]).pick_file(...)`. 2. Register `select_spectrum_file` in `src-tauri/src/lib.rs`. 3. Update `src/js/colprof.js` to invoke `select_spectrum_file`.
gronod added the Kind/Bug
Priority
High
2
labels 2026-09-06 12:35:09 +01:00
Author
Owner

Resolved in commit 5a1ad65 on development.

  • Implemented select_spectrum_file Tauri command in src-tauri/src/commands.rs with .sp filter wrapping app.dialog().file().pick_file(...).
  • Registered select_spectrum_file in the Tauri invoke handler in src-tauri/src/lib.rs.
  • Updated src/js/colprof.js btnBrowseSpectrum event handler to invoke select_spectrum_file passing the current working directory, populating the input and setting wizardState.customSpectrumPath.
  • Verified backend compilation and all 91 cargo unit tests pass.
Resolved in commit `5a1ad65` on `development`. - Implemented `select_spectrum_file` Tauri command in `src-tauri/src/commands.rs` with `.sp` filter wrapping `app.dialog().file().pick_file(...)`. - Registered `select_spectrum_file` in the Tauri invoke handler in `src-tauri/src/lib.rs`. - Updated `src/js/colprof.js` `btnBrowseSpectrum` event handler to invoke `select_spectrum_file` passing the current working directory, populating the input and setting `wizardState.customSpectrumPath`. - Verified backend compilation and all 91 cargo unit tests pass.
Sign in to join this conversation.