Skip to content

Commit

Permalink
Merge branch 'master' into sebas-update-bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
jvelezpo authored Jan 10, 2024
2 parents 1a82bd0 + ca79adc commit 7490398
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 20 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ Note: Activity from this Chrome extension will not display on leaderboards, so i

1. Install the extension:

[![Chrome Web Store](https://wakatime.com/static/img/chrome-web-store.png)](https://chrome.google.com/webstore/detail/wakatime/jnbbnacmeggbgdjgaoojpmhdlkkpblgi)
[![Chrome](https://wakatime.com/static/img/chrome-web-store.png)](https://chrome.google.com/webstore/detail/wakatime/jnbbnacmeggbgdjgaoojpmhdlkkpblgi)

[![Firefox](https://wakatime.com/static/img/firefox-addon.png)](https://addons.mozilla.org/en-US/firefox/addon/wakatime/)

[![Edge](https://wakatime.com/static/img/microsoft-extension.png)](https://microsoftedge.microsoft.com/addons/detail/wakatime/cdnpfnaadjmaplhghnlonephmabegadl)

2. Login to [WakaTime](https://wakatime.com/).

Expand Down
9 changes: 8 additions & 1 deletion src/background.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import browser from 'webextension-polyfill';
import WakaTimeCore from './core/WakaTimeCore';
import { PostHeartbeatMessage } from './types/heartbeats';

// Add a listener to resolve alarms
browser.alarms.onAlarm.addListener(async (alarm) => {
Expand All @@ -22,7 +23,7 @@ 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 () => {
console.log('recording a heartbeat - active tab changed ');
console.log('recording a heartbeat - active tab changed');
await WakaTimeCore.recordHeartbeat();
});

Expand Down Expand Up @@ -62,6 +63,12 @@ self.addEventListener('activate', async () => {
await WakaTimeCore.createDB();
});

browser.runtime.onMessage.addListener(async (request: PostHeartbeatMessage) => {
if (request.recordHeartbeat === true) {
await WakaTimeCore.recordHeartbeat(request.projectDetails);
}
});

/**
* "Persistent" service worker via bug exploit
* https://stackoverflow.com/questions/66618136/persistent-service-worker-in-chrome-extension
Expand Down
4 changes: 2 additions & 2 deletions src/components/Options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,9 @@ export default function Options(): JSX.Element {
className="form-control"
value={state.apiUrl}
onChange={(e) => setState({ ...state, apiUrl: e.target.value })}
placeholder="https://wakatime.com/api/v1"
placeholder="https://api.wakatime.com/api/v1"
/>
<span className="help-block">https://wakatime.com/api/v1</span>
<span className="help-block">https://api.wakatime.com/api/v1</span>
</div>
</div>

Expand Down
2 changes: 1 addition & 1 deletion src/config/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('wakatime config', () => {
},
},
"apiKey": "",
"apiUrl": "https://wakatime.com/api/v1",
"apiUrl": "https://api.wakatime.com/api/v1",
"colors": {
"allGood": "",
"lightTheme": "white",
Expand Down
2 changes: 1 addition & 1 deletion src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ const config: Config = {

apiKey: '',

apiUrl: process.env.API_URL ?? 'https://wakatime.com/api/v1',
apiUrl: process.env.API_URL ?? 'https://api.wakatime.com/api/v1',

colors: {
allGood: '',
Expand Down
1 change: 1 addition & 0 deletions src/core/WakaTimeCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ class WakaTimeCore {
};

payload.project = heartbeat.project ?? '<<LAST_PROJECT>>';
payload.branch = heartbeat.branch ?? '<<LAST_BRANCH>>';

return payload;
}
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", "idle"],
"version": "3.0.17"
"version": "3.0.21"
}
37 changes: 37 additions & 0 deletions src/manifests/edge.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"action": {
"default_icon": {
"19": "graphics/wakatime-logo-19.png",
"38": "graphics/wakatime-logo-38.png"
},
"default_popup": "popup.html",
"default_title": "WakaTime"
},
"background": {
"service_worker": "background.js",
"type": "module"
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["wakatimeScript.js"],
"run_at": "document_end"
}
],
"description": "Automatic time tracking for Edge.",
"devtools_page": "devtools.html",
"homepage_url": "https://wakatime.com",
"host_permissions": ["https://api.wakatime.com/*", "https://wakatime.com/*"],
"icons": {
"16": "graphics/wakatime-logo-16.png",
"48": "graphics/wakatime-logo-48.png",
"128": "graphics/wakatime-logo-128.png"
},
"manifest_version": 3,
"name": "WakaTime",
"options_ui": {
"page": "options.html"
},
"permissions": ["alarms", "tabs", "storage", "idle"],
"version": "3.0.21"
}
2 changes: 1 addition & 1 deletion src/manifests/firefox.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@
"page": "options.html"
},
"permissions": ["<all_urls>", "alarms", "tabs", "storage", "idle"],
"version": "3.0.17"
"version": "3.0.21"
}
13 changes: 13 additions & 0 deletions src/types/heartbeats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,20 @@ export interface Datum {
}

export interface SendHeartbeat {
branch: string | null;
hostname: string;
project: string | null;
url: string;
}

export interface ProjectDetails {
category: string;
editor: string;
language: string;
project: string;
}

export interface PostHeartbeatMessage {
projectDetails?: ProjectDetails;
recordHeartbeat: boolean;
}
3 changes: 2 additions & 1 deletion src/types/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ export interface User {
is_hireable: boolean;
is_onboarding_finished: boolean;
languages_used_public: boolean;
last_branch?: string;
last_heartbeat_at: string;
last_plugin: string;
last_plugin_name: string;
last_project: string;
last_project?: string;
location: string;
logged_time_public: boolean;
modified_at: string;
Expand Down
20 changes: 11 additions & 9 deletions src/wakatimeScript.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import WakaTimeCore from './core/WakaTimeCore';

const twoMinutes = 120000;

interface DesignProject {
Expand All @@ -10,13 +8,18 @@ interface DesignProject {
}

const parseCanva = (): DesignProject | undefined => {
const canvaProject = document.getElementsByClassName('rF765A');
if (canvaProject.length === 0) return;

const projectName = (document.head.querySelector('meta[property="og:title"]') as HTMLMetaElement)
.content;
if (!projectName) return;

// make sure the page title matches the design input element's value, meaning this is a design file
const canvaProjectInput = Array.from(
document.querySelector('nav')?.querySelectorAll('input') ?? [],
).find((inp) => inp.value === projectName);
if (!canvaProjectInput) return;

return {
category: 'Designing',
category: 'designing',
editor: 'Canva',
language: 'Canva Design',
project: projectName,
Expand All @@ -30,7 +33,7 @@ const parseFigma = (): DesignProject | undefined => {
const projectName = (document.querySelector('span[data-testid="filename"]') as HTMLElement)
.innerText;
return {
category: 'Designing',
category: 'designing',
editor: 'Figma',
language: 'Figma Design',
project: projectName,
Expand All @@ -50,9 +53,8 @@ const init = async () => {
const { hostname } = document.location;

const projectDetails = getParser[hostname]?.();

if (projectDetails) {
await WakaTimeCore.recordHeartbeat(projectDetails);
chrome.runtime.sendMessage({ projectDetails, recordHeartbeat: true });
}
};

Expand Down
8 changes: 6 additions & 2 deletions webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as webpack from 'webpack';
// eslint-disable-next-line
import CopyPlugin from 'copy-webpack-plugin';

type BrowserTypes = 'chrome' | 'firefox';
type BrowserTypes = 'chrome' | 'firefox' | 'edge';

const publicFolder = join(__dirname, 'public');
const cssFolder = join(publicFolder, 'css');
Expand Down Expand Up @@ -75,5 +75,9 @@ export default (
arv: Record<string, string>,
): webpack.Configuration[] => {
const isProd = arv.mode !== 'development';
return [getConfigByBrowser(isProd, 'chrome'), getConfigByBrowser(isProd, 'firefox')];
return [
getConfigByBrowser(isProd, 'chrome'),
getConfigByBrowser(isProd, 'firefox'),
getConfigByBrowser(isProd, 'edge'),
];
};

0 comments on commit 7490398

Please sign in to comment.