Skip to content

add SI unit toggle button#78

Open
otomn wants to merge 1 commit into
zz85:masterfrom
otomn:unitSI
Open

add SI unit toggle button#78
otomn wants to merge 1 commit into
zz85:masterfrom
otomn:unitSI

Conversation

@otomn
Copy link
Copy Markdown

@otomn otomn commented Mar 17, 2026

closes #77

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a UI toggle to switch between IEC (KiB = 1024) and SI (KB = 1000) byte units, addressing the requested disambiguation in #77.

Changes:

  • Add unitIsSI state to PluginManager and use it in format(bytes) to choose 1000 vs 1024 and unit labels (KB vs KiB, etc.).
  • Add a new “KiB/KB” toggle button to the header UI.
  • Add toggleUnit() and (currently) auto-toggle on macOS during startup.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
app/js/utils.js Makes byte formatting depend on a new SI/IEC toggle and changes unit labels accordingly.
app/js/router.js Introduces PluginManager.unitIsSI state.
app/js/radar.js Adds unit toggle behavior (including a macOS startup toggle) and reloads last data on toggle.
app/index.html Adds the unit toggle button to the toolbar.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/js/radar.js
Comment on lines +709 to +710
unit_button.textContent = PluginManager.unitIsSI ? "KB" : "KiB"
PluginManager.loadLast()
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toggleUnit() always calls PluginManager.loadLast(), which will throw if LASTLOAD_FILE does not exist yet (e.g., before the first scan, or if the file was deleted). Guard the reload (similar to colors.js, which checks PluginManager.data) and update the UI without forcing a reload when there’s no data to reload.

Suggested change
unit_button.textContent = PluginManager.unitIsSI ? "KB" : "KiB"
PluginManager.loadLast()
unit_button.textContent = PluginManager.unitIsSI ? "KB" : "KiB";
if (PluginManager.data) {
PluginManager.loadLast();
}

Copilot uses AI. Check for mistakes.
Comment thread app/js/radar.js
Comment on lines +470 to +472
if (navigator.platform.includes("Mac")) {
toggleUnit()
}
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR introduces platform-specific behavior (auto-switching units on macOS) that isn’t described in the PR title/description or the linked issue. If the intent is to only add a user-controlled toggle, consider removing the macOS default-switch or documenting/justifying it and persisting the preference so it’s consistent across restarts.

Copilot uses AI. Check for mistakes.
Comment thread app/js/utils.js
GB: gb,
TB: tb
};
let unitIsSI = global.PluginManager.unitIsSI
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

format() now directly reads global.PluginManager.unitIsSI, which will throw if PluginManager is not initialized yet (or if this module is used in the non-renderer Node context). Make this access defensive (e.g., default to binary units when PluginManager/unitIsSI is missing) so format() remains safe to call in all existing environments.

Suggested change
let unitIsSI = global.PluginManager.unitIsSI
let unitIsSI = !!(global && global.PluginManager && global.PluginManager.unitIsSI);

Copilot uses AI. Check for mistakes.
Comment thread app/js/radar.js
Comment on lines +470 to +472
if (navigator.platform.includes("Mac")) {
toggleUnit()
}
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling toggleUnit() during ready() on macOS can crash on a fresh run because toggleUnit() triggers PluginManager.loadLast(), which reads LASTLOAD_FILE unconditionally. Either remove the automatic toggle, or ensure toggleUnit() only reloads data when a previous snapshot exists (and/or when PluginManager.data is set).

Suggested change
if (navigator.platform.includes("Mac")) {
toggleUnit()
}

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1KB = 1000B

2 participants