Skip to content

Commit

Permalink
refactor: rm worker thread
Browse files Browse the repository at this point in the history
  • Loading branch information
timeowilliams committed Dec 2, 2024
1 parent e642019 commit 8dd7f0a
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 168 deletions.
5 changes: 0 additions & 5 deletions forge.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,6 @@ const config: ForgeConfig = {
entry: 'src/preload.ts',
config: 'vite.preload.config.ts',
target: 'preload'
},
{
entry: 'src/worker.ts',
config: 'vite.worker.config.ts',
target: 'main'
}
],
renderer: [
Expand Down
6 changes: 0 additions & 6 deletions latest-mac.json

This file was deleted.

35 changes: 3 additions & 32 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
Tray,
nativeImage
} from 'electron'
import { Worker } from 'worker_threads'
import path, { join } from 'path'
import dayjs from 'dayjs'
import fs from 'fs'
Expand Down Expand Up @@ -100,19 +99,13 @@ export function handleUserData(user: User, store: TypedStore): User {
country: user.country,
language: user.language
})
schedulerWorker.postMessage({
type: MessageType.SET_USER_INFO,
user
})

return user
}

// Load user data if available on app start
export function loadUserData(): User | null {
const savedUser: User | null = store.get('user') || null
if (savedUser) {
schedulerWorker.postMessage({ type: MessageType.SET_USER_INFO, user: savedUser })
const iconPath = app.isPackaged
? path.join(process.resourcesPath, 'icon.png')
: path.join(__dirname, '../../resources/icon.png')
Expand Down Expand Up @@ -401,35 +394,13 @@ export function handleUserLogout(): void {
}).show()
}

app.on('before-quit', () => schedulerWorker.terminate())
app.on('will-quit', () => {
ipcMain.removeAllListeners()
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') app.quit()
})

// Initialize worker and listen for messages
const schedulerWorkerPath = join(__dirname, 'worker.js')
const schedulerWorker = new Worker(schedulerWorkerPath, {
workerData: {
API_BASE_URL: API_BASE_URL
}
})
schedulerWorker.on('message', (message: any) => {
if (message.type === MessageType.RESET_WEEKLY) resetCounters('weekly')
if (message.type === MessageType.GET_DATA) {
const currentSiteTimeTrackers = getSiteTrackers()
const deepWorkHours = getDeepWorkHours()
schedulerWorker.postMessage({
type: MessageType.REPLY_DATA,
data: { currentSiteTimeTrackers, deepWorkHours }
})
}
})
schedulerWorker.on('error', (err) => console.error('Worker Error:', err))
schedulerWorker.on('message', (message) => console.log('Worker Message:', message))

// Getters
export function getDeepWorkHours(): DeepWorkHours {
calculateDeepWorkHours(getSiteTrackers(), deepWorkHours, store)
Expand All @@ -444,7 +415,7 @@ schedule.scheduleJob('0 0 0 * * *', async () => {
stopActivityMonitoring()
await checkAndSendMissedEmails()
await resetCounters('daily')
// startActivityMonitoring()
startActivityMonitoring()
log.info('new reset date is ', store.get('lastResetDate'))
})

Expand All @@ -453,8 +424,8 @@ schedule.scheduleJob('55 23 * * 0', () => {
log.info('Scheduled weekly reset at 11:55 PM on Sunday')
stopActivityMonitoring()
checkAndSendMissedEmails()
resetCounters('daily')
// startActivityMonitoring()
resetCounters('weekly')
startActivityMonitoring()
log.info('Weekly counters have been reset')
})

Expand Down
121 changes: 0 additions & 121 deletions src/worker.ts

This file was deleted.

4 changes: 0 additions & 4 deletions vite.worker.config.ts

This file was deleted.

0 comments on commit 8dd7f0a

Please sign in to comment.