Skip to content

Commit

Permalink
Merge pull request #265 from wakatime/feature/google-meet-support
Browse files Browse the repository at this point in the history
Feature/google meet support
  • Loading branch information
alanhamlett authored Aug 27, 2024
2 parents 83a50a8 + aa3743d commit 6403ca6
Show file tree
Hide file tree
Showing 31 changed files with 12,693 additions and 988 deletions.
54 changes: 44 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"react-redux": "^8.0.5",
"react-transition-group": "^4.4.5",
"redux-logger": "^4.0.0",
"uuid": "^10.0.0",
"webextension-polyfill": "^0.10.0"
},
"devDependencies": {
Expand All @@ -70,6 +71,7 @@
"@types/redux-logger": "^3.0.9",
"@types/shelljs": "^0.8.8",
"@types/sinon-chrome": "^2.2.11",
"@types/uuid": "^10.0.0",
"@types/wait-on": "^5.2.0",
"@types/webextension-polyfill": "^0.10.0",
"@typescript-eslint/eslint-plugin": "^4.33.0",
Expand Down
26 changes: 8 additions & 18 deletions src/background.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import browser from 'webextension-polyfill';
import WakaTimeCore from './core/WakaTimeCore';
import { PostHeartbeatMessage } from './types/heartbeats';
import { getHtmlContentByTabId } from './utils';

// Add a listener to resolve alarms
browser.alarms.onAlarm.addListener(async (alarm) => {
Expand All @@ -12,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 @@ -24,28 +22,23 @@ browser.alarms.create('heartbeatAlarm', { periodInMinutes: 2 });
* Whenever a active tab is changed it records a heartbeat with that tab url.
*/
browser.tabs.onActivated.addListener(async (activeInfo) => {
console.log('recording a heartbeat - active tab changed');
const html = await getHtmlContentByTabId(activeInfo.tabId);
await WakaTimeCore.recordHeartbeat(html);
await WakaTimeCore.handleActivity(activeInfo.tabId);
});

/**
* Whenever a active window is changed it records a heartbeat with the active tab url.
*/
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,
});

let html = '';
const tabId = tabs[0]?.id;
if (tabId) {
html = await getHtmlContentByTabId(tabId);
await WakaTimeCore.handleActivity(tabId);
}
await WakaTimeCore.recordHeartbeat(html);
}
});

Expand All @@ -62,8 +55,7 @@ browser.tabs.onUpdated.addListener(async (tabId, changeInfo) => {
});
// If tab updated is the same as active tab
if (tabId == tabs[0]?.id) {
const html = await getHtmlContentByTabId(tabId);
await WakaTimeCore.recordHeartbeat(html);
await WakaTimeCore.handleActivity(tabs[0].id);
}
}
});
Expand All @@ -76,12 +68,10 @@ self.addEventListener('activate', async () => {
await WakaTimeCore.createDB();
});

browser.runtime.onMessage.addListener(async (request: PostHeartbeatMessage, sender) => {
if (request.recordHeartbeat === true) {
if (sender.tab?.id) {
const html = await getHtmlContentByTabId(sender.tab.id);
await WakaTimeCore.recordHeartbeat(html, request.projectDetails);
}
browser.runtime.onMessage.addListener(async (request: { task: string }, sender) => {
if (request.task === 'handleActivity') {
if (!sender.tab?.id) return;
await WakaTimeCore.handleActivity(sender.tab.id);
}
});

Expand Down
4 changes: 2 additions & 2 deletions src/components/MainList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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/changeExtensionState';
import changeExtensionState from '../utils/changeExtensionStatus';

export interface MainListProps {
loggingEnabled: boolean;
Expand Down Expand Up @@ -40,7 +40,7 @@ export default function MainList({
const disableLogging = async (): Promise<void> => {
dispatch(setLoggingEnabled(false));
await browser.storage.sync.set({ loggingEnabled: false });
await changeExtensionState('notLogging');
await changeExtensionState('trackingDisabled');
};

return (
Expand Down
Loading

0 comments on commit 6403ca6

Please sign in to comment.