Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor and add Google Meet support #265

Merged
merged 18 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ browser.alarms.create('heartbeatAlarm', { periodInMinutes: 2 });
*/
browser.tabs.onActivated.addListener(async (activeInfo) => {
console.log('recording a heartbeat - active tab changed');
const html = await getHtmlContentByTabId(activeInfo.tabId);
let html = '';
try {
html = await getHtmlContentByTabId(activeInfo.tabId);
// eslint-disable-next-line no-empty
} catch (error: unknown) {}
await WakaTimeCore.recordHeartbeat(html);
});

Expand All @@ -43,7 +47,10 @@ browser.windows.onFocusChanged.addListener(async (windowId) => {
let html = '';
const tabId = tabs[0]?.id;
if (tabId) {
html = await getHtmlContentByTabId(tabId);
try {
html = await getHtmlContentByTabId(tabId);
// eslint-disable-next-line no-empty
} catch (error: unknown) {}
}
await WakaTimeCore.recordHeartbeat(html);
}
Expand All @@ -62,7 +69,11 @@ 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);
let html = '';
try {
html = await getHtmlContentByTabId(tabId);
// eslint-disable-next-line no-empty
} catch (error: unknown) {}
await WakaTimeCore.recordHeartbeat(html);
}
}
Expand All @@ -79,7 +90,11 @@ self.addEventListener('activate', async () => {
browser.runtime.onMessage.addListener(async (request: PostHeartbeatMessage, sender) => {
if (request.recordHeartbeat === true) {
if (sender.tab?.id) {
const html = await getHtmlContentByTabId(sender.tab.id);
let html = '';
try {
html = await getHtmlContentByTabId(sender.tab.id);
// eslint-disable-next-line no-empty
} catch (error: unknown) {}
await WakaTimeCore.recordHeartbeat(html, request.projectDetails);
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/utils/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ export const fetchUserData = async (
let html = '';
const tabId = tabs[0]?.id;
if (tabId) {
html = await getHtmlContentByTabId(tabId);
try {
html = await getHtmlContentByTabId(tabId);
// eslint-disable-next-line no-empty
} catch (error: unknown) {}
}

await WakaTimeCore.recordHeartbeat(html);
Expand Down
27 changes: 27 additions & 0 deletions src/wakatimeScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,25 @@ const parseFigma = (): DesignProject | undefined => {
};
};

const parseMeet = (): DesignProject | undefined => {
const meetId = document.querySelector('[data-meeting-title]')?.getAttribute('data-meeting-title');
if (!meetId) {
return;
}
return {
category: 'meeting',
editor: 'Meet',
language: 'Google Meet',
project: meetId,
};
};

const getParser: {
[key: string]:
| (() => { editor: string; language: string; project: string } | undefined)
| undefined;
} = {
'meet.google.com': parseMeet,
'www.canva.com': parseCanva,
'www.figma.com': parseFigma,
};
Expand Down Expand Up @@ -89,3 +103,16 @@ chrome.runtime.onMessage.addListener((request: { message: string }, sender, send
sendResponse({ html: document.documentElement.outerHTML });
}
});

// Google Meet
// https://meet.google.com/jzf-bwrz-djk
if (window.location.href.startsWith('https://meet.google.com/')) {
// In google meet website
// Check every two seconds if the user is in a meeting.
setInterval(() => {
alanhamlett marked this conversation as resolved.
Show resolved Hide resolved
const inMeeting = !!document.querySelector('[data-meeting-title]');
if (inMeeting) {
debounce(() => init());
}
}, 2000);
}
Loading