Skip to content

Commit

Permalink
Fix: artifact name and download chromium (#605)
Browse files Browse the repository at this point in the history
This pull request includes fixes for two issues.

The first fix creates a constant artifact names (without version) to
hold a stable link to the latest download.

The second fix resolves an issue with the resolution of the chromium
build-id.

Additionally, the pull request includes some code changes related to
logging for the quitAndInstall function.
  • Loading branch information
baruchiro authored Oct 14, 2024
1 parent 3a3bb10 commit 782f834
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
2 changes: 2 additions & 0 deletions electron-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ directories:
output: dist
buildResources: buildResources

artifactName: '${productName}.${ext}'

files:
- packages/**/dist/**

Expand Down
24 changes: 19 additions & 5 deletions packages/main/src/backend/import/downloadChromium.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { Browser, install } from '@puppeteer/browsers';
import { Browser, detectBrowserPlatform, install, resolveBuildId } from '@puppeteer/browsers';
import os from 'os';
import logger from '/@/logging/logger';

type PuppeteerProgressCallback = (downloadBytes: number, totalBytes: number) => void;
type PercentCallback = (percent: number) => void;

let isCached = true;
const getIntegerPercent = (callback: PercentCallback): PuppeteerProgressCallback => {
isCached = false;
let prevPercent = -1;

return (downloadBytes: number, totalBytes: number) => {
Expand All @@ -16,23 +19,34 @@ const getIntegerPercent = (callback: PercentCallback): PuppeteerProgressCallback
};
};

const revision = '1364960'; // getPuppeteerConfig().chromiumRevision; see https://github.com/puppeteer/puppeteer/issues/8203#issuecomment-1535088987

let downloadProm: ReturnType<typeof downloadChromium> | null = null;

export default async function downloadChromium(installPath: string, onProgress?: PercentCallback): Promise<string> {
if (downloadProm) return downloadProm;

const progressCallback = onProgress && getIntegerPercent(onProgress);

const platform = detectBrowserPlatform();
if (!platform) {
throw new Error(`Cannot download a binary for the provided platform: ${os.platform()} (${os.arch()})`);
}
const buildId = await resolveBuildId(Browser.CHROMIUM, platform, 'latest');

logger.log(`Browser: ${Browser.CHROMIUM}, Platform: ${platform}, Tag: stable, BuildId: ${buildId}`);

downloadProm = install({
cacheDir: installPath,
browser: Browser.CHROMIUM,
buildId: revision,
buildId,
downloadProgressCallback: progressCallback,
}).then(({ executablePath }) => {
downloadProm = null;
logger.log('Chromium downloaded to', executablePath);
if (!isCached) {
logger.log('Chromium downloaded to', executablePath);
} else {
logger.log('Chromium cached at', executablePath);
}
isCached = true;
return executablePath;
});

Expand Down
6 changes: 3 additions & 3 deletions packages/main/src/backend/import/importTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ export async function scrapeFinancialAccountsAndFetchTransactions(
) {
let chromiumPath: string;

console.log('Scraping financial accounts and fetching transactions');
logger.log('Scraping financial accounts and fetching transactions');

if (scrapingConfig.chromiumPath) {
console.log('Using provided chromium path', scrapingConfig.chromiumPath);
logger.log('Using provided chromium path', scrapingConfig.chromiumPath);
chromiumPath = scrapingConfig.chromiumPath;
} else {
console.log('Downloading chromium');
logger.log('Downloading chromium');
chromiumPath = await getChrome(userDataPath, (percent) => emitChromeDownload(eventPublisher, percent));
}

Expand Down
1 change: 1 addition & 0 deletions packages/main/src/handlers/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ export const downloadUpdate = async () =>
});

export const quitAndInstall = () => {
logger.info('Quitting and installing update');
setImmediate(() => autoUpdater.quitAndInstall());
};
1 change: 1 addition & 0 deletions packages/preload/src/eventsBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export async function showSaveDialog() {
}

export async function quitAndInstall() {
console.log('preload invoking quitAndInstall');
return electron.ipcRenderer.invoke('quitAndInstall');
}

Expand Down

0 comments on commit 782f834

Please sign in to comment.