Skip to content

Commit

Permalink
Merge branch 'master' into firefox-api-permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
ouuan authored Dec 25, 2024
2 parents a934f2c + a1828f4 commit b0eab4d
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 37 deletions.
5 changes: 3 additions & 2 deletions src/components/MainList.tsx
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
6 changes: 4 additions & 2 deletions src/components/NavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ export default function NavBar(): JSX.Element {

const customRules = () => {
if (user) {
const url = 'https://wakatime.com';
return (
<li className="mb-2">
<a
target="_blank"
href="https://wakatime.com/settings/rules"
href={`${url}/settings/rules`}
rel="noreferrer"
className="text-body-secondary link-underline link-underline-opacity-0 d-flex w-100 align-items-center"
>
Expand All @@ -42,11 +43,12 @@ export default function NavBar(): JSX.Element {

const dashboard = () => {
if (user) {
const url = 'https://wakatime.com';
return (
<li className="mb-2">
<a
target="_blank"
href="https://wakatime.com/dashboard"
href={url}
rel="noreferrer"
className="text-body-secondary link-underline link-underline-opacity-0 d-flex w-100 align-items-center"
>
Expand Down
20 changes: 10 additions & 10 deletions src/core/WakaTimeCore.ts
Original file line number Diff line number Diff line change
@@ -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 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';
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';
/* eslint-disable no-fallthrough */
/* eslint-disable default-case */

class WakaTimeCore {
tabsWithDevtoolsOpen: Tabs.Tab[];
Expand Down Expand Up @@ -185,7 +185,7 @@ class WakaTimeCore {
const request: RequestInit = {
body: JSON.stringify(
heartbeats.map((heartbeat) => {
return { ...heartbeat, userAgent };
return { ...heartbeat, plugin: userAgent };
}),
),
credentials: 'omit',
Expand Down
2 changes: 1 addition & 1 deletion src/manifests/chrome.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@
"page": "options.html"
},
"permissions": ["alarms", "tabs", "storage", "activeTab"],
"version": "4.0.9"
"version": "4.0.12"
}
2 changes: 1 addition & 1 deletion src/manifests/edge.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@
"page": "options.html"
},
"permissions": ["alarms", "tabs", "storage", "activeTab"],
"version": "4.0.9"
"version": "4.0.12"
}
2 changes: 1 addition & 1 deletion src/manifests/firefox.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@
},
"permissions": ["alarms", "tabs", "storage", "activeTab", "https://api.wakatime.com/*", "https://wakatime.com/*"],
"optional_permissions": ["<all_urls>"],
"version": "4.0.9"
"version": "4.0.12"
}
5 changes: 3 additions & 2 deletions src/reducers/currentUser.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
18 changes: 18 additions & 0 deletions src/utils/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,21 @@ export const saveSettings = async (settings: Settings): Promise<void> => {
});
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.', '://');
};
23 changes: 5 additions & 18 deletions src/utils/user.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down

0 comments on commit b0eab4d

Please sign in to comment.