Skip to content

Commit

Permalink
Fix includeTabMarkers being altered by clicking the browser action bu…
Browse files Browse the repository at this point in the history
…tton and add setting to hide tab markers with hints global toggle off (#253)
  • Loading branch information
david-tejada authored Dec 6, 2023
1 parent c686964 commit 78e3561
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 7 deletions.
4 changes: 1 addition & 3 deletions src/background/background.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import browser from "webextension-polyfill";
import { store } from "../common/storage";
import { initBackgroundScript } from "./setup/initBackgroundScript";
import { toggleHintsGlobal, updateHintsToggle } from "./actions/toggleHints";
import { toggleKeyboardClicking } from "./actions/toggleKeyboardClicking";
Expand All @@ -20,8 +19,7 @@ browser.contextMenus.onClicked.addListener(contextMenusOnClicked);
browser.runtime.onMessage.addListener(handleRequestFromContent);

browserAction.onClicked.addListener(async () => {
const newStatus = await toggleHintsGlobal();
await store("includeTabMarkers", newStatus);
await toggleHintsGlobal();
});

browser.commands.onCommand.addListener(async (internalCommand: string) => {
Expand Down
1 change: 1 addition & 0 deletions src/common/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const defaultSettings = {
viewportMargin: 1000,
urlInTitle: true,
includeTabMarkers: true,
hideTabMarkersWithGlobalHintsOff: false,
uppercaseTabMarkers: true,
keyboardClicking: false,
keysToExclude: new Array<[string, string]>(),
Expand Down
10 changes: 7 additions & 3 deletions src/content/settings/watchSettingsChanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ async function handleSettingsChanges(
if (isToggleChange) {
await updateHintsEnabled();
await notifyTogglesStatus();
return;
}

if ("keyboardClicking" in changes) {
Expand Down Expand Up @@ -70,13 +69,18 @@ async function handleSettingsChanges(
if (
"urlInTitle" in changes ||
"includeTabMarkers" in changes ||
"uppercaseTabMarkers" in changes
"uppercaseTabMarkers" in changes ||
"hideTabMarkersWithGlobalHintsOff" in changes ||
(Object.keys(changes).includes("hintsToggleGlobal") &&
getCachedSetting("hideTabMarkersWithGlobalHintsOff"))
) {
await initTitleDecoration();
return;
}

await refresh({ hintsStyle: true, hintsPosition: true });
if (!isToggleChange) {
await refresh({ hintsStyle: true, hintsPosition: true });
}
}

export function watchSettingsChanges() {
Expand Down
7 changes: 6 additions & 1 deletion src/content/utils/decorateTitle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import browser from "webextension-polyfill";
import { throttle } from "lodash";
import { getCachedSetting } from "../settings/cacheSettings";
import { isMainframe } from "../setup/contentScriptContext";
import { getToggles } from "../settings/toggles";

// Settings
let urlInTitle: boolean;
Expand Down Expand Up @@ -112,8 +113,12 @@ export async function initTitleDecoration() {
const previousUrlInTitle = urlInTitle;
const previousIncludeTabMarkers = includeTabMarkers;

const globalHintsOff = getToggles().global;

urlInTitle = getCachedSetting("urlInTitle");
includeTabMarkers = getCachedSetting("includeTabMarkers");
includeTabMarkers =
getCachedSetting("includeTabMarkers") &&
!(!globalHintsOff && getCachedSetting("hideTabMarkersWithGlobalHintsOff"));
uppercaseTabMarkers = getCachedSetting("uppercaseTabMarkers");

if (
Expand Down
13 changes: 13 additions & 0 deletions src/settings/SettingsComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,19 @@ export function SettingsComponent() {
/>
</SettingRow>

<SettingRow>
<Toggle
label="Hide tab markers with global hints toggle off"
isPressed={settings.hideTabMarkersWithGlobalHintsOff}
onClick={() => {
handleChange(
"hideTabMarkersWithGlobalHintsOff",
!settings.hideTabMarkersWithGlobalHintsOff
);
}}
/>
</SettingRow>

<SettingRow>
<Toggle
label="Use uppercase tab markers"
Expand Down
1 change: 1 addition & 0 deletions src/typings/StorageSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export const zStorageSchema = z.object({
// Other settings
urlInTitle: z.boolean(),
includeTabMarkers: z.boolean(),
hideTabMarkersWithGlobalHintsOff: z.boolean(),
uppercaseTabMarkers: z.boolean(),
keyboardClicking: z.boolean(),
keysToExclude: z
Expand Down

0 comments on commit 78e3561

Please sign in to comment.