Skip to content

Commit 33d1146

Browse files
committed
refactor: Separate hostname in settings from sync storage into local storage;
- Modify the way settings are retrieved from sync and local storages. - Make sure the hostname doesn't get in the sync storage but in the local storage.
1 parent a1828f4 commit 33d1146

2 files changed

Lines changed: 45 additions & 22 deletions

File tree

src/core/WakaTimeCore.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,21 @@ class WakaTimeCore {
165165
}
166166

167167
async sendHeartbeats(): Promise<void> {
168-
const settings = await browser.storage.sync.get({
169-
apiKey: config.apiKey,
170-
heartbeatApiEndPoint: config.heartbeatApiEndPoint,
171-
hostname: '',
172-
});
168+
const [syncSettings, localSettings] = await Promise.all([
169+
browser.storage.sync.get({
170+
apiKey: config.apiKey,
171+
heartbeatApiEndPoint: config.heartbeatApiEndPoint,
172+
}) as Promise<{ apiKey: string; heartbeatApiEndPoint: string }>,
173+
browser.storage.local.get({
174+
hostname: '',
175+
}) as Promise<{ hostname: string }>,
176+
]);
177+
178+
const settings = {
179+
...syncSettings,
180+
hostname: localSettings.hostname,
181+
};
182+
173183
if (!settings.apiKey) {
174184
await changeExtensionStatus('notSignedIn');
175185
return;

src/utils/settings.ts

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,31 @@ export interface Settings {
2323
}
2424

2525
export const getSettings = async (): Promise<Settings> => {
26-
const settings = (await browser.storage.sync.get({
27-
allowList: [],
28-
apiKey: config.apiKey,
29-
apiUrl: config.apiUrl,
30-
blacklist: null,
31-
customProjectNames: [],
32-
denyList: [],
33-
hostname: config.hostname,
34-
loggingEnabled: config.loggingEnabled,
35-
loggingStyle: config.loggingStyle,
36-
loggingType: config.loggingType,
37-
socialMediaSites: config.socialMediaSites,
38-
theme: config.theme,
39-
trackSocialMedia: true,
40-
whitelist: null,
41-
})) as Omit<Settings, 'socialMediaSites'> & {
26+
const [syncSettings, localSettings] = await Promise.all([
27+
browser.storage.sync.get({
28+
allowList: [],
29+
apiKey: config.apiKey,
30+
apiUrl: config.apiUrl,
31+
blacklist: null,
32+
customProjectNames: [],
33+
denyList: [],
34+
loggingEnabled: config.loggingEnabled,
35+
loggingStyle: config.loggingStyle,
36+
loggingType: config.loggingType,
37+
socialMediaSites: config.socialMediaSites,
38+
theme: config.theme,
39+
trackSocialMedia: true,
40+
whitelist: null,
41+
}),
42+
browser.storage.local.get({
43+
hostname: config.hostname,
44+
}),
45+
]);
46+
47+
const settings = {
48+
...syncSettings,
49+
hostname: localSettings.hostname,
50+
} as Omit<Settings, 'socialMediaSites'> & {
4251
blacklist?: string;
4352
socialMediaSites: string[] | string;
4453
whitelist?: string;
@@ -81,7 +90,11 @@ export const getSettings = async (): Promise<Settings> => {
8190
};
8291

8392
export const saveSettings = async (settings: Settings): Promise<void> => {
84-
return browser.storage.sync.set(settings);
93+
const { hostname, ...syncSettings } = settings;
94+
await Promise.all([
95+
browser.storage.sync.set(syncSettings),
96+
browser.storage.local.set({ hostname }),
97+
]);
8598
};
8699

87100
export const getApiUrl = async () => {

0 commit comments

Comments
 (0)