Skip to content

Commit 11715f0

Browse files
refactor brush mode localstorage
1 parent e7a8c8c commit 11715f0

1 file changed

Lines changed: 9 additions & 17 deletions

File tree

src/index.js

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { log_message, LogLevel } from "../build/error_logging";
3131
import { initialize_annotation_canvases } from "../build/canvas_utils";
3232
import { record_action, record_finish, record_finish_edit, record_finish_move, undo, redo } from "../build/actions";
3333
import { ULabelMask } from "../build/mask_utils";
34+
import { get_local_storage_item, set_local_storage_item } from "../build/utilities";
3435

3536
import $ from "jquery";
3637
const jQuery = $;
@@ -55,11 +56,10 @@ jQuery.fn.outer_html = function () {
5556
return jQuery("<div />").append(this.eq(0).clone()).html();
5657
};
5758

58-
export class ULabel {
59-
// Valid brush overlap modes and the localStorage key used to persist the global choice
60-
static BRUSH_OVERLAP_MODES = ["none", "exclude", "overwrite"];
61-
static BRUSH_OVERLAP_STORAGE_KEY = "ulabel_brush_overlap_mode";
59+
// Valid brush overlap modes for bitmask painting (see set_brush_overlap_mode).
60+
const BRUSH_OVERLAP_MODES = ["none", "exclude", "overwrite"];
6261

62+
export class ULabel {
6363
static version() {
6464
return ULABEL_VERSION;
6565
}
@@ -2526,13 +2526,9 @@ export class ULabel {
25262526
// Load the global brush overlap mode from localStorage, falling back to the config default.
25272527
load_brush_overlap_mode() {
25282528
let mode = this.config["default_brush_overlap_mode"];
2529-
try {
2530-
const stored = window.localStorage.getItem(ULabel.BRUSH_OVERLAP_STORAGE_KEY);
2531-
if (stored !== null && ULabel.BRUSH_OVERLAP_MODES.includes(stored)) {
2532-
mode = stored;
2533-
}
2534-
} catch {
2535-
// localStorage may be unavailable; fall back to the config default
2529+
const stored = get_local_storage_item("ulabel_brush_overlap_mode");
2530+
if (stored !== null && BRUSH_OVERLAP_MODES.includes(stored)) {
2531+
mode = stored;
25362532
}
25372533
this.config["brush_overlap_mode"] = mode;
25382534
}
@@ -2543,16 +2539,12 @@ export class ULabel {
25432539

25442540
// Set the global brush overlap mode, persist it, and update the toolbox buttons.
25452541
set_brush_overlap_mode(mode) {
2546-
if (!ULabel.BRUSH_OVERLAP_MODES.includes(mode)) {
2542+
if (!BRUSH_OVERLAP_MODES.includes(mode)) {
25472543
log_message(`Invalid brush overlap mode: ${mode}`, LogLevel.WARNING);
25482544
return;
25492545
}
25502546
this.config["brush_overlap_mode"] = mode;
2551-
try {
2552-
window.localStorage.setItem(ULabel.BRUSH_OVERLAP_STORAGE_KEY, mode);
2553-
} catch {
2554-
// Ignore persistence failures (e.g. localStorage unavailable)
2555-
}
2547+
set_local_storage_item("ulabel_brush_overlap_mode", mode);
25562548
BrushToolboxItem.update_overlap_mode_buttons(mode);
25572549
}
25582550

0 commit comments

Comments
 (0)