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

Commit

Permalink
Merge pull request #169 from Siderus/feature/persist-activities
Browse files Browse the repository at this point in the history
Persist activities to a file
  • Loading branch information
kernelwhisperer authored Aug 8, 2018
2 parents fbc9d83 + a42bc27 commit 1ca5bfe
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 36 deletions.
1 change: 1 addition & 0 deletions app/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export function addFilesFromFSPath (filePaths, _queryGateways = queryGateways) {
recursive: true,
progress: (progress) => {
app.emit('patch-activity', {
finished: progress === size,
uuid,
/**
* {
Expand Down
16 changes: 16 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.json')
let activitiesWindow = null
let activitiesById = []
let activities = {}
Expand Down Expand Up @@ -122,6 +124,18 @@ function startWelcome () {
* 8. show storage window
*/
function startOrion () {
// retrieve the activity log from file
if (existsSync(activityLogPath)) {
const activityLog = JSON.parse(readFileSync(activityLogPath))
activitiesById = activityLog.activitiesById
// assign the activities as well, but first mark the ones that did not finish
activitiesById.forEach(id => {
const activity = activityLog.activities[id]
activity.interrupted = !activity.finished
activities[id] = activity
})
}

// Ask github whether there is an update
autoUpdater.checkForUpdates()
autoUpdater.on('update-available', (info) => {
Expand Down Expand Up @@ -379,6 +393,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
61 changes: 31 additions & 30 deletions app/windows/Activities/Components/AddActivity.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,36 +36,37 @@ const Progress = styled.div`
}
`

const Activity = ({ activity }) => {
const finished = activity.progress.bytes === activity.size.bytes

return (
<ActivityWrapper>
<td>
<span className="icon icon-upload" title={activity.type}></span>
</td>
<td>
<NameAndPath>
<h4>{activity.filename}</h4>
<span>{activity.path}</span>
</NameAndPath>
</td>
<td>
<Progress>
{
!finished && <ProgressBar percentage={activity.progress.bytes / activity.size.bytes * 100} />
}
{
finished ? <span>{activity.size.value} {activity.size.unit}</span>
const Activity = ({ activity }) => (
<ActivityWrapper>
<td>
<span className="icon icon-upload" title={activity.type}></span>
</td>
<td>
<NameAndPath>
<h4>{activity.filename}</h4>
<span>{activity.path}</span>
</NameAndPath>
</td>
<td>
<Progress>
{
!activity.finished && !activity.interrupted &&
<ProgressBar percentage={activity.progress.bytes / activity.size.bytes * 100} />
}
{
activity.interrupted
? 'Interrupted'
: activity.finished
? <span>{activity.size.value} {activity.size.unit}</span>
: <span>{activity.progress.value} {activity.progress.unit} of {activity.size.value} {activity.size.unit}</span>
}
</Progress>
</td>
<td>
{moment(activity.timestamp).fromNow()}
</td>
</ActivityWrapper>
)
}

}
</Progress>
</td>
<td>
{moment(activity.timestamp).fromNow()}
</td>
</ActivityWrapper>
)

export default Activity
12 changes: 7 additions & 5 deletions app/windows/Activities/Components/ImportActivity.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ const Activity = ({ activity }) => {
<td>
<Progress>
{
!activity.finished && <ProgressBar indeterminate />
!activity.finished && !activity.interrupted && <ProgressBar indeterminate />
}
{
activity.finished && (activity.size
? <span>{activity.size.value} {activity.size.unit}</span>
: 'Unknown'
)
activity.interrupted
? 'Interrupted'
: activity.finished && (activity.size
? <span>{activity.size.value} {activity.size.unit}</span>
: 'Unknown'
)
}
</Progress>
</td>
Expand Down
2 changes: 1 addition & 1 deletion app/windows/Activities/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports.create = function createDetailsWindow (app) {
})

// Show menu only on StorageList
thisWindow.setMenu(null)
// thisWindow.setMenu(null)

// Show the window only when ready
thisWindow.once('ready-to-show', () => {
Expand Down

0 comments on commit 1ca5bfe

Please sign in to comment.