diff --git a/src/components/MainList.tsx b/src/components/MainList.tsx index 3a84e60..8803105 100644 --- a/src/components/MainList.tsx +++ b/src/components/MainList.tsx @@ -1,11 +1,12 @@ +import React from 'react'; + import { useDispatch, useSelector } from 'react-redux'; -import React from 'react'; import { configLogout, setLoggingEnabled } from '../reducers/configReducer'; -import { userLogout } from '../reducers/currentUser'; import { ReduxSelector } from '../types/store'; import { User } from '../types/user'; import changeExtensionState from '../utils/changeExtensionStatus'; +import { userLogout } from '../reducers/currentUser'; export interface MainListProps { loggingEnabled: boolean; diff --git a/src/components/NavBar.tsx b/src/components/NavBar.tsx index 05d1f88..dfc46b4 100644 --- a/src/components/NavBar.tsx +++ b/src/components/NavBar.tsx @@ -22,11 +22,12 @@ export default function NavBar(): JSX.Element { const customRules = () => { if (user) { + const url = 'https://wakatime.com'; return (
  • @@ -42,11 +43,12 @@ export default function NavBar(): JSX.Element { const dashboard = () => { if (user) { + const url = 'https://wakatime.com'; return (
  • diff --git a/src/core/WakaTimeCore.ts b/src/core/WakaTimeCore.ts index af8cddc..a3cb97f 100644 --- a/src/core/WakaTimeCore.ts +++ b/src/core/WakaTimeCore.ts @@ -1,18 +1,18 @@ -import { openDB } from 'idb'; import browser, { Tabs } from 'webextension-polyfill'; -/* eslint-disable no-fallthrough */ -/* eslint-disable default-case */ +import { openDB } from 'idb'; import moment from 'moment'; import { v4 as uuid4 } from 'uuid'; -import { OptionalHeartbeat } from '../types/sites'; -import { changeExtensionStatus } from '../utils/changeExtensionStatus'; -import getDomainFromUrl, { getDomain } from '../utils/getDomainFromUrl'; -import { getOperatingSystem, IS_EDGE, IS_FIREFOX } from '../utils/operatingSystem'; -import { getSettings, Settings } from '../utils/settings'; -import { getApiUrl } from '../utils/user'; - import config, { ExtensionStatus } from '../config/config'; import { EntityType, Heartbeat, HeartbeatsBulkResponse } from '../types/heartbeats'; +import getDomainFromUrl, { getDomain } from '../utils/getDomainFromUrl'; +import { IS_EDGE, IS_FIREFOX, getOperatingSystem } from '../utils/operatingSystem'; +import { Settings, getApiUrl, getSettings } from '../utils/settings'; + +import { OptionalHeartbeat } from '../types/sites'; +import { changeExtensionStatus } from '../utils/changeExtensionStatus'; + +/* eslint-disable no-fallthrough */ +/* eslint-disable default-case */ class WakaTimeCore { tabsWithDevtoolsOpen: Tabs.Tab[]; @@ -185,7 +185,7 @@ class WakaTimeCore { const request: RequestInit = { body: JSON.stringify( heartbeats.map((heartbeat) => { - return { ...heartbeat, userAgent }; + return { ...heartbeat, plugin: userAgent }; }), ), credentials: 'omit', diff --git a/src/manifests/chrome.json b/src/manifests/chrome.json index d3a34bc..87da597 100644 --- a/src/manifests/chrome.json +++ b/src/manifests/chrome.json @@ -33,5 +33,5 @@ "page": "options.html" }, "permissions": ["alarms", "tabs", "storage", "activeTab"], - "version": "4.0.9" + "version": "4.0.12" } diff --git a/src/manifests/edge.json b/src/manifests/edge.json index 9e6e782..c1ed9a2 100644 --- a/src/manifests/edge.json +++ b/src/manifests/edge.json @@ -33,5 +33,5 @@ "page": "options.html" }, "permissions": ["alarms", "tabs", "storage", "activeTab"], - "version": "4.0.9" + "version": "4.0.12" } diff --git a/src/manifests/firefox.json b/src/manifests/firefox.json index 40db0e9..f5b134a 100644 --- a/src/manifests/firefox.json +++ b/src/manifests/firefox.json @@ -40,5 +40,5 @@ }, "permissions": ["alarms", "tabs", "storage", "activeTab", "https://api.wakatime.com/*", "https://wakatime.com/*"], "optional_permissions": [""], - "version": "4.0.9" + "version": "4.0.12" } diff --git a/src/reducers/currentUser.ts b/src/reducers/currentUser.ts index de3072d..0e19e23 100644 --- a/src/reducers/currentUser.ts +++ b/src/reducers/currentUser.ts @@ -1,9 +1,10 @@ import { createAsyncThunk, createSlice } from '@reduxjs/toolkit'; import axios, { AxiosResponse } from 'axios'; import browser from 'webextension-polyfill'; -import config from '../config/config'; import { CurrentUser, User, UserPayload } from '../types/user'; -import { getApiUrl } from '../utils/user'; + +import config from '../config/config'; +import { getApiUrl } from '../utils/settings'; interface setUserAction { payload: User | undefined; diff --git a/src/utils/settings.ts b/src/utils/settings.ts index dffb9f0..2b96ab9 100644 --- a/src/utils/settings.ts +++ b/src/utils/settings.ts @@ -88,3 +88,21 @@ export const saveSettings = async (settings: Settings): Promise => { }); await browser.storage.sync.set(settings); }; + +export const getApiUrl = async () => { + const settings = await browser.storage.sync.get({ + apiUrl: config.apiUrl, + }); + let apiUrl = (settings.apiUrl as string) || config.apiUrl; + const suffixes = ['/', '.bulk', '/users/current/heartbeats', '/heartbeats', '/heartbeat']; + for (const suffix of suffixes) { + if (apiUrl.endsWith(suffix)) { + apiUrl = apiUrl.slice(0, -suffix.length); + } + } + return apiUrl; +}; + +export const getWebsiteUrl = async () => { + return (await getApiUrl()).replace('/api/v1', '').replace('://api.', '://'); +}; diff --git a/src/utils/user.ts b/src/utils/user.ts index 0212cdb..af16789 100644 --- a/src/utils/user.ts +++ b/src/utils/user.ts @@ -1,28 +1,15 @@ import { AnyAction, Dispatch } from '@reduxjs/toolkit'; import axios, { AxiosResponse } from 'axios'; -import browser from 'webextension-polyfill'; - import moment from 'moment'; -import config from '../config/config'; +import browser from 'webextension-polyfill'; import { setApiKey, setLoggingEnabled, setTotalTimeLoggedToday } from '../reducers/configReducer'; -import { setUser } from '../reducers/currentUser'; import { GrandTotal, Summaries } from '../types/summaries'; import { ApiKeyPayload, AxiosUserResponse, User } from '../types/user'; -import changeExtensionState from './changeExtensionStatus'; -export const getApiUrl = async () => { - const settings = await browser.storage.sync.get({ - apiUrl: config.apiUrl, - }); - let apiUrl = (settings.apiUrl as string) || config.apiUrl; - const suffixes = ['/', '.bulk', '/users/current/heartbeats', '/heartbeats', '/heartbeat']; - for (const suffix of suffixes) { - if (apiUrl.endsWith(suffix)) { - apiUrl = apiUrl.slice(0, -suffix.length); - } - } - return apiUrl; -}; +import config from '../config/config'; +import { setUser } from '../reducers/currentUser'; +import changeExtensionState from './changeExtensionStatus'; +import { getApiUrl } from './settings'; /** * Checks if the user is logged in.