Skip to content

Commit

Permalink
add child count to lines
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyfallWasTaken committed Dec 26, 2024
1 parent 7b69de6 commit 1cb37b1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 6 additions & 5 deletions src/entrypoints/figma-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ export default defineUnlistedScript(async () => {

if (shouldSendHeartbeat()) {
log.debug("Sending heartbeat...");
log.debug(figma.root);
const entity = getEntity();
await m2iMessenger.sendMessage("emitHeartbeat", {
project: figma.root.name,
entity: getEntityName(),
entity: entity.name,
lines: "children" in entity ? entity.children.length : 0,
time: Math.floor(Date.now() / 1000),
type: "file",
language: "Figma",
Expand All @@ -77,12 +78,12 @@ export default defineUnlistedScript(async () => {
await figma.notify("WakaTime for Figma is running!");
});

function getEntityName(): string {
function getEntity() {
const currentSelection = figma.currentPage.selection;
if (currentSelection && currentSelection.length > 0) {
return currentSelection[0].name;
return currentSelection[0];
}
return figma.root.name;
return figma.root;
}

function shouldSendHeartbeat(): boolean {
Expand Down
4 changes: 3 additions & 1 deletion src/lib/wakatime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export interface PartialHeartbeat {
project: string;
language: string;
is_write: boolean;
lines?: number;
}

export default class WakaTime {
Expand All @@ -56,13 +57,14 @@ export default class WakaTime {
async trySendHeartbeats(partialHeartbeats: PartialHeartbeat[]) {
const heartbeats = partialHeartbeats.map((partialHeartbeat) => {
return {
lines: 1,

...partialHeartbeat,
editor: "Figma",
machine: `${getBrowser()} on ${getOS()}`,
operating_system: getOS(),
user_agent: USER_AGENT,

lines: 1,
line_additions: 0,
line_deletions: 0,
lineno: 1,
Expand Down

0 comments on commit 1cb37b1

Please sign in to comment.