[Added tooltips] [IPC constants]

This commit is contained in:
Scott E. Graves
2018-10-02 16:13:45 -05:00
parent f2a7d1c188
commit 85d8dc8c01
12 changed files with 187 additions and 115 deletions

1
.gitignore vendored
View File

@@ -4,3 +4,4 @@ node_modules/
build/
chrome_data/
dist/
/.cache

View File

@@ -2,7 +2,7 @@
const {app, BrowserWindow, Tray, nativeImage, Menu} = require('electron');
const {ipcMain} = require('electron');
const Constants = require('./src/constants');
const path = require('path');
const url = require('url');
require('electron-debug')();
@@ -76,6 +76,14 @@ function createWindow() {
autoLauncher.disable();
}
}
},
{
type: 'separator'
},
{
label: 'Exit', click(item) {
app.quit();
}
}
]);
@@ -130,7 +138,7 @@ if (!instanceLock) {
});
}
ipcMain.on('check_installed', (event, data) => {
ipcMain.on(Constants.IPC_Check_Installed, (event, data) => {
const dataDirectory = helpers.resolvePath(data.Directory);
const destination = path.join(dataDirectory, data.Version);
helpers
@@ -141,7 +149,7 @@ ipcMain.on('check_installed', (event, data) => {
exists = fs.existsSync(destination) && fs.lstatSync(destination).isDirectory();
} catch (e) {
}
event.sender.send('check_installed_reply', {
event.sender.send(Constants.IPC_Check_Installed_Reply, {
data: {
Dependencies: dependencies,
Exists: exists,
@@ -150,7 +158,7 @@ ipcMain.on('check_installed', (event, data) => {
}
});
}).catch((e) => {
event.sender.send('check_installed_reply', {
event.sender.send(Constants.IPC_Check_Installed_Reply, {
data: {
Dependencies: [],
Error: e,
@@ -161,7 +169,7 @@ ipcMain.on('check_installed', (event, data) => {
});
});
ipcMain.on('delete_file', (event, data) => {
ipcMain.on(Constants.IPC_Delete_File, (event, data) => {
try {
if (fs.existsSync(data.FilePath)) {
fs.unlinkSync(data.FilePath);
@@ -170,7 +178,7 @@ ipcMain.on('delete_file', (event, data) => {
}
});
ipcMain.on('detect_mounts', (event, data) => {
ipcMain.on(Constants.IPC_Detect_Mounts, (event, data) => {
let driveLetters = {
Hyperspace: [],
Sia: [],
@@ -218,7 +226,7 @@ ipcMain.on('detect_mounts', (event, data) => {
siaLocation = siaLocation.toUpperCase();
grabDriveLetters(hsLocation, siaLocation);
}
event.sender.send('detect_mounts_reply', {
event.sender.send(Constants.IPC_Detect_Mounts_Reply, {
data: {
DriveLetters: driveLetters,
Locations: {
@@ -236,7 +244,7 @@ ipcMain.on('detect_mounts', (event, data) => {
.catch((err) => {
grabDriveLetters('', '');
event.sender.send('detect_mounts_reply', {
event.sender.send(Constants.IPC_Detect_Mounts_Reply, {
data: {
DriveLetters: driveLetters,
Error: err,
@@ -246,11 +254,11 @@ ipcMain.on('detect_mounts', (event, data) => {
});
});
ipcMain.on('download_file', (event, data) => {
ipcMain.on(Constants.IPC_Download_File, (event, data) => {
const dataDirectory = helpers.resolvePath(data.Directory);
const destination = path.join(dataDirectory, data.Filename);
helpers.downloadFile(data.URL, destination, (progress) => {
event.sender.send('download_file_progress', {
event.sender.send(Constants.IPC_Download_File_Progress, {
data: {
Destination: destination,
Progress: progress,
@@ -258,7 +266,7 @@ ipcMain.on('download_file', (event, data) => {
}
});
}, (success, err) => {
event.sender.send('download_file_complete', {
event.sender.send(Constants.IPC_Download_File_Complete, {
data: {
Destination: destination,
Error: err,
@@ -269,7 +277,7 @@ ipcMain.on('download_file', (event, data) => {
});
});
ipcMain.on('extract_release', (event, data) => {
ipcMain.on(Constants.IPC_Extract_Release, (event, data) => {
const dataDirectory = helpers.resolvePath(data.Directory);
const destination = path.join(dataDirectory, data.Version);
helpers.mkDirByPathSync(destination);
@@ -283,7 +291,7 @@ ipcMain.on('extract_release', (event, data) => {
} catch (e) {
}
stream.close();
event.sender.send('extract_release_complete', {
event.sender.send(Constants.IPC_Extract_Release_Complete, {
data: {
Error: e,
Source: data.Source,
@@ -293,7 +301,7 @@ ipcMain.on('extract_release', (event, data) => {
})
.on('finish', () => {
stream.close();
event.sender.send('extract_release_complete', {
event.sender.send(Constants.IPC_Extract_Release_Complete, {
data: {
Source: data.Source,
Success: true,
@@ -302,20 +310,20 @@ ipcMain.on('extract_release', (event, data) => {
});
});
ipcMain.on('get_config', (event, data) => {
ipcMain.on(Constants.IPC_Get_Config, (event, data) => {
const dataDirectory = helpers.resolvePath(data.Directory);
helpers
.getConfig(dataDirectory, data.Version, data.StorageType)
.then((data) => {
if (data.Code === 0) {
event.sender.send('get_config_reply', {
event.sender.send(Constants.IPC_Get_Config_Reply, {
data: {
Success: true,
Config: data.Data,
}
});
} else {
event.sender.send('get_config_reply', {
event.sender.send(Constants.IPC_Get_Config_Reply, {
data: {
Error: data.Code,
Success: false,
@@ -324,7 +332,7 @@ ipcMain.on('get_config', (event, data) => {
}
})
.catch((e)=> {
event.sender.send('get_config_reply', {
event.sender.send(Constants.IPC_Get_Config_Reply, {
data: {
Error: e,
Success: false,
@@ -333,12 +341,12 @@ ipcMain.on('get_config', (event, data) => {
});
});
ipcMain.on('get_config_template', (event, data) => {
ipcMain.on(Constants.IPC_Get_Config_Template, (event, data) => {
const dataDirectory = helpers.resolvePath(data.Directory);
helpers
.getConfigTemplate(dataDirectory, data.Version, data.StorageType)
.then((data) => {
event.sender.send('get_config_template_reply', {
event.sender.send(Constants.IPC_Get_Config_Template_Reply, {
data: {
Success: true,
Template: data,
@@ -346,7 +354,7 @@ ipcMain.on('get_config_template', (event, data) => {
});
})
.catch((e)=> {
event.sender.send('get_config_template_reply', {
event.sender.send(Constants.IPC_Get_Config_Template_Reply, {
data: {
Error: e,
Success: false,
@@ -355,40 +363,40 @@ ipcMain.on('get_config_template', (event, data) => {
});
});
ipcMain.on('get_platform', (event) => {
event.sender.send('get_platform_reply', {
ipcMain.on(Constants.IPC_Get_Platform, (event) => {
event.sender.send(Constants.IPC_Get_Platform_Reply, {
data: os.platform()
});
});
ipcMain.on('get_state', (event, data) => {
ipcMain.on(Constants.IPC_Get_State, (event, data) => {
const dataDirectory = helpers.resolvePath(data);
helpers.mkDirByPathSync(dataDirectory);
const configFile = path.join(dataDirectory, 'settings.json');
if (fs.existsSync(configFile)) {
event.sender.send('get_state_reply', {
event.sender.send(Constants.IPC_Get_State_Reply, {
data: JSON.parse(fs.readFileSync(configFile, 'utf8')),
});
} else {
event.sender.send('get_state_reply', {
event.sender.send(Constants.IPC_Get_State_Reply, {
data: null,
});
}
});
ipcMain.on('grab_releases', (event) => {
event.sender.send('grab_releases_reply');
ipcMain.on(Constants.IPC_Grab_Releases, (event) => {
event.sender.send(Constants.IPC_Grab_Releases_Reply);
});
ipcMain.on('grab_ui_releases', (event) => {
event.sender.send('grab_ui_releases_reply');
ipcMain.on(Constants.IPC_Grab_UI_Releases, (event) => {
event.sender.send(Constants.IPC_Grab_UI_Releases_Reply);
});
ipcMain.on('install_dependency', (event, data) => {
ipcMain.on(Constants.IPC_Install_Dependency, (event, data) => {
helpers
.executeAndWait(data.Source)
.then(()=> {
event.sender.send('install_dependency_reply', {
event.sender.send(Constants.IPC_Install_Dependency_Reply, {
data: {
Source: data.Source,
Success: true,
@@ -396,7 +404,7 @@ ipcMain.on('install_dependency', (event, data) => {
});
})
.catch((e)=> {
event.sender.send('install_dependency_reply', {
event.sender.send(Constants.IPC_Install_Dependency_Reply, {
data: {
Error: e,
Source: data.Source,
@@ -406,14 +414,14 @@ ipcMain.on('install_dependency', (event, data) => {
});
});
ipcMain.on('install_upgrade', (event, data) => {
ipcMain.on(Constants.IPC_Install_Upgrade, (event, data) => {
helpers
.executeAsync(data.Source)
.then(()=> {
mainWindow.close();
})
.catch((e)=> {
event.sender.send('install_upgrade_reply', {
event.sender.send(Constants.IPC_Install_Upgrade_Reply, {
data: {
Error: e,
Source: data.Source,
@@ -423,11 +431,11 @@ ipcMain.on('install_upgrade', (event, data) => {
});
});
ipcMain.on('mount_drive', (event, data) => {
ipcMain.on(Constants.IPC_Mount_Drive, (event, data) => {
const dataDirectory = helpers.resolvePath(data.Directory);
const errorHandler = (pid) => {
mountedPIDs.splice(mountedPIDs.indexOf(pid), 1);
event.sender.send('unmount_drive_reply', {
event.sender.send(Constants.IPC_Unmount_Drive_Reply, {
data: {
PID: -1,
StorageType: data.StorageType,
@@ -442,7 +450,7 @@ ipcMain.on('mount_drive', (event, data) => {
if (pid !== -1) {
mountedPIDs.push(pid);
}
event.sender.send('mount_drive_reply', {
event.sender.send(Constants.IPC_Mount_Drive_Reply, {
data: {
PID: pid,
StorageType: data.StorageType,
@@ -455,14 +463,14 @@ ipcMain.on('mount_drive', (event, data) => {
});
});
ipcMain.on('save_state', (event, data) => {
ipcMain.on(Constants.IPC_Save_State, (event, data) => {
const dataDirectory = helpers.resolvePath(data.Directory);
helpers.mkDirByPathSync(dataDirectory);
const configFile = path.join(dataDirectory, 'settings.json');
fs.writeFileSync(configFile, JSON.stringify(data.State), 'utf8');
});
ipcMain.on('set_config_values', (event, data) => {
ipcMain.on(Constants.IPC_Set_Config_Values, (event, data) => {
const dataDirectory = helpers.resolvePath(data.Directory);
const setConfigValue = (i) => {
if (i < data.Items.length) {
@@ -475,18 +483,18 @@ ipcMain.on('set_config_values', (event, data) => {
setConfigValue(++i);
});
} else {
event.sender.send('set_config_values_reply', {});
event.sender.send(Constants.IPC_Set_Config_Values_Reply, {});
}
};
setConfigValue(0);
});
ipcMain.on('unmount_drive', (event, data) => {
ipcMain.on(Constants.IPC_Unmount_Drive, (event, data) => {
helpers
.stopProcessByPID(data.PID)
.then((pid)=> {
if (mountedPIDs.indexOf(pid) === -1) {
event.sender.send('unmount_drive_reply');
event.sender.send(Constants.IPC_Unmount_Drive_Reply);
}
})
.catch((e) => {

View File

@@ -47,6 +47,7 @@
"react-dev-utils": "^5.0.1",
"react-dom": "^16.4.1",
"react-loader-spinner": "^2.0.6",
"react-tooltip": "^3.8.4",
"resolve": "1.6.0",
"style-loader": "0.19.0",
"sw-precache-webpack-plugin": "0.11.4",
@@ -68,7 +69,7 @@
},
"devDependencies": {
"cross-env": "^5.2.0",
"electron": "3.0.0",
"electron": "^3.0.2",
"electron-builder": "^20.28.4",
"extract-text-webpack-plugin": "^3.0.2",
"webpack-browser-plugin": "^1.0.20"
@@ -121,6 +122,7 @@
"appId": "repertory-ui",
"files": [
"./electron.js",
"./src/constants.js",
"build/**/*",
"node_modules/**/*",
"./helpers.js"

View File

@@ -1,5 +1,4 @@
import React, {Component} from 'react';
import * as Constants from './constants';
import axios from 'axios';
import styles from './App.css';
import Box from './components/UI/Box/Box';
@@ -15,6 +14,7 @@ import MountItems from './containers/MountItems/MountItems';
import UpgradeIcon from './components/UpgradeIcon/UpgradeIcon';
import UpgradeUI from './components/UpgradeUI/UpgradeUI';
const Constants = require('./constants');
const Scheduler = require('node-schedule');
let ipcRenderer = null;
@@ -399,18 +399,7 @@ class App extends Component {
};
onGrabReleasesReply = ()=> {
axios.get(Constants.RELEASES_URL)
.then(response => {
const versionLookup = {
Alpha: response.data.Versions.Alpha[this.state.Platform],
Beta: response.data.Versions.Beta[this.state.Platform],
RC: response.data.Versions.RC[this.state.Platform],
Release: response.data.Versions.Release[this.state.Platform],
};
const locationsLookup = {
...response.data.Locations[this.state.Platform],
};
const doUpdate = (locationsLookup, versionLookup) => {
const latestVersion = versionLookup[this.state.ReleaseTypes[this.state.Release]].length - 1;
let version = this.state.Version;
if (version === -1) {
@@ -424,9 +413,40 @@ class App extends Component {
VersionAvailable: version !== latestVersion,
VersionLookup: versionLookup,
});
this.checkVersionInstalled(this.state.Release, version, versionLookup);
};
axios.get(Constants.RELEASES_URL)
.then(response => {
const versionLookup = {
Alpha: response.data.Versions.Alpha[this.state.Platform],
Beta: response.data.Versions.Beta[this.state.Platform],
RC: response.data.Versions.RC[this.state.Platform],
Release: response.data.Versions.Release[this.state.Platform],
};
const locationsLookup = {
...response.data.Locations[this.state.Platform],
};
window.localStorage.setItem('releases', JSON.stringify({
LocationsLookup: locationsLookup,
VersionLookup: versionLookup
}));
doUpdate(locationsLookup, versionLookup);
}).catch(error => {
console.log(error);
const releases = window.localStorage.getItem('releases');
if (releases && (releases.length > 0)) {
const obj = JSON.parse(releases);
const locationsLookup = obj.LocationsLookup;
const versionLookup = obj.VersionLookup;
doUpdate(locationsLookup, versionLookup);
} else {
// TODO Handle error
}
});
};
@@ -446,6 +466,10 @@ class App extends Component {
}
}).catch(error => {
console.log(error);
this.setState({
UpgradeAvailable: false,
UpgradeData: {},
});
});
};
@@ -648,7 +672,7 @@ class App extends Component {
<table cellPadding={0}
cellSpacing={0}
style={{margin: 0, padding: 0}}
width="100%">
width='100%'>
<tbody style={{margin: 0, padding: 0}}>
<tr style={{margin: 0, padding: 0}}>
<td style={{margin: 0, padding: 0}}

View File

@@ -1,4 +1,6 @@
.MountItem {
padding: 0;
margin: 0;
width: 100%;
}

View File

@@ -3,7 +3,8 @@ import CSSModules from 'react-css-modules';
import styles from './Box.css';
export default CSSModules((props) => {
const styleList = ['Box'];
const styleList = [];
styleList.push('Box');
if (props.dxDark) {
styleList.push('Darker');
}

View File

@@ -1,4 +1,4 @@
.UpgradeIcon {
.Owner {
display: block;
margin-right: 2px;
padding: 0;
@@ -7,5 +7,20 @@
border: 0;
box-sizing: border-box;
cursor: pointer;
opacity: 0.65;
}
.Owner p {
margin: 0;
padding: 0;
}
.UpgradeIcon {
display: block;
margin: 0;
padding: 0;
border: 0;
width: 20px;
height: 20px;
box-sizing: border-box;
opacity: 0.65;
}

View File

@@ -2,18 +2,34 @@ import React from 'react';
import CSSModules from 'react-css-modules';
import styles from './UpgradeIcon.css';
import availableImage from '../../assets/images/release_available.png';
import ReactTooltip from 'react-tooltip';
export default CSSModules((props) => {
let style;
let style2;
let placement = 'left';
let toolTipText = 'UI Upgrade Available';
if (props.release) {
style = {float: 'right', marginRight: '5%', cursor: 'default'};
placement='bottom';
toolTipText = 'New Release Available';
style = {float: 'right', marginRight: '5%', width: '15px', height: '15px', cursor: 'default'};
style2 = {width: '15px', height: '15px'};
}
return props.available ?
<img alt=''
onClick={props.clicked}
src={availableImage}
style={style}
styleName='UpgradeIcon'/> :
null;
return props
.available ?
(
<div style={style}
styleName='Owner'>
<p data-tip='' data-for={placement}>
<img alt=''
onClick={props.clicked}
src={availableImage}
style={style2}
styleName='UpgradeIcon'/>
</p>
<ReactTooltip id={placement} place={placement}>{toolTipText}</ReactTooltip>
</div>
)
: null;
}, styles, {allowMultiple: true});

View File

@@ -1,57 +1,60 @@
export const RELEASES_URL = 'https://bitbucket.org/blockstorage/repertory/raw/master/releases.json';
export const DATA_LOCATIONS = {
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.RELEASES_URL = 'https://bitbucket.org/blockstorage/repertory/raw/1.0.0-alpha.2_branch/releases.json';
exports.DATA_LOCATIONS = {
linux: '~/.local/repertory/ui',
darwin: '~/Library/Application Support/repertory/ui',
win32: '%LOCALAPPDATA%\\repertory\\ui',
win32: '%LOCALAPPDATA%\\repertory\\ui'
};
export const UI_RELEASES_URL = 'https://bitbucket.org/blockstorage/repertory-ui/raw/master/releases.json';
exports.UI_RELEASES_URL = 'https://bitbucket.org/blockstorage/repertory-ui/raw/1.0.1_branch/releases.json';
export const IPC_Check_Installed = 'check_installed';
export const IPC_Check_Installed_Reply = 'check_installed_reply';
exports.IPC_Check_Installed = 'check_installed';
exports.IPC_Check_Installed_Reply = 'check_installed_reply';
export const IPC_Delete_File = 'delete_file';
exports.IPC_Delete_File = 'delete_file';
export const IPC_Detect_Mounts = 'detect_mounts';
export const IPC_Detect_Mounts_Reply = 'detect_mounts_reply';
exports.IPC_Detect_Mounts = 'detect_mounts';
exports.IPC_Detect_Mounts_Reply = 'detect_mounts_reply';
export const IPC_Download_File = 'download_file';
export const IPC_Download_File_Complete = 'download_file_complete';
export const IPC_Download_File_Progress = 'download_file_progress';
exports.IPC_Download_File = 'download_file';
exports.IPC_Download_File_Complete = 'download_file_complete';
exports.IPC_Download_File_Progress = 'download_file_progress';
export const IPC_Extract_Release = 'extract_release';
export const IPC_Extract_Release_Complete = 'extract_release_complete';
exports.IPC_Extract_Release = 'extract_release';
exports.IPC_Extract_Release_Complete = 'extract_release_complete';
export const IPC_Get_Config = 'get_config';
export const IPC_Get_Config_Reply = 'get_config_reply';
exports.IPC_Get_Config = 'get_config';
exports.IPC_Get_Config_Reply = 'get_config_reply';
export const IPC_Get_Config_Template = 'get_config_template';
export const IPC_Get_Config_Template_Reply = 'get_config_template_reply';
exports.IPC_Get_Config_Template = 'get_config_template';
exports.IPC_Get_Config_Template_Reply = 'get_config_template_reply';
export const IPC_Get_Platform = 'get_platform';
export const IPC_Get_Platform_Reply = 'get_platform_reply';
exports.IPC_Get_Platform = 'get_platform';
exports.IPC_Get_Platform_Reply = 'get_platform_reply';
export const IPC_Get_State = 'get_state';
export const IPC_Get_State_Reply = 'get_state_reply';
exports.IPC_Get_State = 'get_state';
exports.IPC_Get_State_Reply = 'get_state_reply';
export const IPC_Grab_Releases = 'grab_releases';
export const IPC_Grab_Releases_Reply = 'grab_releases_reply';
exports.IPC_Grab_Releases = 'grab_releases';
exports.IPC_Grab_Releases_Reply = 'grab_releases_reply';
export const IPC_Grab_UI_Releases = 'grab_ui_releases';
export const IPC_Grab_UI_Releases_Reply = 'grab_ui_releases_reply';
exports.IPC_Grab_UI_Releases = 'grab_ui_releases';
exports.IPC_Grab_UI_Releases_Reply = 'grab_ui_releases_reply';
export const IPC_Install_Dependency = 'install_dependency';
export const IPC_Install_Dependency_Reply = 'install_dependency_reply';
exports.IPC_Install_Dependency = 'install_dependency';
exports.IPC_Install_Dependency_Reply = 'install_dependency_reply';
export const IPC_Install_Upgrade = 'install_upgrade';
export const IPC_Install_Upgrade_Reply = 'install_upgrade_reply';
exports.IPC_Install_Upgrade = 'install_upgrade';
exports.IPC_Install_Upgrade_Reply = 'install_upgrade_reply';
export const IPC_Mount_Drive = 'mount_drive';
export const IPC_Mount_Drive_Reply = 'mount_drive_reply';
exports.IPC_Mount_Drive = 'mount_drive';
exports.IPC_Mount_Drive_Reply = 'mount_drive_reply';
export const IPC_Save_State = 'save_state';
exports.IPC_Save_State = 'save_state';
export const IPC_Set_Config_Values = 'set_config_values';
export const IPC_Set_Config_Values_Reply = 'set_config_values_reply';
exports.IPC_Set_Config_Values = 'set_config_values';
exports.IPC_Set_Config_Values_Reply = 'set_config_values_reply';
export const IPC_Unmount_Drive = 'unmount_drive';
export const IPC_Unmount_Drive_Reply = 'unmount_drive_reply';
exports.IPC_Unmount_Drive = 'unmount_drive';
exports.IPC_Unmount_Drive_Reply = 'unmount_drive_reply';

View File

@@ -3,10 +3,11 @@ import styles from './Configuration.css';
import Box from '../../components/UI/Box/Box';
import Button from '../../components/UI/Button/Button';
import ConfigurationItem from '../../components/ConfigurationItem/ConfigurationItem';
import * as Constants from '../../constants';
import CSSModules from 'react-css-modules';
import Modal from '../../components/UI/Modal/Modal';
const Constants = require('../../constants');
let ipcRenderer = null;
if (!process.versions.hasOwnProperty('electron')) {
ipcRenderer = ((window && window.require) ? window.require('electron').ipcRenderer : null);

View File

@@ -1,4 +1,5 @@
.MountItems {
margin-top: 10px;
padding: 0;
margin: 0;
width: 100%;
}

View File

@@ -1,12 +1,10 @@
import React from 'react';
import {Component} from 'react';
import * as Constants from '../../constants';
import CSSModules from 'react-css-modules';
import styles from './MountItems.css';
import MountItem from '../../components/MountItem/MountItem';
import {IPC_Detect_Mounts} from "../../constants";
import {IPC_Mount_Drive} from "../../constants";
import {IPC_Unmount_Drive} from "../../constants";
const Constants = require('../../constants');
let ipcRenderer = null;
if (!process.versions.hasOwnProperty('electron')) {
@@ -50,7 +48,7 @@ class MountItems extends Component {
detectMounts = ()=> {
this.props.mountsBusy(true);
ipcRenderer.send(IPC_Detect_Mounts, {
ipcRenderer.send(Constants.IPC_Detect_Mounts, {
Directory: this.props.directory,
Version: this.props.version,
});
@@ -78,14 +76,14 @@ class MountItems extends Component {
this.props.mountsBusy(true);
if (mount) {
ipcRenderer.send(IPC_Mount_Drive, {
ipcRenderer.send(Constants.IPC_Mount_Drive, {
Directory: this.props.directory,
Location: location,
StorageType: storageType,
Version: this.props.version,
});
} else {
ipcRenderer.send(IPC_Unmount_Drive, {
ipcRenderer.send(Constants.IPC_Unmount_Drive, {
Directory: this.props.directory,
Location: location,
PID: pid,