MichaelYuhe / ai-group-tabs

Organize and group your Chrome tabs with AI
MIT License
981 stars 88 forks source link

[bug fix] Fix auto grouping doesn't work because isOn is undefined by default #61

Closed jt-wang closed 9 months ago

jt-wang commented 9 months ago

Theres' a bug that auto grouping doesn't work.

This is because in background.ts, it executes auto grouping only when Chrome local storage isOn is true.

const enable = await getStorage<boolean>("isOn");
  if (
    !enable ||
    !tab.id ||
    !tab.url ||
    window.type != "normal" ||
    !types.length ||
    (tab.status === "complete" && tab.url.startsWith("chrome://"))
  ) {
    return;
  }

However, isOn is by default undefined, because popup.tsx doesn't store isOn value to Chrome local storage, as the only place it sets is when user clicks on disableGrouping.

  const disableGrouping = () => {
    setIsOn((isOn) => {
      setStorage("isOn", !isOn);
      return !isOn;
    });
  };

Since isOn is undefined, backtround.ts won't execute auto grouping.

This PR fixes this.


48 is aimed to avoid such bugs when these states should have been synced across browser storage and React states.

jt-wang commented 9 months ago

@MichaelYuhe Great suggestion! updated.