diff --git a/index.js b/index.js index c7e26b97..180c95df 100644 --- a/index.js +++ b/index.js @@ -58,6 +58,11 @@ electron.ipcMain.on('setAspectRatio', function (e, aspectRatio, extraSize) { setAspectRatio(aspectRatio, extraSize) }) + +electron.ipcMain.on('setProgress', function (e, progress) { + setProgress(progress) +}) + function createMainWindow () { var win = new electron.BrowserWindow({ backgroundColor: '#282828', @@ -118,6 +123,13 @@ function setAspectRatio (aspectRatio, extraSize) { } } +// Show progress bar. Valid range is [0, 1]. Remove when < 0; indeterminate when > 1. +function setProgress (progress) { + if (mainWindow) { + mainWindow.setProgressBar(progress) + } +} + function toggleDevTools (win) { debug('toggleDevTools') win = win || electron.BrowserWindow.getFocusedWindow() @@ -334,9 +346,3 @@ if (process.platform === 'darwin') { } ) } - -// var progress = 0 -// setInterval(function () { -// progress += 0.1 -// mainWindow.setProgressBar(progress) -// }, 1000) diff --git a/main/index.js b/main/index.js index adbea872..b97dfa6f 100644 --- a/main/index.js +++ b/main/index.js @@ -74,6 +74,19 @@ function update () { var patches = diff(currentVDom, newVDom) rootElement = patch(rootElement, patches) currentVDom = newVDom + + updateDockIcon() +} + +function updateDockIcon () { + if (state.view.client) { + var progress = state.view.client.progress + // Hide progress bar when client has no torrents, or progress is 100% + if (state.view.client.torrents.length === 0 || progress === 1) { + progress = -1 + } + electron.ipcRenderer.send('setProgress', progress) + } } setInterval(function () {