Skip to content

Commit

Permalink
Fix beta releases + portable
Browse files Browse the repository at this point in the history
  • Loading branch information
blarfoon committed Apr 21, 2021
1 parent d80d99e commit 6045e91
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 37 deletions.
20 changes: 17 additions & 3 deletions public/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ if (releaseChannelExists) {
if (releaseId === 1) {
allowUnstableReleases = true;
}
} else if (!releaseChannelExists && app.getVersion().includes('beta')) {
fss.writeFileSync(path.join(app.getPath('userData'), 'rChannel'), 1);
allowUnstableReleases = true;
}

if (
Expand Down Expand Up @@ -451,7 +454,12 @@ ipcMain.handle('show-window', () => {
}
});

ipcMain.handle('quit-app', () => {
ipcMain.handle('quit-app', async () => {
if (watcher) {
log.log('Stopping listener');
await watcher.stop();
watcher = null;
}
mainWindow.close();
mainWindow = null;
});
Expand Down Expand Up @@ -511,8 +519,13 @@ ipcMain.handle('openFileDialog', (e, filters) => {
});
});

ipcMain.handle('appRestart', () => {
ipcMain.handle('appRestart', async () => {
log.log('Restarting app');
if (watcher) {
log.log('Stopping listener');
await watcher.stop();
watcher = null;
}
app.relaunch();
mainWindow.close();
});
Expand Down Expand Up @@ -573,7 +586,8 @@ ipcMain.handle('calculateMurmur2FromPath', (e, filePath) => {

if (process.env.REACT_APP_RELEASE_TYPE === 'setup') {
autoUpdater.autoDownload = false;
autoUpdater.allowDowngrade = !allowUnstableReleases;
autoUpdater.allowDowngrade =
!allowUnstableReleases && app.getVersion().includes('beta');
autoUpdater.allowPrerelease = allowUnstableReleases;
autoUpdater.setFeedURL({
owner: 'gorilla-devs',
Expand Down
3 changes: 1 addition & 2 deletions src/app/desktop/components/SystemNavbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const SystemNavbar = () => {
});
} else if (
process.platform === 'win32' &&
process.env.REACT_APP_RELEASE_TYPE === 'portable'
process.env.REACT_APP_RELEASE_TYPE !== 'setup'
) {
dispatch(checkForPortableUpdates())
.then(v => dispatch(updateUpdateAvailable(Boolean(v))))
Expand Down Expand Up @@ -75,7 +75,6 @@ const SystemNavbar = () => {
useEffect(() => {
if (process.env.NODE_ENV === 'development') return;
setTimeout(() => {
console.log(process.env.REACT_APP_RELEASE_TYPE);
checkForUpdates();
setInterval(() => {
checkForUpdates();
Expand Down
63 changes: 31 additions & 32 deletions src/common/reducers/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2821,46 +2821,44 @@ export const initLatestMods = instanceName => {
};
};

export const getAppLatestVersion = () => {
return async () => {
const { data: latestReleases } = await axios.get(
'https://api.github.com/repos/gorilla-devs/GDLauncher/releases'
);
export const getAppLatestVersion = async () => {
const { data: latestReleases } = await axios.get(
'https://api.github.com/repos/gorilla-devs/GDLauncher/releases?per_page=10'
);

const latestPrerelease = latestReleases.find(v => v.prerelease);
const latestStablerelease = latestReleases.find(v => !v.prerelease);
const latestPrerelease = latestReleases.find(v => v.prerelease);
const latestStablerelease = latestReleases.find(v => !v.prerelease);

const appData = parse(await ipcRenderer.invoke('getAppdataPath'));
let releaseChannel = 0;
const appData = parse(await ipcRenderer.invoke('getAppdataPath'));
let releaseChannel = 0;

try {
const rChannel = await fs.readFile(
path.join(appData, 'gdlauncher_next', 'rChannel')
);
releaseChannel = rChannel.toString();
} catch {
// swallow error
}
try {
const rChannel = await fs.readFile(
path.join(appData, 'gdlauncher_next', 'rChannel')
);
releaseChannel = rChannel.toString();
} catch {
// swallow error
}

const v = await ipcRenderer.invoke('getAppVersion');
const v = await ipcRenderer.invoke('getAppVersion');

const installedVersion = parse(v);
const isAppUpdated = r => !lt(installedVersion, parse(r.tag_name));
const installedVersion = parse(v);
const isAppUpdated = r => !lt(installedVersion, parse(r.tag_name));

// If we're on beta but the release channel is stable, return latest stable to force an update
if (v.includes('beta') && releaseChannel === 0) {
return latestStablerelease;
}
// If we're on beta but the release channel is stable, return latest stable to force an update
if (v.includes('beta') && releaseChannel === 0) {
return latestStablerelease;
}

if (!isAppUpdated(latestStablerelease)) {
return latestStablerelease;
}
if (!isAppUpdated(latestPrerelease) && releaseChannel !== 0) {
return latestPrerelease;
}
if (!isAppUpdated(latestStablerelease)) {
return latestStablerelease;
}
if (!isAppUpdated(latestPrerelease) && releaseChannel !== 0) {
return latestPrerelease;
}

return false;
};
return false;
};

export const checkForPortableUpdates = () => {
Expand All @@ -2878,6 +2876,7 @@ export const checkForPortableUpdates = () => {
const { data: latestManifest } = await axios.get(
`${baseAssetUrl}/${process.platform}_latest.json`
);
console.log('inside', latestVersion);
// Cleanup all files that are not required for the update
await makeDir(tempFolder);

Expand Down

0 comments on commit 6045e91

Please sign in to comment.