Skip to content
This repository has been archived by the owner on Jul 7, 2024. It is now read-only.
/ Orion Public archive

Persist activities to a file #169

Merged
merged 5 commits into from
Aug 8, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions app/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { app, dialog, shell, ipcMain } from 'electron'
import { autoUpdater } from 'electron-updater'
import { join as pathJoin } from 'path'
import { existsSync, writeFileSync, readFileSync } from 'fs'
import pjson from '../package.json'
import Settings from 'electron-settings'
import './lib/report/node'
Expand Down Expand Up @@ -35,6 +36,7 @@ import ActivitiesWindow from './windows/Activities/window'
app.mainWindow = null

// activities window
const activityLogPath = pathJoin(app.getPath('userData'), 'activity.log')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.json?

let activitiesWindow = null
let activitiesById = []
let activities = {}
Expand Down Expand Up @@ -127,6 +129,13 @@ function startOrion () {
setupTrayIcon()
}

// retrieve the activity log from file
if (existsSync(activityLogPath)) {
const activityLog = JSON.parse(readFileSync(activityLogPath))
activitiesById = activityLog.activitiesById
activities = activityLog.activities
}

// Ask github whether there is an update
autoUpdater.checkForUpdates()
autoUpdater.on('update-available', (info) => {
Expand Down Expand Up @@ -380,6 +389,8 @@ app.on('will-quit', () => {
if (global.IPFS_PROCESS) {
global.IPFS_PROCESS.kill()
}
// persist activities
writeFileSync(activityLogPath, JSON.stringify({ activitiesById, activities }))
})

app.on('window-all-closed', () => {
Expand Down