chore: implement new ts components
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import axios, { AxiosResponse } from 'axios';
|
||||
import moment from 'moment';
|
||||
import { Tabs } from 'webextension-polyfill-ts';
|
||||
import { User } from '../types/user';
|
||||
import { AxiosUserResponse, User } from '../types/user';
|
||||
import config from '../config/config';
|
||||
import { SummariesPayload, GrandTotal } from '../types/summaries';
|
||||
|
||||
@@ -10,15 +10,18 @@ class WakaTimeCore {
|
||||
constructor() {
|
||||
this.tabsWithDevtoolsOpen = [];
|
||||
}
|
||||
|
||||
setTabsWithDevtoolsOpen(tabs: Tabs.Tab[]): void {
|
||||
this.tabsWithDevtoolsOpen = tabs;
|
||||
}
|
||||
async getTotalTimeLoggedToday(): Promise<GrandTotal> {
|
||||
|
||||
async getTotalTimeLoggedToday(api_key = ''): Promise<GrandTotal> {
|
||||
const today = moment().format('YYYY-MM-DD');
|
||||
const summariesAxiosPayload: AxiosResponse<SummariesPayload> = await axios.get(
|
||||
config.summariesApiUrl,
|
||||
{
|
||||
data: {
|
||||
params: {
|
||||
api_key,
|
||||
end: today,
|
||||
start: today,
|
||||
},
|
||||
@@ -26,9 +29,23 @@ class WakaTimeCore {
|
||||
);
|
||||
return summariesAxiosPayload.data.data[0].grand_total;
|
||||
}
|
||||
async checkAuth(): Promise<User> {
|
||||
const userPayload: AxiosResponse<User> = await axios.get(config.currentUserApiUrl);
|
||||
return userPayload.data;
|
||||
|
||||
async checkAuth(api_key = ''): Promise<User> {
|
||||
console.log('api_keyapi_keyapi_keyapi_key', api_key);
|
||||
const userPayload: AxiosResponse<AxiosUserResponse> = await axios.get(
|
||||
config.currentUserApiUrl,
|
||||
{ params: { api_key } },
|
||||
);
|
||||
return userPayload.data.data;
|
||||
}
|
||||
|
||||
async recordHeartbeat(): Promise<void> {
|
||||
const items = await browser.storage.sync.get({
|
||||
blacklist: '',
|
||||
loggingEnabled: config.loggingEnabled,
|
||||
loggingStyle: config.loggingStyle,
|
||||
whitelist: '',
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user