Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate hostname in settings from sync storage into local storage #297

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/core/WakaTimeCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,21 @@ class WakaTimeCore {
}

async sendHeartbeats(): Promise<void> {
const settings = await browser.storage.sync.get({
apiKey: config.apiKey,
heartbeatApiEndPoint: config.heartbeatApiEndPoint,
hostname: '',
});
const [syncSettings, localSettings] = await Promise.all([
browser.storage.sync.get({
apiKey: config.apiKey,
heartbeatApiEndPoint: config.heartbeatApiEndPoint,
}) as Promise<{ apiKey: string; heartbeatApiEndPoint: string }>,
browser.storage.local.get({
hostname: '',
}) as Promise<{ hostname: string }>,
]);

const settings = {
...syncSettings,
hostname: localSettings.hostname,
};

if (!settings.apiKey) {
await changeExtensionStatus('notSignedIn');
return;
Expand Down
47 changes: 30 additions & 17 deletions src/utils/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,31 @@ export interface Settings {
}

export const getSettings = async (): Promise<Settings> => {
const settings = (await browser.storage.sync.get({
allowList: [],
apiKey: config.apiKey,
apiUrl: config.apiUrl,
blacklist: null,
customProjectNames: [],
denyList: [],
hostname: config.hostname,
loggingEnabled: config.loggingEnabled,
loggingStyle: config.loggingStyle,
loggingType: config.loggingType,
socialMediaSites: config.socialMediaSites,
theme: config.theme,
trackSocialMedia: true,
whitelist: null,
})) as Omit<Settings, 'socialMediaSites'> & {
const [syncSettings, localSettings] = await Promise.all([
browser.storage.sync.get({
allowList: [],
apiKey: config.apiKey,
apiUrl: config.apiUrl,
blacklist: null,
customProjectNames: [],
denyList: [],
loggingEnabled: config.loggingEnabled,
loggingStyle: config.loggingStyle,
loggingType: config.loggingType,
socialMediaSites: config.socialMediaSites,
theme: config.theme,
trackSocialMedia: true,
whitelist: null,
}),
browser.storage.local.get({
hostname: config.hostname,
}),
]);

const settings = {
...syncSettings,
hostname: localSettings.hostname,
} as Omit<Settings, 'socialMediaSites'> & {
blacklist?: string;
socialMediaSites: string[] | string;
whitelist?: string;
Expand Down Expand Up @@ -81,7 +90,11 @@ export const getSettings = async (): Promise<Settings> => {
};

export const saveSettings = async (settings: Settings): Promise<void> => {
return browser.storage.sync.set(settings);
const { hostname, ...syncSettings } = settings;
await Promise.all([
browser.storage.sync.set(syncSettings),
browser.storage.local.set({ hostname }),
]);
};

export const getApiUrl = async () => {
Expand Down