Skip to content

Commit

Permalink
fix: Use platform file extension instead of .exe
Browse files Browse the repository at this point in the history
  • Loading branch information
cyperdark committed Oct 29, 2024
1 parent 27c0860 commit 60368d7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
7 changes: 3 additions & 4 deletions packages/common/utils/platforms.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export const platformResolver = (platform: string) => {
export function platformResolver(platform: string) {
let platformType = '';
let platformFileType = '';
let platformCommand = '';

switch (platform) {
case 'win32':
platformType = 'windows';
platformFileType = 'exe';
platformFileType = '.exe';
platformCommand = 'start ""';
break;

Expand All @@ -17,10 +17,9 @@ export const platformResolver = (platform: string) => {

case 'darwin':
platformType = 'macos';
platformFileType = 'macos';
platformCommand = 'open -R';
break;
}

return { platformType, platformFileType, platformCommand };
};
}
23 changes: 15 additions & 8 deletions packages/updater/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ import path from 'path';
// NOTE: _version.js packs with pkg support in tosu build
const currentVersion = require(process.cwd() + '/_version.js');

const platform = platformResolver(process.platform);

const fileDestination = path.join(getProgramPath(), 'update.zip');
const backupExecutablePath = path.join(getProgramPath(), 'tosu_old.exe');
const backupExecutablePath = path.join(
getProgramPath(),
`tosu_old${platform.platformFileType}`
);

const deleteNotLocked = async (filePath: string) => {
try {
Expand All @@ -36,9 +41,7 @@ export const checkUpdates = async () => {
wLogger.info('Checking updates');

try {
const { platformType } = platformResolver(process.platform);

if (platformType === '') {
if (platform.platformType === '') {
wLogger.warn(
`Unsupported platform (${process.platform}). Unable to run updater`
);
Expand Down Expand Up @@ -69,7 +72,7 @@ export const checkUpdates = async () => {
return new Error('Version the same');
}

return { assets, versionName, platformType };
return { assets, versionName };
} catch (exc) {
wLogger.error(`checkUpdates`, (exc as any).message);
wLogger.debug(exc);
Expand All @@ -88,7 +91,7 @@ export const autoUpdater = async () => {
return check;
}

const { assets, versionName, platformType } = check;
const { assets, versionName } = check;
if (versionName.includes(currentVersion)) {
wLogger.info(`You're using latest version v${currentVersion}`);

Expand All @@ -104,10 +107,14 @@ export const autoUpdater = async () => {
}

const findAsset = assets.find(
(r) => r.name.includes(platformType) && r.name.endsWith('.zip')
(r) =>
r.name.includes(platform.platformType) &&
r.name.endsWith('.zip')
);
if (!findAsset) {
wLogger.info(`Files to update not found (${platformType})`);
wLogger.info(
`Files to update not found (${platform.platformType})`
);
return 'noFiles';
}

Expand Down

0 comments on commit 60368d7

Please sign in to comment.