Skip to content

Commit

Permalink
Merge pull request #6 from anthonyraymond/reworked-dekstop
Browse files Browse the repository at this point in the history
Reworked dekstop
  • Loading branch information
anthonyraymond authored Feb 13, 2019
2 parents 7c54dc3 + 43f1c0e commit ffb21f9
Show file tree
Hide file tree
Showing 19 changed files with 70 additions and 436 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,3 @@ script:
- yarn lint
- yarn flow
- yarn build-e2e
- yarn test-e2e
55 changes: 40 additions & 15 deletions app/electron/WindowManager.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { app, ipcMain, BrowserWindow as BrowserWindowElectron } from 'electron';
import {
app,
ipcMain,
BrowserWindow as BrowserWindowElectron,
dialog
} from 'electron';
import waitOn from 'wait-on';
import StateManager from './StateManager';
import MenuBuilder from './MenuBuilder';
Expand All @@ -14,6 +19,8 @@ export default class WindowManager {

dependencyUpdater = new DependencyUpdater();

isUpdateInProgress = false;

stateManager = new StateManager();

joal = new Joal();
Expand Down Expand Up @@ -46,11 +53,29 @@ export default class WindowManager {
window: BrowserWindow,
descriptor: WindowItem
): void {
window.on('close', () => {
window.on('close', e => {
WindowManager.saveWindowState(window, descriptor);

this.stateManager.save();

if (this.isUpdateInProgress) {
const pressedButton = dialog.showMessageBox(window, {
type: 'question',
title: 'Update in progress',
message:
'Closing the app during the dependencies download process may leave your app in an unstable state.\n\nAre you sure you want to quit now ?',
buttons: ['&Yes', '&Cancel'],
defaultId: 1,
cancelId: 1,
normalizeAccessKeys: true
});
if (pressedButton === 1) {
e.preventDefault();
return;
}
}
this.isUpdateInProgress = false; // the below app.quit() will call this function another time, prevent a second dialog to open
// Force quit when the window is closed to prevent mac from hidding in in the dock.
this.joal.kill(() => app.quit());
});
window.on('closed', () => {
Expand All @@ -60,22 +85,26 @@ export default class WindowManager {

registerIpcEventHandlers(window: BrowserWindow): void {
ipcMain.on('renderer-ready-to-update', event => {
this.dependencyUpdater.checkAndInstallUpdate(event);
this.isUpdateInProgress = true;
this.dependencyUpdater
.checkAndInstallUpdate(event)
.then(() => {
this.isUpdateInProgress = false;
return true;
})
.catch(() => {
this.isUpdateInProgress = false;
});
});
ipcMain.on('renderer-ready-to-start-joal', () => {
console.log('Start joal now');

const uiConfig = this.joal.start();
const configAsUrlParam = encodeURI(JSON.stringify(uiConfig));

// TODO : remove this function as soon as the webui is able to intercept the loadURL.extraHeaders on startup
window.webContents.on('did-navigate', () => {
window.webContents.executeJavaScript(
`localStorage.setItem('guiConfig', '${JSON.stringify(uiConfig)}')`
);
});
const uiUrl = `http://${uiConfig.host}:${uiConfig.port}/${
uiConfig.pathPrefix
}/ui`;
}/ui?ui_credentials=${configAsUrlParam}`;
waitOn(
{
resources: [uiUrl],
Expand All @@ -92,11 +121,7 @@ export default class WindowManager {
);
return;
}
window.loadURL(uiUrl, {
extraHeaders: `joal-desktop-forwarded-ui-config: ${JSON.stringify(
uiConfig
)}`
});
window.loadURL(uiUrl);
}
);
});
Expand Down
2 changes: 1 addition & 1 deletion app/electron/runner/Joal.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ export default class Joal {
if (callback) {
callbackFn = callback;
}
console.log('Killing joal');

if (this.joalProcess) {
console.log('Killing joal');
treeKill(this.joalProcess.pid, 'SIGINT', err => {
if (!err) {
return callbackFn();
Expand Down
5 changes: 3 additions & 2 deletions app/electron/updaters/DependencyUpdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ import {
updateProcessError
} from '../../components/updaters/updaters.actions';

/* eslint-disable class-methods-use-this */
export default class DepencencyUpdater {
checkAndInstallUpdate(ipcChannel) {
// eslint-disable-line class-methods-use-this
// first check and install electron update
const passReducerActionToRenderer = action => {
// eslint-disable-line no-param-reassign
ipcChannel.sender.send('forward-update-message-to-renderer', action);
};

passReducerActionToRenderer(electronCheckingForUpdate());
updateElectron()
return updateElectron()
.onProgress(progress =>
passReducerActionToRenderer(electronDownloadProgress(progress * 100))
)
Expand Down Expand Up @@ -115,3 +115,4 @@ export default class DepencencyUpdater {
});
}
}
/* eslint-enable class-methods-use-this */
17 changes: 14 additions & 3 deletions app/electron/updaters/joal-updater/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const CLIENT_FILES_DIR = path.join(ROOT_INSTALL_FOLDER, 'clients');
const TORRENTS_DIR = path.join(ROOT_INSTALL_FOLDER, 'torrents');
const ARCHIVED_TORRENTS_DIR = path.join(TORRENTS_DIR, 'archived');
const JOAL_CORE_VERSION_FILE = path.join(ROOT_INSTALL_FOLDER, '.joal-core');
const JOAL_CORE_VERSION = '2.1.11';
const JOAL_CORE_VERSION = '2.1.12';
const JAR_NAME = `jack-of-all-trades-${JOAL_CORE_VERSION}.jar`;
const DOWNLOAD_URL = `https://github.com/anthonyraymond/joal/releases/download/v${JOAL_CORE_VERSION}/joal.tar.gz`;

Expand Down Expand Up @@ -94,8 +94,13 @@ const cleanInstallFolder = () => {
.forEach(jar => rimraf.sync(path.join(ROOT_INSTALL_FOLDER, jar)));
}

rimraf.sync(TMP_UPDATE_DIR);
rimraf.sync(JOAL_CORE_VERSION_FILE);
if (fs.existsSync(TMP_UPDATE_DIR)) {
rimraf.sync(TMP_UPDATE_DIR);
}

if (fs.existsSync(JOAL_CORE_VERSION_FILE)) {
rimraf.sync(JOAL_CORE_VERSION_FILE);
}
};

const install = () =>
Expand All @@ -109,6 +114,12 @@ const install = () =>
});
return;
}
try {
cleanInstallFolder(); // clean before install
} catch (e) {
console.log('Joal failed to clean install folder before install');
reject(e);
}

console.log('Joal is not installed yet, pulling from github');
let downloaded = 0;
Expand Down
12 changes: 11 additions & 1 deletion app/electron/updaters/jre-updater/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import os from 'os';
import { app } from 'electron';
import path from 'path';
import request from 'request';
import fs from 'fs';
import rimraf from 'rimraf';
import zlib from 'zlib';
import tar from 'tar-fs';
Expand Down Expand Up @@ -79,7 +80,9 @@ const isInstalledAndDoesNotRequiresUpdates = () => {
};

const cleanInstallFolder = () => {
rimraf.sync(ROOT_INSTALL_FOLDER);
if (fs.existsSync(ROOT_INSTALL_FOLDER)) {
rimraf.sync(ROOT_INSTALL_FOLDER);
}
};

const install = () =>
Expand All @@ -94,6 +97,13 @@ const install = () =>
return;
}

try {
cleanInstallFolder(); // clean before install
} catch (e) {
console.log('Jre failed to clean install folder before install');
reject(e);
}

console.log(`Jre is not installed yet, pulling it from ${url()}`);
let downloaded = 0;
let totalDownloadLength = 0;
Expand Down
1 change: 0 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,3 @@ test_script:
- yarn package-ci
- yarn lint
- yarn build-e2e
- yarn test-e2e
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "joal-desktop",
"productName": "JoalDesktop",
"version": "1.2.0",
"version": "2.0.0",
"description": "A tool to fake your torrent tracker upload.",
"scripts": {
"build": "concurrently \"yarn build-main\" \"yarn build-renderer\"",
Expand Down
12 changes: 0 additions & 12 deletions test/.eslintrc

This file was deleted.

13 changes: 0 additions & 13 deletions test/actions/__snapshots__/counter.spec.js.snap

This file was deleted.

43 changes: 0 additions & 43 deletions test/actions/counter.spec.js

This file was deleted.

70 changes: 0 additions & 70 deletions test/components/Counter.spec.js

This file was deleted.

Loading

0 comments on commit ffb21f9

Please sign in to comment.