OS X installation support

This commit is contained in:
Scott E. Graves
2018-12-11 10:31:04 -06:00
parent 29a72f4707
commit e603894e2d
3 changed files with 148 additions and 102 deletions

View File

@@ -310,7 +310,7 @@ ipcMain.on(Constants.IPC_Detect_Mounts, (event, data) => {
const setImage = (locations) => { const setImage = (locations) => {
if (os.platform() === 'win32' || os.platform() === 'linux') { if (os.platform() === 'win32' || os.platform() === 'linux') {
let driveInUse = false; let driveInUse;
for (const provider of Constants.PROVIDER_LIST) { for (const provider of Constants.PROVIDER_LIST) {
driveInUse = locations[provider].length > 0; driveInUse = locations[provider].length > 0;
if (driveInUse) if (driveInUse)
@@ -504,16 +504,45 @@ ipcMain.on(Constants.IPC_Install_Dependency, (event, data) => {
}); });
ipcMain.on(Constants.IPC_Install_Upgrade, (event, data) => { ipcMain.on(Constants.IPC_Install_Upgrade, (event, data) => {
if (os.platform() === 'win32') {
helpers helpers
.executeAsync(data.Source) .executeAsync(data.Source)
.then(()=> { .then(() => {
mainWindow.close(); closeApplication();
}) })
.catch(error => { .catch(error => {
standardIPCReply(event, Constants.IPC_Install_Upgrade_Reply, { standardIPCReply(event, Constants.IPC_Install_Upgrade_Reply, {
Source: data.Source, Source: data.Source,
}, error); }, 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) => { ipcMain.on(Constants.IPC_Mount_Drive, (event, data) => {

View File

@@ -134,7 +134,7 @@ module.exports.executeAsync = (command, args=[]) => {
reject(err, pid); reject(err, pid);
} else { } else {
clearTimeout(timeout); clearTimeout(timeout);
setTimeout(()=>launchProcess(count, setTimeout(() => resolve(), 3000)), 1000); setTimeout(()=> launchProcess(count, setTimeout(() => resolve(), 3000)), 1000);
} }
}); });

View File

@@ -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 = () => { getSelectedVersion = () => {
return this.state.VersionLookup[this.state.ReleaseTypes[this.state.Release]][this.state.Version]; return this.state.VersionLookup[this.state.ReleaseTypes[this.state.Release]][this.state.Version];
}; };
@@ -204,13 +228,10 @@ class App extends Component {
handleDependencyDownload = (url) => { handleDependencyDownload = (url) => {
if (ipcRenderer) { if (ipcRenderer) {
const items = url.split('/');
const fileName = items[items.length - 1];
this.setState({ this.setState({
DownloadActive: true, DownloadActive: true,
DownloadingDependency: true, DownloadingDependency: true,
DownloadName: fileName, DownloadName: this.extractFileNameFromURL(url),
}, ()=> { }, ()=> {
ipcRenderer.send(Constants.IPC_Download_File, { ipcRenderer.send(Constants.IPC_Download_File, {
Directory: Constants.DATA_LOCATIONS[this.props.platform], Directory: Constants.DATA_LOCATIONS[this.props.platform],
@@ -270,10 +291,11 @@ class App extends Component {
DownloadingUpgrade: true, DownloadingUpgrade: true,
DownloadName: 'UI Upgrade', DownloadName: 'UI Upgrade',
}, ()=> { }, ()=> {
const url = this.state.UpgradeData.urls[0];
ipcRenderer.send(Constants.IPC_Download_File, { ipcRenderer.send(Constants.IPC_Download_File, {
Directory: Constants.DATA_LOCATIONS[this.props.platform], Directory: Constants.DATA_LOCATIONS[this.props.platform],
Filename: this.props.platform === 'win32' ? 'upgrade.exe' : 'upgrade', Filename: this.props.platform === 'win32' ? 'upgrade.exe' : this.extractFileNameFromURL(url),
URL: this.state.UpgradeData.urls[0], URL: url,
}); });
}); });
} else { } 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 = () => { notifyAutoMountProcessed = () => {
this.setState({AutoMountProcessed: true}); this.setState({AutoMountProcessed: true});
}; };
@@ -330,49 +383,11 @@ class App extends Component {
onDownloadFileComplete = (event, arg) => { onDownloadFileComplete = (event, arg) => {
if (this.state.DownloadingRelease) { if (this.state.DownloadingRelease) {
if (arg.data.Success) { this.extractRelease(arg.data);
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: '',
});
} else if (this.state.DownloadingDependency) { } else if (this.state.DownloadingDependency) {
if (arg.data.Success) { this.installDependency(arg.data);
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: '',
});
} else if (this.state.DownloadingUpgrade) { } else if (this.state.DownloadingUpgrade) {
if (arg.data.Success) { this.installUpgrade(arg.data);
ipcRenderer.send(Constants.IPC_Install_Upgrade, {
Source: arg.data.Destination,
});
} else {
this.setState({
DownloadActive: false,
DownloadProgress: 0.0,
DownloadingUpgrade: false,
DownloadName: '',
});
}
} else { } else {
this.setState({ this.setState({
DownloadActive: false, DownloadActive: false,
@@ -446,7 +461,8 @@ class App extends Component {
}); });
}; };
axios.get(Constants.RELEASES_URL) axios
.get(Constants.RELEASES_URL)
.then(response => { .then(response => {
const versionLookup = { const versionLookup = {
Alpha: response.data.Versions.Alpha[this.props.platform], Alpha: response.data.Versions.Alpha[this.props.platform],
@@ -479,7 +495,8 @@ class App extends Component {
}; };
onGrabUiReleasesReply = ()=> { onGrabUiReleasesReply = ()=> {
axios.get(Constants.UI_RELEASES_URL) axios
.get(Constants.UI_RELEASES_URL)
.then(response => { .then(response => {
const data = response.data; const data = response.data;
if (data.Versions && if (data.Versions &&