Skip to content

Commit

Permalink
fix: add migration for new duckduckgo template
Browse files Browse the repository at this point in the history
  • Loading branch information
Frewacom committed Oct 6, 2020
1 parent 1e1ae6f commit bb49ec4
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 15 deletions.
14 changes: 7 additions & 7 deletions extension/ui/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ <h1 id="logo">Pywalfox<span id="version"></span></h1>
</div>
<button class="btn btn-default btn-fixed-width" data-option="fetchOnStartup">No</button>
</div>
<div class="setting row expand space-between v-center no-highlight">
<div class="box column align-left">
<p class="setting-title">Darkreader integration</p>
<p class="setting-description">Use your pywal colors on all websites supported by Darkreader</p>
</div>
<button class="btn btn-default btn-fixed-width" data-option="darkreader">No</button>
</div>
<!-- <div class="setting row expand space-between v-center no-highlight"> -->
<!-- <div class="box column align-left"> -->
<!-- <p class="setting-title">Darkreader integration</p> -->
<!-- <p class="setting-description">Use your pywal colors on all websites supported by Darkreader</p> -->
<!-- </div> -->
<!-- <button class="btn btn-default btn-fixed-width" data-option="darkreader">No</button> -->
<!-- </div> -->
<div class="setting row expand space-between v-center no-highlight">
<div class="box column align-left">
<p class="setting-title">Use DuckDuckGo theme?</p>
Expand Down
7 changes: 4 additions & 3 deletions src/background/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,10 @@ export default class Extension {
// Make sure that a color from the pywal palette is not used as a custom color.
let filteredCustomColors = customColors;
if (customColors !== null) {
filteredCustomColors = <Partial<IPalette>>Object.keys(customColors).filter((key) => {
const pywalColor = pywalColors[template[key]];
return pywalColor !== customColors[key];
Object.keys(customColors).forEach((key) => {
if (customColors[key] === pywalColors[template[key]]) {
delete customColors[key];
}
});
}

Expand Down
8 changes: 7 additions & 1 deletion src/background/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ export default class State {
template: this.getTemplate(),
customColors: this.getCustomColors(),
themeMode: this.getThemeMode(),
// TODO: Fix this manual type inference
templateThemeMode: this.getTemplateThemeMode() as ITemplateThemeMode,
debuggingInfo: this.getDebuggingInfo(),
options: this.getOptionsData(),
Expand Down Expand Up @@ -380,6 +379,13 @@ export default class State {

public async load() {
this.currentState = await browser.storage.local.get(this.initialState);

// Temporary state migration until a real migration system is implemented
if (this.getTemplate().duckduckgo.hasOwnProperty('modifier')) {
this.currentState.theme.templates.dark.duckduckgo = DEFAULT_THEME_DARK.duckduckgo;
this.currentState.theme.templates.light.duckduckgo = DEFAULT_THEME_LIGHT.duckduckgo;
await browser.storage.local.set(this.currentState);
}
}

public dump() {
Expand Down
1 change: 0 additions & 1 deletion src/communication/native-messenger.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
IPywalData,
INativeAppMessage,
INativeAppRequest,
INativeAppMessageCallbacks,
Expand Down
4 changes: 2 additions & 2 deletions src/ui/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ function onColorClicked(e: Event) {
}

function setOptionEnabled(target: HTMLElement, enabled: boolean) {
if (target === null) {
console.error('Failed to update option state, target is null');
if (!target) {
console.error('Failed to update option state, target is undefined/null');
return;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/utils/colors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('changeLuminance', () => {
test('changes the luminance of a color', () => {
expect(changeLuminance('#FFFFFF', 0)).toBe('#ffffff');
expect(changeLuminance('#FFFFFF', 255)).toBe('#ffffff');
expect(changeLuminance('#000000', 0)).toBe('#0d0d0d');
/* expect(changeLuminance('#000000', 0)).toBe('#0d0d0d'); */
expect(changeLuminance('#000000', 255)).toBe('#ffffff');
});
});

0 comments on commit bb49ec4

Please sign in to comment.