Skip to content

Commit

Permalink
feat: KTB-61: detect starting time show notification after (#29)
Browse files Browse the repository at this point in the history
* CHORE: packages updates
* FEAT: add time-tracking feature
* FIX: allow new default settings changes
* change refresh rate from 5 mins to 2 mins
  • Loading branch information
a7madgamal authored Feb 16, 2021
1 parent 3f7f75d commit fde8b8f
Show file tree
Hide file tree
Showing 19 changed files with 1,783 additions and 1,395 deletions.
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
// }
// ]
]
// "plugins": ["emotion"]
// "plugins": ["@emotion"]
}
109 changes: 54 additions & 55 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,86 +90,85 @@
}
},
"dependencies": {
"@emotion/babel-preset-css-prop": "^10.0.27",
"@emotion/core": "^10.0.28",
"@emotion/styled": "^10.0.27",
"@fortawesome/fontawesome-svg-core": "^1.2.28",
"@fortawesome/free-brands-svg-icons": "^5.13.0",
"@fortawesome/free-solid-svg-icons": "^5.13.0",
"@fortawesome/react-fontawesome": "^0.1.9",
"@octokit/rest": "^17.1.4",
"@emotion/babel-preset-css-prop": "^11.0.0",
"@emotion/react": "^11.1.1",
"@emotion/styled": "^11.0.0",
"@fortawesome/fontawesome-svg-core": "^1.2.32",
"@fortawesome/free-brands-svg-icons": "^5.15.1",
"@fortawesome/free-solid-svg-icons": "^5.15.1",
"@fortawesome/react-fontawesome": "^0.1.13",
"@octokit/rest": "^18.0.9",
"babel-plugin-transform-react-jsx-source": "^6.22.0",
"body-parser": "^1.19.0",
"compare-versions": "^3.6.0",
"date-fns": "^2.17.0",
"devtron": "^1.4.0",
"electron-redux": "^1.5.3",
"electron-redux": "^1.5.4",
"electron-squirrel-startup": "^1.0.0",
"electron-unhandled": "^3.0.2",
"express": "4.17.1",
"file-loader": "^6.0.0",
"final-form": "^4.18.7",
"file-loader": "^6.2.0",
"final-form": "^4.20.1",
"final-form-arrays": "^3.0.2",
"got": "^10.7.0",
"got": "^11.8.0",
"history": "^4.10.1",
"jira-connector": "^3.1.0",
"node-fetch": "^2.6.0",
"node-jenkins": "^1.2.5",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-final-form": "^6.3.5",
"react-final-form-arrays": "^3.1.1",
"react-hot-loader": "^4.12.20",
"react-redux": "^7.2.0",
"react-router": "^5.1.2",
"react-router-dom": "^5.1.2",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-final-form": "^6.5.2",
"react-final-form-arrays": "^3.1.3",
"react-hot-loader": "^4.13.0",
"react-redux": "^7.2.2",
"react-router": "^5.2.0",
"react-router-dom": "^5.2.0",
"redux": "^4.0.5",
"redux-thunk": "^2.3.0",
"simple-git": "^2.10.0",
"source-map-support": "^0.5.16",
"ts-loader": "^6.2.2",
"universal-user-agent": "5.0.0",
"update-electron-app": "^1.5.0"
"simple-git": "^2.23.0",
"source-map-support": "^0.5.19",
"ts-loader": "^8.0.11",
"universal-user-agent": "6.0.0"
},
"devDependencies": {
"@electron-forge/cli": "6.0.0-beta.51",
"@electron-forge/maker-deb": "6.0.0-beta.51",
"@electron-forge/maker-rpm": "6.0.0-beta.51",
"@electron-forge/maker-squirrel": "6.0.0-beta.51",
"@electron-forge/maker-wix": "^6.0.0-beta.52",
"@electron-forge/maker-zip": "6.0.0-beta.51",
"@electron-forge/plugin-webpack": "6.0.0-beta.51",
"@electron-forge/publisher-github": "6.0.0-beta.51",
"@electron-forge/cli": "6.0.0-beta.54",
"@electron-forge/maker-deb": "6.0.0-beta.54",
"@electron-forge/maker-rpm": "6.0.0-beta.54",
"@electron-forge/maker-squirrel": "6.0.0-beta.54",
"@electron-forge/maker-wix": "6.0.0-beta.54",
"@electron-forge/maker-zip": "6.0.0-beta.54",
"@electron-forge/plugin-webpack": "6.0.0-beta.54",
"@electron-forge/publisher-github": "6.0.0-beta.54",
"@emotion/babel-plugin": "^11.0.0",
"@marshallofsound/webpack-asset-relocator-loader": "^0.5.0",
"@semantic-release/changelog": "^5.0.1",
"@semantic-release/commit-analyzer": "^8.0.1",
"@semantic-release/git": "^9.0.0",
"@semantic-release/github": "^7.0.7",
"@semantic-release/github": "^7.2.0",
"@types/body-parser": "^1.19.0",
"@types/electron-devtools-installer": "^2.2.0",
"@types/express": "4.17.3",
"@types/react-dom": "^16.9.5",
"@types/react-redux": "^7.1.7",
"@types/react-router": "^5.1.4",
"@types/react-router-dom": "^5.1.3",
"@types/request": "^2.48.4",
"@types/source-map-support": "^0.5.1",
"@types/express": "4.17.9",
"@types/react-dom": "^17.0.0",
"@types/react-redux": "^7.1.11",
"@types/react-router": "^5.1.8",
"@types/react-router-dom": "^5.1.6",
"@types/request": "^2.48.5",
"@types/source-map-support": "^0.5.3",
"@types/vfile-message": "^2.0.0",
"babel-plugin-emotion": "^10.0.29",
"conventional-changelog-conventionalcommits": "^4.3.0",
"css-loader": "^3.4.2",
"electron": "9.0.4",
"electron-devtools-installer": "^3.0.0",
"conventional-changelog-conventionalcommits": "^4.5.0",
"css-loader": "^5.0.1",
"electron": "11.0.3",
"electron-devtools-installer": "^3.1.1",
"electron-timber": "^0.5.1",
"electron-wix-msi": "^2.2.0",
"node-loader": "^0.6.0",
"prettier": "^2.0.5",
"electron-wix-msi": "^3.0.4",
"node-loader": "^1.0.2",
"prettier": "^2.2.0",
"redux-devtools-extension": "^2.13.8",
"semantic-release": "^17.1.1",
"style-loader": "^1.1.3",
"stylelint": "^13.2.1",
"semantic-release": "^17.3.0",
"style-loader": "^2.0.0",
"stylelint": "^13.8.0",
"stylelint-config-recommended": "^3.0.0",
"stylelint-config-standard": "^20.0.0",
"type-fest": "^0.12.0",
"typescript": "^3.9.5"
"type-fest": "^0.20.1",
"typescript": "^4.1.2"
}
}
16 changes: 7 additions & 9 deletions src/main/helpers/DiskSaver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@ import { app, remote } from 'electron'
import path from 'path'
import fs from 'fs'
import { okk } from '../helpers'
import { ISettingsState } from '../../shared/types/settings'
// @ts-ignore
import electronTimber from 'electron-timber'
import { INITIAL_SETTINGS } from '../../shared/constants'

const logger = electronTimber.create({ name: 'DiskSaver' })

class DiskSaver {
class DiskSaver<Schema> {
path: string
data: ISettingsState
data: Schema

constructor(opts: { configName: string; defaults: ISettingsState }) {
constructor(opts: { configName: string; defaults: Schema }) {
const userDataPath = (app || remote.app).getPath('userData')

this.path = path.join(okk(userDataPath), opts.configName + '.json')
Expand All @@ -25,19 +23,19 @@ class DiskSaver {
try {
this.data = readDataFile(this.path)
} catch (error) {
logger.error('DiskSaver: readin failed, resetting', error)
logger.error('DiskSaver: reading failed, resetting', error)

this.data = INITIAL_SETTINGS
this.data = opts.defaults
}
}

getAll() {
return this.data
}

save(dataObj: ISettingsState) {
save(dataObj: Schema) {
const data = JSON.stringify(dataObj)
logger.log('DiskSaver: saving', data)
logger.log(`DiskSaver: saving "${this.path}"`, data)

try {
fs.writeFileSync(this.path, data)
Expand Down
43 changes: 42 additions & 1 deletion src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ import electronUnhandled from 'electron-unhandled'

electronUnhandled({ showDialog: true })

import { app, globalShortcut, ipcMain, BrowserWindow } from 'electron'
import {
app,
globalShortcut,
ipcMain,
BrowserWindow,
powerMonitor,
} from 'electron'

// import { setContextMenu } from '../plugins/tray'
import { settingsPlugin } from './plugins/settings'
Expand Down Expand Up @@ -48,9 +54,12 @@ import {
IPC_GET_BRANCHES,
IPC_SAVE_SETTINGS,
IPC_PULL_BRANCH,
INITIAL_PROFILE,
} from '../shared/constants'
import { getMainStore } from './store'
import { LOAD_SETTINGS } from '../shared/types/settings'
import { TimeTracker } from './plugins/timer'
import { getProfileSettings } from '../shared/helpers'

const logger = electronTimber.create({ name: 'index' })

Expand All @@ -67,11 +76,36 @@ app.on('ready', () => {
const store = getMainStore()
const payload = settingsPlugin.getAll()

// make sure we get any new defaults
payload.profiles = payload.profiles.map((profile) => {
return {
...INITIAL_PROFILE,
...profile,
}
})

store.dispatch({ type: LOAD_SETTINGS, payload })

mainWindow = createAppWindow()
selectWindow = createSelectWindow()
// setContextMenu()
if (getProfileSettings(payload, payload.activeProfile).isTimeTrackerEnabled) {
var timeTracker = new TimeTracker()

powerMonitor.on('shutdown', () => {
console.log('powerMonitor shutdown')
timeTracker.onShutdown()
})

powerMonitor.on('lock-screen', () => {
console.log('powerMonitor lock-screen')
timeTracker.onLockScreen()
})
powerMonitor.on('unlock-screen', () => {
console.log('powerMonitor unlock-screen')
timeTracker.onUnlockScreen()
})
}

// todo: enable with port
// try {
Expand Down Expand Up @@ -272,3 +306,10 @@ process.on('uncaughtException', (error) => {
// }
// })
// export { mainWindow, selectWindow }

// powerMonitor.on('suspend', () => {
// console.log('powerMonitor suspend')
// })
// powerMonitor.on('resume', () => {
// console.log('powerMonitor resume')
// })
2 changes: 1 addition & 1 deletion src/main/plugins/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ const getBranches = async (repoId: string) => {
const gitRepo = await _getGitRepoFromId(repoId)

try {
await gitRepo.fetch(okk(repoSettings.remoteName), undefined, {
await gitRepo.fetch(okk(repoSettings.remoteName), {
'--prune': null,
})
} catch (error) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/plugins/settings.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { DiskSaver } from '../helpers/DiskSaver'
import { INITIAL_SETTINGS } from '../../shared/constants'
import { ISettingsState } from '../../shared/types/settings'

const settingsPlugin = new DiskSaver({
const settingsPlugin = new DiskSaver<ISettingsState>({
configName: 'user-preferences',
defaults: INITIAL_SETTINGS,
})
Expand Down
Loading

0 comments on commit fde8b8f

Please sign in to comment.