add SI unit toggle button#78
Conversation
There was a problem hiding this comment.
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
unitIsSIstate toPluginManagerand use it informat(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.
| unit_button.textContent = PluginManager.unitIsSI ? "KB" : "KiB" | ||
| PluginManager.loadLast() |
There was a problem hiding this comment.
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.
| unit_button.textContent = PluginManager.unitIsSI ? "KB" : "KiB" | |
| PluginManager.loadLast() | |
| unit_button.textContent = PluginManager.unitIsSI ? "KB" : "KiB"; | |
| if (PluginManager.data) { | |
| PluginManager.loadLast(); | |
| } |
| if (navigator.platform.includes("Mac")) { | ||
| toggleUnit() | ||
| } |
There was a problem hiding this comment.
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.
| GB: gb, | ||
| TB: tb | ||
| }; | ||
| let unitIsSI = global.PluginManager.unitIsSI |
There was a problem hiding this comment.
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.
| let unitIsSI = global.PluginManager.unitIsSI | |
| let unitIsSI = !!(global && global.PluginManager && global.PluginManager.unitIsSI); |
| if (navigator.platform.includes("Mac")) { | ||
| toggleUnit() | ||
| } |
There was a problem hiding this comment.
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).
| if (navigator.platform.includes("Mac")) { | |
| toggleUnit() | |
| } |
closes #77