Skip to content

Commit

Permalink
fix: set default color scheme at first start
Browse files Browse the repository at this point in the history
Ensure the default color scheme is set when the app is starting up for
the first time. Previously, the app on the Fitbit device was only
showing a black screen until the color scheme was changed within the
companion app.
  • Loading branch information
remigius42 committed Sep 25, 2023
1 parent 0457993 commit e0d9dcf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
13 changes: 13 additions & 0 deletions companion/__tests__/settings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
NEW_TOKEN_DEFAULT_VALUES
} from "../ui/NewTokenFieldName"
import { SettingsButton } from "../ui/SettingsButton"
import { ColorSchemeName } from "../../common/ColorSchemes"

describe("settings", () => {
beforeEach(() => jest.resetAllMocks())
Expand Down Expand Up @@ -54,6 +55,18 @@ describe("settings", () => {
"false"
)
})

it("uses default color scheme", () => {
const settingsStorageMock = jest.mocked(settings).settingsStorage
settingsStorageMock.getItem.mockImplementation(() => null)

fallbackToDefaultSettings()

expect(settingsStorageMock.setItem).toBeCalledWith(
SettingsButton.colorScheme,
JSON.stringify(ColorSchemeName.default)
)
})
})

describe("setDefaultValuesForManualTokenEntry", () => {
Expand Down
7 changes: 7 additions & 0 deletions companion/settings.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { settingsStorage } from "settings"
import { NEW_TOKEN_DEFAULT_VALUES } from "./ui/NewTokenFieldName"
import { SettingsButton } from "./ui/SettingsButton"
import { ColorSchemeName } from "../common/ColorSchemes"

/**
* Fallback to the default settings if some configuration is missing.
Expand All @@ -17,6 +18,12 @@ export function fallbackToDefaultSettings() {
if (settingsStorage.getItem(SettingsButton.showEnlargedTokensView) === null) {
settingsStorage.setItem(SettingsButton.showEnlargedTokensView, "false")
}
if (settingsStorage.getItem(SettingsButton.colorScheme) === null) {
settingsStorage.setItem(
SettingsButton.colorScheme,
JSON.stringify(ColorSchemeName.default)
)
}
}

export function setDefaultValuesForManualTokenEntry() {
Expand Down

0 comments on commit e0d9dcf

Please sign in to comment.