From bd0f1533a375977c1256b023299c99f097a56240 Mon Sep 17 00:00:00 2001 From: Daniel Constantin Date: Wed, 8 Aug 2018 13:35:41 +0300 Subject: [PATCH 1/4] Persist activities to a file --- app/index.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/index.js b/app/index.js index ac8271b..939bd57 100644 --- a/app/index.js +++ b/app/index.js @@ -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' @@ -35,6 +36,7 @@ import ActivitiesWindow from './windows/Activities/window' app.mainWindow = null // activities window +const activityLogPath = pathJoin(app.getPath('userData'), 'activity.log') let activitiesWindow = null let activitiesById = [] let activities = {} @@ -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) => { @@ -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', () => { From 797294ad959d67f9248fe0ae4ee043ff05669ba3 Mon Sep 17 00:00:00 2001 From: Daniel Constantin Date: Wed, 8 Aug 2018 13:51:49 +0300 Subject: [PATCH 2/4] Rename the activity log file --- app/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/index.js b/app/index.js index 939bd57..3a19835 100644 --- a/app/index.js +++ b/app/index.js @@ -36,7 +36,7 @@ import ActivitiesWindow from './windows/Activities/window' app.mainWindow = null // activities window -const activityLogPath = pathJoin(app.getPath('userData'), 'activity.log') +const activityLogPath = pathJoin(app.getPath('userData'), 'activity-log.json') let activitiesWindow = null let activitiesById = [] let activities = {} From fe5f98e28ebf0ec3a992dd57952c70aa356fd520 Mon Sep 17 00:00:00 2001 From: Daniel Constantin Date: Wed, 8 Aug 2018 18:54:45 +0300 Subject: [PATCH 3/4] Mark unfinished activities --- app/api.js | 1 + app/index.js | 9 ++- .../Activities/Components/AddActivity.jsx | 60 +++++++++---------- .../Activities/Components/ImportActivity.jsx | 12 ++-- 4 files changed, 45 insertions(+), 37 deletions(-) diff --git a/app/api.js b/app/api.js index b6abdff..22828b7 100644 --- a/app/api.js +++ b/app/api.js @@ -136,6 +136,7 @@ export function addFilesFromFSPath (filePaths, _queryGateways = queryGateways) { recursive: true, progress: (progress) => { app.emit('patch-activity', { + finished: progress === size, uuid, /** * { diff --git a/app/index.js b/app/index.js index 3a19835..11cfafd 100644 --- a/app/index.js +++ b/app/index.js @@ -133,7 +133,12 @@ function startOrion () { if (existsSync(activityLogPath)) { const activityLog = JSON.parse(readFileSync(activityLogPath)) activitiesById = activityLog.activitiesById - activities = activityLog.activities + // 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 @@ -313,7 +318,7 @@ app.on('import-from-hash', (hash) => { app.emit('show-activities-window') importObjectByHash(hash) - .then(() => {}) + .then(() => { }) .catch(err => { dialog.showErrorBox('Gurl, an error occurred!', `${err}`) }) diff --git a/app/windows/Activities/Components/AddActivity.jsx b/app/windows/Activities/Components/AddActivity.jsx index 1d80cb6..eb547df 100644 --- a/app/windows/Activities/Components/AddActivity.jsx +++ b/app/windows/Activities/Components/AddActivity.jsx @@ -36,36 +36,36 @@ const Progress = styled.div` } ` -const Activity = ({ activity }) => { - const finished = activity.progress.bytes === activity.size.bytes +const Activity = ({ activity }) => ( + + + + + + +

{activity.filename}

+ {activity.path} +
+ + + + { + activity.interrupted + ? 'Interrupted' + : activity.finished + ? {activity.size.value} {activity.size.unit} + : + {activity.progress.value} {activity.progress.unit} of {activity.size.value} {activity.size.unit} + + - return ( - - - - - - -

{activity.filename}

- {activity.path} -
- - - - { - !finished && - } - { - finished ? {activity.size.value} {activity.size.unit} - : {activity.progress.value} {activity.progress.unit} of {activity.size.value} {activity.size.unit} - } - - - - {moment(activity.timestamp).fromNow()} - -
- ) -} + } +
+ + + {moment(activity.timestamp).fromNow()} + +
+) export default Activity diff --git a/app/windows/Activities/Components/ImportActivity.jsx b/app/windows/Activities/Components/ImportActivity.jsx index a5d00ed..5c45d2f 100644 --- a/app/windows/Activities/Components/ImportActivity.jsx +++ b/app/windows/Activities/Components/ImportActivity.jsx @@ -43,13 +43,15 @@ const Activity = ({ activity }) => { { - !activity.finished && + !activity.finished && !activity.interrupted && } { - activity.finished && (activity.size - ? {activity.size.value} {activity.size.unit} - : 'Unknown' - ) + activity.interrupted + ? 'Interrupted' + : activity.finished && (activity.size + ? {activity.size.value} {activity.size.unit} + : 'Unknown' + ) } From a42bc27147808a39071dba9e7d31d51de7b3b457 Mon Sep 17 00:00:00 2001 From: Daniel Constantin Date: Wed, 8 Aug 2018 20:03:18 +0300 Subject: [PATCH 4/4] Fix AddActivity component --- app/windows/Activities/Components/AddActivity.jsx | 9 +++++---- app/windows/Activities/window.js | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/windows/Activities/Components/AddActivity.jsx b/app/windows/Activities/Components/AddActivity.jsx index eb547df..3d487c1 100644 --- a/app/windows/Activities/Components/AddActivity.jsx +++ b/app/windows/Activities/Components/AddActivity.jsx @@ -49,15 +49,16 @@ const Activity = ({ activity }) => ( + { + !activity.finished && !activity.interrupted && + + } { activity.interrupted ? 'Interrupted' : activity.finished ? {activity.size.value} {activity.size.unit} - : - {activity.progress.value} {activity.progress.unit} of {activity.size.value} {activity.size.unit} - - + : {activity.progress.value} {activity.progress.unit} of {activity.size.value} {activity.size.unit} } diff --git a/app/windows/Activities/window.js b/app/windows/Activities/window.js index 6eb1731..cfde055 100644 --- a/app/windows/Activities/window.js +++ b/app/windows/Activities/window.js @@ -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', () => {