Skip to content

Commit

Permalink
Dismiss Steam running warning if Steam exits
Browse files Browse the repository at this point in the history
Fixes #30
  • Loading branch information
mathphreak committed Aug 14, 2016
1 parent 9c5cabe commit 65790b4
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 28 deletions.
59 changes: 36 additions & 23 deletions src/client/move.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,45 +96,59 @@ function makeDeleteProgressObserver() {
ipc.send('progress', false);
$('#progress-container').height('0%');
$('.progress').height(0);
setTimeout(() => clGames.emit('refresh'), 400);
setTimeout(() => {
$('.progress').width(0);
clGames.emit('refresh');
}, 400);
}, 400)
);
}

function runningConfirm(cancelText) {
return function (running) {
let result = new Rx.Subject();
function checkRunningAndConfirm(cancelText) {
const result = new Rx.Subject();
function done(r) {
result.onNext(r);
result.onCompleted();
}
ipc.send('isSteamRunning', true);
ipc.once('isSteamRunning', (evt, running) => {
let skipDialog = false;
function handleNewISRResult(evt, stillRunning) {
if (!stillRunning) {
// Don't continue to ask for updates
ipc.send('isSteamRunning', false);
ipc.removeListener('isSteamRunning', handleNewISRResult);

// Close the dialog
skipDialog = true;
vex.closeAll();

// Return that Steam is not actually running
done(!stillRunning);
}
}
if (running) {
const message = `<p>It looks like Steam is currently running.</p>
<p>If you move games while Steam is running, bad things may happen.</p>
<p>If you have quit Steam or Steam isn't actually running,
just continue.</p>`;
<p>This message will disappear if you go quit Steam.</p>
<p>If Steam isn't actually running, just continue.</p>`;
ipc.on('isSteamRunning', handleNewISRResult);
vex.dialog.confirm({
message,
buttons: [
vexSubmitButton('Continue'),
vexCancelButton(cancelText)
],
callback: x => {
result.onNext(x);
result.onCompleted();
callback: r => {
if (!skipDialog) {
done(r);
}
}
});
} else {
result = Rx.Observable.just(true);
done(true);
}
return result;
};
}

function checkRunning() {
const result = new Rx.Subject();
ipc.once('isSteamRunning', (evt, x) => {
console.log('isSteamRunning:', x);
result.onNext(x);
result.onCompleted();
});
ipc.send('isSteamRunning');
return result;
}

Expand All @@ -159,8 +173,7 @@ function ready() {
const copyProgressObserver = makeCopyProgressObserver();
const deleteProgressObserver = makeDeleteProgressObserver();

checkRunning()
.flatMap(runningConfirm('Cancel'))
checkRunningAndConfirm('Cancel')
.flatMap(go => {
if (go) {
ipc.send('progress', 0);
Expand Down
23 changes: 18 additions & 5 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Import the Electron stuff
import {app, BrowserWindow, ipcMain as ipc, Menu, MenuItem, shell} from 'electron';
import _ from 'lodash';
import Rx from 'rx';
import * as initSteps from './steps/init';

// Keep a global reference of the window object, if you don't, the window will
Expand All @@ -20,11 +21,23 @@ ipc.on('progress', (event, arg) => {

ipc.on('showMenu', (event, arg) => buildMenu(arg));

ipc.on('isSteamRunning', event => {
// For some reason, ps-list doesn't work in the renderer.
// So we call isSteamRunning here instead.
initSteps.isSteamRunning()
.subscribe(x => event.sender.send('isSteamRunning', x));
let isrSubscription;
ipc.on('isSteamRunning', (event, subscribe) => {
if (subscribe) {
// For some reason, ps-list doesn't work in the renderer.
// So we call isSteamRunning here instead.
initSteps.isSteamRunning()
.subscribe(running => {
event.sender.send('isSteamRunning', running);
if (running) {
isrSubscription = Rx.Observable.interval(2000)
.flatMap(() => initSteps.isSteamRunning())
.subscribe(r => event.sender.send('isSteamRunning', r));
}
});
} else {
isrSubscription.dispose();
}
});

// Quit when all windows are closed. Even on OS X.
Expand Down

0 comments on commit 65790b4

Please sign in to comment.