-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added green github activity like color to the calendar
- Loading branch information
1 parent
402cd98
commit 0218611
Showing
20 changed files
with
325 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
/* eslint-disable no-unused-vars */ | ||
export enum DevHistoryChannels { | ||
GET_DAY = 'GET_DAY', | ||
GET_GIT_ACTIVITY_FOR_MONTH = 'GET_GIT_ACTIVITY_FOR_MONTH', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/electron/devHistory/channels/GitActivityForMonthChannelPub.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { InvokeChannelBasePub } from '../../IpcChannelTypes/InvokeChannelBasePub' | ||
import { DevHistoryChannels } from './DevHistoryChannelEnum' | ||
|
||
export class GitActivityForMonthChannelPub extends InvokeChannelBasePub { | ||
constructor() { | ||
super('GitActivityForMonth', DevHistoryChannels.GET_GIT_ACTIVITY_FOR_MONTH) | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/electron/devHistory/channels/GitActivityForMonthChannelSub.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { IpcMainEvent } from 'electron' | ||
import { IIpcMainInvokeEventSub } from '../../IpcChannelTypes/IIpcMainInvokeEventSub' | ||
import { GitActivityForMonthChannelPub } from './GitActivityForMonthChannelPub' | ||
import { | ||
GitActivityForMonthRequest, | ||
GitActivityForMonthResponse, | ||
} from './MessageTypes' | ||
import { gitActivityForMonth } from '../services/month-analyser' | ||
|
||
export class GitActivityForMonthChannelSub | ||
extends GitActivityForMonthChannelPub | ||
implements | ||
IIpcMainInvokeEventSub< | ||
GitActivityForMonthRequest, | ||
GitActivityForMonthResponse | ||
> | ||
{ | ||
async handle( | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
event: IpcMainEvent, | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
request: GitActivityForMonthRequest, | ||
): Promise<GitActivityForMonthResponse> { | ||
// read the list of entries from the chrome history sqlite database | ||
// return the list of entries | ||
const analysis = await gitActivityForMonth( | ||
request.startDate, | ||
request.endDate, | ||
) | ||
|
||
return { | ||
activity: analysis, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import path from 'path' | ||
import fs from 'fs' | ||
import fsp from 'fs/promises' | ||
import { app } from 'electron' | ||
|
||
export async function getFromCache( | ||
start: number, | ||
end: number, | ||
): Promise<Map<number, boolean> | undefined> { | ||
const cachePath = await getCachePath(start, end) | ||
|
||
if (!fs.existsSync(cachePath)) { | ||
console.log(`Cache file not found for ${start}-${end}`) | ||
return undefined | ||
} | ||
const fileUtf8 = await fsp.readFile(cachePath, { encoding: 'utf-8' }) | ||
|
||
const cache: [number, boolean][] = JSON.parse(fileUtf8) | ||
|
||
// Create a new map and populate it with the parsed key-value pairs | ||
const numberBooleanMap = new Map<number, boolean>(cache) | ||
|
||
return numberBooleanMap | ||
} | ||
|
||
export async function saveToCache( | ||
start: number, | ||
end: number, | ||
activity: Map<number, boolean>, | ||
): Promise<void> { | ||
const cachePath = await getCachePath(start, end) | ||
console.log('saving to cache', cachePath) | ||
if (!fs.existsSync(path.dirname(cachePath))) { | ||
await fsp.mkdir(path.dirname(cachePath), { recursive: true }) | ||
} | ||
const jsonString = JSON.stringify(Array.from(activity.entries())) | ||
|
||
await fsp.writeFile(cachePath, jsonString) | ||
} | ||
|
||
async function getCachePath(start: number, end: number): Promise<string> { | ||
const cachePath = path.join( | ||
app.getPath('userData'), | ||
'month-git-activity-cache', | ||
`${start}-${end}.json`, | ||
) | ||
return cachePath | ||
} |
Oops, something went wrong.