OS X installation support
This commit is contained in:
51
electron.js
51
electron.js
@@ -310,7 +310,7 @@ ipcMain.on(Constants.IPC_Detect_Mounts, (event, data) => {
|
||||
|
||||
const setImage = (locations) => {
|
||||
if (os.platform() === 'win32' || os.platform() === 'linux') {
|
||||
let driveInUse = false;
|
||||
let driveInUse;
|
||||
for (const provider of Constants.PROVIDER_LIST) {
|
||||
driveInUse = locations[provider].length > 0;
|
||||
if (driveInUse)
|
||||
@@ -504,16 +504,45 @@ ipcMain.on(Constants.IPC_Install_Dependency, (event, data) => {
|
||||
});
|
||||
|
||||
ipcMain.on(Constants.IPC_Install_Upgrade, (event, data) => {
|
||||
helpers
|
||||
.executeAsync(data.Source)
|
||||
.then(()=> {
|
||||
mainWindow.close();
|
||||
})
|
||||
.catch(error => {
|
||||
standardIPCReply(event, Constants.IPC_Install_Upgrade_Reply, {
|
||||
Source: data.Source,
|
||||
}, error);
|
||||
});
|
||||
if (os.platform() === 'win32') {
|
||||
helpers
|
||||
.executeAsync(data.Source)
|
||||
.then(() => {
|
||||
closeApplication();
|
||||
})
|
||||
.catch(error => {
|
||||
standardIPCReply(event, Constants.IPC_Install_Upgrade_Reply, {
|
||||
Source: data.Source,
|
||||
}, error);
|
||||
});
|
||||
} else if (data.Source.toLocaleLowerCase().endsWith('.dmg')) {
|
||||
helpers
|
||||
.executeAsync('hdiutil', ['attach', data.Source])
|
||||
.then(() => {
|
||||
closeApplication();
|
||||
})
|
||||
.catch(error => {
|
||||
standardIPCReply(event, Constants.IPC_Install_Upgrade_Reply, {
|
||||
Source: data.Source,
|
||||
}, error);
|
||||
});
|
||||
} else if (data.Source.toLocaleLowerCase().endsWith('.appimage')) {
|
||||
// TODO Generate and execute script with delay
|
||||
/*helpers
|
||||
.executeAsync(data.Source)
|
||||
.then(() => {
|
||||
closeApplication();
|
||||
})
|
||||
.catch(error => {
|
||||
standardIPCReply(event, Constants.IPC_Install_Upgrade_Reply, {
|
||||
Source: data.Source,
|
||||
}, error);
|
||||
});*/
|
||||
} else {
|
||||
standardIPCReply(event, Constants.IPC_Install_Upgrade_Reply, {
|
||||
Source: data.Source,
|
||||
}, Error('Unsupported upgrade: ' + data.Source));
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.on(Constants.IPC_Mount_Drive, (event, data) => {
|
||||
|
||||
@@ -134,7 +134,7 @@ module.exports.executeAsync = (command, args=[]) => {
|
||||
reject(err, pid);
|
||||
} else {
|
||||
clearTimeout(timeout);
|
||||
setTimeout(()=>launchProcess(count, setTimeout(() => resolve(), 3000)), 1000);
|
||||
setTimeout(()=> launchProcess(count, setTimeout(() => resolve(), 3000)), 1000);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
197
src/App.js
197
src/App.js
@@ -153,6 +153,30 @@ class App extends Component {
|
||||
}
|
||||
};
|
||||
|
||||
extractFileNameFromURL = url => {
|
||||
const parts = url.split('/');
|
||||
return parts[parts.length - 1];
|
||||
};
|
||||
|
||||
extractRelease = (data) => {
|
||||
if (data.Success) {
|
||||
const selectedVersion = this.getSelectedVersion();
|
||||
ipcRenderer.send(Constants.IPC_Extract_Release, {
|
||||
Directory: Constants.DATA_LOCATIONS[this.props.platform],
|
||||
Source: data.Destination,
|
||||
Version: selectedVersion,
|
||||
});
|
||||
}
|
||||
|
||||
this.setState({
|
||||
DownloadActive: false,
|
||||
DownloadProgress: 0.0,
|
||||
DownloadingRelease: false,
|
||||
ExtractActive: data.Success,
|
||||
DownloadName: '',
|
||||
});
|
||||
};
|
||||
|
||||
getSelectedVersion = () => {
|
||||
return this.state.VersionLookup[this.state.ReleaseTypes[this.state.Release]][this.state.Version];
|
||||
};
|
||||
@@ -204,13 +228,10 @@ class App extends Component {
|
||||
|
||||
handleDependencyDownload = (url) => {
|
||||
if (ipcRenderer) {
|
||||
const items = url.split('/');
|
||||
const fileName = items[items.length - 1];
|
||||
|
||||
this.setState({
|
||||
DownloadActive: true,
|
||||
DownloadingDependency: true,
|
||||
DownloadName: fileName,
|
||||
DownloadName: this.extractFileNameFromURL(url),
|
||||
}, ()=> {
|
||||
ipcRenderer.send(Constants.IPC_Download_File, {
|
||||
Directory: Constants.DATA_LOCATIONS[this.props.platform],
|
||||
@@ -270,10 +291,11 @@ class App extends Component {
|
||||
DownloadingUpgrade: true,
|
||||
DownloadName: 'UI Upgrade',
|
||||
}, ()=> {
|
||||
const url = this.state.UpgradeData.urls[0];
|
||||
ipcRenderer.send(Constants.IPC_Download_File, {
|
||||
Directory: Constants.DATA_LOCATIONS[this.props.platform],
|
||||
Filename: this.props.platform === 'win32' ? 'upgrade.exe' : 'upgrade',
|
||||
URL: this.state.UpgradeData.urls[0],
|
||||
Filename: this.props.platform === 'win32' ? 'upgrade.exe' : this.extractFileNameFromURL(url),
|
||||
URL: url,
|
||||
});
|
||||
});
|
||||
} else {
|
||||
@@ -290,6 +312,37 @@ class App extends Component {
|
||||
});
|
||||
};
|
||||
|
||||
installDependency = data => {
|
||||
if (data.Success) {
|
||||
ipcRenderer.send(Constants.IPC_Install_Dependency, {
|
||||
Source: data.Destination,
|
||||
URL: data.URL,
|
||||
});
|
||||
}
|
||||
|
||||
this.setState({
|
||||
DownloadActive: false,
|
||||
DownloadProgress: 0.0,
|
||||
DownloadingDependency: data.Success,
|
||||
DownloadName: '',
|
||||
});
|
||||
};
|
||||
|
||||
installUpgrade = data => {
|
||||
if (data.Success) {
|
||||
ipcRenderer.send(Constants.IPC_Install_Upgrade, {
|
||||
Source: data.Destination,
|
||||
});
|
||||
} else {
|
||||
this.setState({
|
||||
DownloadActive: false,
|
||||
DownloadProgress: 0.0,
|
||||
DownloadingUpgrade: false,
|
||||
DownloadName: '',
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
notifyAutoMountProcessed = () => {
|
||||
this.setState({AutoMountProcessed: true});
|
||||
};
|
||||
@@ -330,49 +383,11 @@ class App extends Component {
|
||||
|
||||
onDownloadFileComplete = (event, arg) => {
|
||||
if (this.state.DownloadingRelease) {
|
||||
if (arg.data.Success) {
|
||||
const selectedVersion = this.getSelectedVersion();
|
||||
ipcRenderer.send(Constants.IPC_Extract_Release, {
|
||||
Directory: Constants.DATA_LOCATIONS[this.props.platform],
|
||||
Source: arg.data.Destination,
|
||||
Version: selectedVersion,
|
||||
});
|
||||
}
|
||||
|
||||
this.setState({
|
||||
DownloadActive: false,
|
||||
DownloadProgress: 0.0,
|
||||
DownloadingRelease: false,
|
||||
ExtractActive: arg.data.Success,
|
||||
DownloadName: '',
|
||||
});
|
||||
this.extractRelease(arg.data);
|
||||
} else if (this.state.DownloadingDependency) {
|
||||
if (arg.data.Success) {
|
||||
ipcRenderer.send(Constants.IPC_Install_Dependency, {
|
||||
Source: arg.data.Destination,
|
||||
URL: arg.data.URL,
|
||||
});
|
||||
}
|
||||
|
||||
this.setState({
|
||||
DownloadActive: false,
|
||||
DownloadProgress: 0.0,
|
||||
DownloadingDependency: arg.data.Success,
|
||||
DownloadName: '',
|
||||
});
|
||||
this.installDependency(arg.data);
|
||||
} else if (this.state.DownloadingUpgrade) {
|
||||
if (arg.data.Success) {
|
||||
ipcRenderer.send(Constants.IPC_Install_Upgrade, {
|
||||
Source: arg.data.Destination,
|
||||
});
|
||||
} else {
|
||||
this.setState({
|
||||
DownloadActive: false,
|
||||
DownloadProgress: 0.0,
|
||||
DownloadingUpgrade: false,
|
||||
DownloadName: '',
|
||||
});
|
||||
}
|
||||
this.installUpgrade(arg.data);
|
||||
} else {
|
||||
this.setState({
|
||||
DownloadActive: false,
|
||||
@@ -446,58 +461,60 @@ class App extends Component {
|
||||
});
|
||||
};
|
||||
|
||||
axios.get(Constants.RELEASES_URL)
|
||||
.then(response => {
|
||||
const versionLookup = {
|
||||
Alpha: response.data.Versions.Alpha[this.props.platform],
|
||||
Beta: response.data.Versions.Beta[this.props.platform],
|
||||
RC: response.data.Versions.RC[this.props.platform],
|
||||
Release: response.data.Versions.Release[this.props.platform],
|
||||
};
|
||||
const locationsLookup = {
|
||||
...response.data.Locations[this.props.platform],
|
||||
};
|
||||
axios
|
||||
.get(Constants.RELEASES_URL)
|
||||
.then(response => {
|
||||
const versionLookup = {
|
||||
Alpha: response.data.Versions.Alpha[this.props.platform],
|
||||
Beta: response.data.Versions.Beta[this.props.platform],
|
||||
RC: response.data.Versions.RC[this.props.platform],
|
||||
Release: response.data.Versions.Release[this.props.platform],
|
||||
};
|
||||
const locationsLookup = {
|
||||
...response.data.Locations[this.props.platform],
|
||||
};
|
||||
|
||||
window.localStorage.setItem('releases', JSON.stringify({
|
||||
LocationsLookup: locationsLookup,
|
||||
VersionLookup: versionLookup
|
||||
}));
|
||||
|
||||
doUpdate(locationsLookup, versionLookup);
|
||||
}).catch(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;
|
||||
window.localStorage.setItem('releases', JSON.stringify({
|
||||
LocationsLookup: locationsLookup,
|
||||
VersionLookup: versionLookup
|
||||
}));
|
||||
|
||||
doUpdate(locationsLookup, versionLookup);
|
||||
} else {
|
||||
this.setErrorState(error, null, true);
|
||||
}
|
||||
});
|
||||
}).catch(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 {
|
||||
this.setErrorState(error, null, true);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
onGrabUiReleasesReply = ()=> {
|
||||
axios.get(Constants.UI_RELEASES_URL)
|
||||
.then(response => {
|
||||
const data = response.data;
|
||||
if (data.Versions &&
|
||||
data.Versions[this.props.platform] &&
|
||||
(data.Versions[this.props.platform].length > 0) &&
|
||||
(data.Versions[this.props.platform][0] !== this.props.version)) {
|
||||
axios
|
||||
.get(Constants.UI_RELEASES_URL)
|
||||
.then(response => {
|
||||
const data = response.data;
|
||||
if (data.Versions &&
|
||||
data.Versions[this.props.platform] &&
|
||||
(data.Versions[this.props.platform].length > 0) &&
|
||||
(data.Versions[this.props.platform][0] !== this.props.version)) {
|
||||
this.setState({
|
||||
UpgradeAvailable: true,
|
||||
UpgradeDismissed: false,
|
||||
UpgradeData: data.Locations[this.props.platform][data.Versions[this.props.platform][0]],
|
||||
});
|
||||
}
|
||||
}).catch(() => {
|
||||
this.setState({
|
||||
UpgradeAvailable: true,
|
||||
UpgradeDismissed: false,
|
||||
UpgradeData: data.Locations[this.props.platform][data.Versions[this.props.platform][0]],
|
||||
UpgradeAvailable: false,
|
||||
UpgradeData: {},
|
||||
});
|
||||
}
|
||||
}).catch(() => {
|
||||
this.setState({
|
||||
UpgradeAvailable: false,
|
||||
UpgradeData: {},
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
onInstallDependencyReply = (event, arg) => {
|
||||
|
||||
Reference in New Issue
Block a user