Skip to content

Commit

Permalink
fix: Validate installed app
Browse files Browse the repository at this point in the history
  • Loading branch information
cyaiox committed Sep 13, 2024
1 parent 12fb821 commit 6573053
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 22 deletions.
18 changes: 0 additions & 18 deletions packages/main/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,25 +135,7 @@ export async function decompressFile(sourcePath: string, destinationPath: string
}
}

export function isAppInstalled(appPath: string, version: string): boolean {
if (!fs.existsSync(appPath)) {
return false;
}

if (!fs.existsSync(join(appPath, 'version.json'))) {
return false;
}

const versionFile = join(appPath, 'version.json');
const versionData = JSON.parse(fs.readFileSync(versionFile, 'utf8'));
return versionData[version] !== undefined;
}

export function isAppUpdated(appPath: string, version: string): boolean {
if (!isAppInstalled(appPath, version)) {
return false;
}

const versionFile = join(appPath, 'version.json');
const versionData = JSON.parse(fs.readFileSync(versionFile, 'utf8'));
return versionData.version === version;
Expand Down
8 changes: 4 additions & 4 deletions packages/main/src/modules/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { app, BrowserWindow, ipcMain } from 'electron';
import { download } from 'electron-dl';
import log from 'electron-log/main';
import { Analytics, IPC_EVENTS, IPC_EVENT_DATA_TYPE, ANALYTICS_EVENT, IPC_HANDLERS, getErrorMessage } from '#shared';
import { getAppBasePath, decompressFile, getOSName, isAppInstalled, isAppUpdated, PLATFORM, getAppVersion } from '../helpers';
import { getAppBasePath, decompressFile, getOSName, isAppUpdated, PLATFORM, getAppVersion } from '../helpers';
import { getUserId } from './config';

const EXPLORER_PATH = join(getAppBasePath(), 'Explorer');
Expand Down Expand Up @@ -40,11 +40,11 @@ function getExplorerBinPath(version?: string): string {
}

export function isExplorerInstalled(_event: Electron.IpcMainInvokeEvent, version: string) {
return isAppInstalled(getExplorerBinPath(version), version);
return fs.existsSync(getExplorerBinPath(version));
}

export function isExplorerUpdated(_event: Electron.IpcMainInvokeEvent, version: string) {
return isAppUpdated(getExplorerBinPath(version), version);
export function isExplorerUpdated(event: Electron.IpcMainInvokeEvent, version: string) {
return isExplorerInstalled(event, version) && isAppUpdated(EXPLORER_PATH, version);
}

export async function downloadExplorer(event: Electron.IpcMainInvokeEvent, url: string) {
Expand Down

0 comments on commit 6573053

Please sign in to comment.