Skip to content

Commit

Permalink
finish refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
alanhamlett committed Aug 27, 2024
1 parent 4d08aeb commit b84be60
Show file tree
Hide file tree
Showing 10 changed files with 329 additions and 303 deletions.
3 changes: 1 addition & 2 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ browser.alarms.onAlarm.addListener(async (alarm) => {
// Checks if the user is online and if there are cached heartbeats requests,
// if so then procedd to send these payload to wakatime api
if (navigator.onLine) {
await WakaTimeCore.sendCachedHeartbeatsRequest();
await WakaTimeCore.sendHeartbeats();
}
}
});
Expand All @@ -30,7 +30,6 @@ browser.tabs.onActivated.addListener(async (activeInfo) => {
*/
browser.windows.onFocusChanged.addListener(async (windowId) => {
if (windowId != browser.windows.WINDOW_ID_NONE) {
console.log('recording a heartbeat - active window changed');
const tabs: browser.Tabs.Tab[] = await browser.tabs.query({
active: true,
currentWindow: true,
Expand Down
2 changes: 1 addition & 1 deletion src/components/Options.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect, useRef, useState } from 'react';
import config, { SuccessOrFailType } from '../config/config';
import { IS_CHROME } from '../utils';
import apiKeyInvalid from '../utils/apiKey';
import { IS_CHROME } from '../utils/operatingSystem';
import { getSettings, saveSettings, Settings } from '../utils/settings';
import { logUserIn } from '../utils/user';
import SitesList from './SitesList';
Expand Down
3 changes: 2 additions & 1 deletion src/core/WakaTimeCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import browser, { Tabs } from 'webextension-polyfill';
import moment from 'moment';
import { v4 as uuid4 } from 'uuid';
import { OptionalHeartbeat } from '../types/sites';
import { getOperatingSystem, IS_EDGE, IS_FIREFOX } from '../utils';
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 config, { ExtensionStatus } from '../config/config';
Expand Down Expand Up @@ -149,6 +149,7 @@ class WakaTimeCore {
entity: heartbeat?.entity ?? entity,
id: uuid4(),
language: heartbeat?.language,
plugin: heartbeat?.plugin,
project: heartbeat?.project ?? '<<LAST_PROJECT>>',
time: this.getCurrentTime(),
type: heartbeat?.entityType ?? (settings.loggingType as EntityType),
Expand Down
1 change: 1 addition & 0 deletions src/types/heartbeats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export enum Category {
browsing = 'browsing',
code_reviewing = 'code reviewing',
coding = 'coding',
communicating = 'communicating',
debugging = 'debugging',
designing = 'designing',
meeting = 'meeting',
Expand Down
1 change: 1 addition & 0 deletions src/types/sites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface OptionalHeartbeat {
entity?: string;
entityType?: EntityType;
language?: string | null;
plugin?: string;
project?: string | null;
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils/changeExtensionStatus.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import browser from 'webextension-polyfill';
import config, { ExtensionStatus } from '../config/config';
import { IS_FIREFOX } from '.';
import { IS_FIREFOX } from './operatingSystem';

type ColorIconTypes = 'gray' | 'red' | 'white' | '';

Expand Down
232 changes: 0 additions & 232 deletions src/utils/heartbeat.ts

This file was deleted.

11 changes: 0 additions & 11 deletions src/utils/index.ts → src/utils/operatingSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,6 @@ export const IS_EDGE = navigator.userAgent.includes('Edg');
export const IS_FIREFOX = navigator.userAgent.includes('Firefox');
export const IS_CHROME = IS_EDGE === false && IS_FIREFOX === false;

const CODE_REVIEW_URL_REG_LIST = [/github.com\/[^/]+\/[^/]+\/pull\/\d+\/files/];

export const isCodeReviewing = (url: string): boolean => {
for (const reg of CODE_REVIEW_URL_REG_LIST) {
if (url.match(reg)) {
return true;
}
}
return false;
};

export const getOperatingSystem = (): Promise<string> => {
return new Promise((resolve) => {
chrome.runtime.getPlatformInfo(function (info) {
Expand Down
Loading

0 comments on commit b84be60

Please sign in to comment.