Skip to content

Commit

Permalink
handle end of day notification updates (#464)
Browse files Browse the repository at this point in the history
* handle end of day notification updates

* add preferences_update ws case
  • Loading branch information
xavluiz authored Oct 6, 2023
1 parent c33f65a commit 4ef3ed0
Show file tree
Hide file tree
Showing 9 changed files with 257 additions and 51 deletions.
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "swdc-vscode",
"displayName": "Code Time",
"version": "2.7.0",
"version": "2.7.1",
"publisher": "softwaredotcom",
"description": "Code Time is an open source plugin that provides programming metrics right in Visual Studio Code.",
"author": {
Expand Down Expand Up @@ -141,14 +141,14 @@
},
"dependencies": {
"@swdotcom/editor-flow": "1.1.1",
"@types/uuid": "^8.3.4",
"@types/ws": "^8.5.3",
"axios": "^1.3.2",
"date-fns": "^2.29.3",
"@types/uuid": "^9.0.4",
"@types/ws": "^8.5.6",
"axios": "^1.5.1",
"date-fns": "^2.30.0",
"node-cache": "^5.1.2",
"open": "^8.4.0",
"open": "^9.1.0",
"swdc-tracker": "1.5.5",
"uuid": "^9.0.0",
"ws": "^8.11.0"
"uuid": "^9.0.1",
"ws": "^8.14.2"
}
}
8 changes: 0 additions & 8 deletions src/events/userEventEmitter.ts

This file was deleted.

6 changes: 6 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {initializeFlowModeState} from './managers/FlowManager';
import { ExtensionManager } from './managers/ExtensionManager';
import { LocalStorageManager } from './managers/LocalStorageManager';
import { setSessionStorageManager } from './managers/FileManager';
import { setEndOfDayNotification } from './notifications/endOfDay';

let TELEMETRY_ON = true;
let currentColorKind: number | undefined = undefined;
Expand Down Expand Up @@ -140,6 +141,11 @@ export async function intializePlugin() {
// INIT session summary sync manager
SyncManager.getInstance();
}, 3000);

setTimeout(() => {
// Set the end of the day notification trigger if it's enabled
setEndOfDayNotification();
}, 5000);
}

export function getCurrentColorKind() {
Expand Down
3 changes: 3 additions & 0 deletions src/managers/ConfigManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {commands, ViewColumn, WebviewPanel, window} from 'vscode';
import {getUser} from '../DataController';
import {isResponseOk, appGet, appPut} from '../http/HttpClient';
import {getConnectionErrorHtml} from '../local/404';
import { setEndOfDayNotification } from '../notifications/endOfDay';

let currentPanel: WebviewPanel | undefined = undefined;

Expand Down Expand Up @@ -61,6 +62,8 @@ export async function getEditSettingsHtml(): Promise<string> {
export async function updateSettings(path: string, jsonData: any, reloadSettings: false) {
await appPut(path, jsonData);
await getUser();
// update the end of the day notification trigger
setEndOfDayNotification();
// update the sidebar
commands.executeCommand('codetime.refreshCodeTimeView');

Expand Down
4 changes: 1 addition & 3 deletions src/notifications/endOfDay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ export const setEndOfDayNotification = async () => {
const workHours: any = JSON.parse(cachedUser.profile.work_hours)

// If the end of day notification setting is turned on (if undefined or null, will default to true)
if (preferences.notifications?.endOfDayNotification !== false) {
const jwt = getItem('jwt');

if (preferences.notifications?.endOfDayNotification) {
const d = new Date();
const day = format(d, 'EEE').toLowerCase();
let msUntilEndOfTheDay = 0;
Expand Down
4 changes: 4 additions & 0 deletions src/websockets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { handleIntegrationConnectionSocketEvent } from './message_handlers/integ
import { handleCurrentDayStatsUpdate } from './message_handlers/current_day_stats_update';
import { handleFlowStateMessage } from './message_handlers/flow_state';
import { userDeletedCompletionHandler } from './DataController';
import { setEndOfDayNotification } from './notifications/endOfDay';

const WebSocket = require('ws');

Expand Down Expand Up @@ -238,6 +239,9 @@ const handleIncomingMessage = (data: any) => {
case 'account_deleted':
userDeletedCompletionHandler();
break;
case 'preferences_update':
setEndOfDayNotification();
break;
}
} catch (e) {
if (data) {
Expand Down
Binary file removed swdc-vscode-2.7.0.vsix
Binary file not shown.
Binary file added swdc-vscode-2.7.1.vsix
Binary file not shown.
Loading

0 comments on commit 4ef3ed0

Please sign in to comment.