Skip to content

Commit 6aee993

Browse files
committed
fix edge case in migration; update manifest to version 3
1 parent 7b32d58 commit 6aee993

File tree

4 files changed

+36
-15
lines changed

4 files changed

+36
-15
lines changed

src/background/migrate/__tests__/migrate-old-format.test.js

+21-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('MigrateOldFormat', () => {
3131
expect(mockSet).toHaveBeenCalledTimes(0);
3232
});
3333

34-
it('returns styles as is when they are already in the new format', async () => {
34+
it('returns styles as is when they are in the new format', async () => {
3535
const mockSet = jest.fn((_, callback) => callback());
3636
const mockGet = (_, callback) => {
3737
callback({ styles: newFormat });
@@ -43,6 +43,26 @@ describe('MigrateOldFormat', () => {
4343
expect(mockSet).toHaveBeenCalledTimes(0);
4444
});
4545

46+
it('returns styles as is when they are in the new format (with empty css)', async () => {
47+
const newFormatWithEmptyCss = {
48+
'www.google.com': {
49+
css: '',
50+
enabled: false,
51+
readability: false,
52+
},
53+
};
54+
55+
const mockSet = jest.fn((_, callback) => callback());
56+
const mockGet = (_, callback) => {
57+
callback({ styles: newFormatWithEmptyCss });
58+
};
59+
mockChromeAPI(mockGet, mockSet);
60+
61+
const styles = await getMigratedStyles();
62+
expect(styles).toEqual(newFormatWithEmptyCss);
63+
expect(mockSet).toHaveBeenCalledTimes(0);
64+
});
65+
4666
it('backs up v2 styles to "backup_v2_styles"', async () => {
4767
const mockSet = jest.fn((_, callback) => callback());
4868
const mockGet = (_, callback) => {

src/background/migrate/migrate-old-format.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Style, StyleMap, StylebotOptions } from '@stylebot/types';
55
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
66
const isNewFormat = (styles: any) => {
77
const urls: Array<string> = Object.keys(styles);
8-
return !!urls.find(url => !!styles[url].css);
8+
return !!urls.find(url => styles[url].css !== undefined);
99
};
1010

1111
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
@@ -20,28 +20,28 @@ const backupV2Styles = (styles: any) => {
2020
export const getMigratedStyles = (): Promise<StyleMap> => {
2121
return new Promise(resolve => {
2222
chrome.storage.local.get('styles', async items => {
23-
const oldStyles = items['styles'];
23+
const styles = items['styles'];
2424

25-
if (!oldStyles) {
25+
if (!styles) {
2626
resolve({});
2727
return;
2828
}
2929

30-
// test to ensure styles are not already in the new format
31-
if (isNewFormat(oldStyles)) {
32-
resolve(oldStyles);
30+
// check if styles are in the new format
31+
if (isNewFormat(styles)) {
32+
resolve(styles);
3333
return;
3434
}
3535

3636
// backup old styles, in case we run into a bug
37-
await backupV2Styles(oldStyles);
37+
await backupV2Styles(styles);
3838

3939
const formatter = new LegacyCssFormatter();
40-
const urls: Array<string> = Object.keys(oldStyles);
40+
const urls: Array<string> = Object.keys(styles);
4141

4242
const results: Array<Promise<Style>> = urls.map(
4343
async (url): Promise<Style> => {
44-
const style = oldStyles[url];
44+
const style = styles[url];
4545

4646
return new Promise(resolveStyle => {
4747
try {
@@ -67,13 +67,13 @@ export const getMigratedStyles = (): Promise<StyleMap> => {
6767
);
6868

6969
Promise.all(results).then(formattedStyles => {
70-
const styles: StyleMap = {};
70+
const newStyles: StyleMap = {};
7171

7272
formattedStyles.forEach(({ url, css, enabled, readability }) => {
73-
styles[url] = { css, enabled, readability };
73+
newStyles[url] = { css, enabled, readability };
7474
});
7575

76-
resolve(styles);
76+
resolve(newStyles);
7777
});
7878
});
7979
});

src/editor/components/header/TheDeleteStyleDialog.vue

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export default Vue.extend({
5151
height: 100%;
5252
overflow: hidden;
5353
outline: 0;
54+
line-height: 24px;
5455
background: #000000b3;
5556
}
5657

src/extension/manifest.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"manifest_version": 2,
33
"name": "Stylebot",
4-
"version": "2.4.1",
5-
"description": "Change the appearance of websites instantly.",
4+
"version": "3",
5+
"description": "Change the appearance of the web instantly",
66

77
"background": {
88
"scripts": ["background/index.js"]

0 commit comments

Comments
 (0)