Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace download-chromium with puppeteer-core #178

Merged
merged 3 commits into from
Jan 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"csv-parse": "^4.14.1",
"csv-stringify": "^5.5.3",
"direct-vuex": "^0.12.0",
"download-chromium": "^2.2.0",
"electron-log": "^4.1.1",
"emittery": "^0.7.1",
"googleapis": "^59.0.0",
Expand All @@ -44,6 +43,7 @@
"lodash": "^4.17.15",
"moment": "^2.24.0",
"node-machine-id": "^1.1.12",
"puppeteer-core": "^5.5.0",
"vue": "^2.6.10",
"vue-router": "^3.1.6",
"vuetify": "^2.2.22",
Expand All @@ -61,6 +61,7 @@
"@types/jest": "^26.0.10",
"@types/lodash": "^4.14.158",
"@types/node": "12",
"@types/puppeteer-core": "^5.4.0",
"@types/webdriverio": "^4.0.0",
"@typescript-eslint/eslint-plugin": "^3.7.0",
"@typescript-eslint/parser": "^3.2.0",
Expand Down
6 changes: 5 additions & 1 deletion src/backend/eventEmitters/EventEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ export enum AccountType {
}

export enum AccountStatus {
IDLE, PENDING, IN_PROGRESS, DONE, ERROR
IDLE = 'IDLE',
PENDING = 'PENDING',
IN_PROGRESS = 'IN_PROGRESS',
DONE = 'DONE',
ERROR = 'ERROR'
}
Comment on lines 28 to 34
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More readable in the console, so why not


export class BudgetTrackingEvent {
Expand Down
30 changes: 17 additions & 13 deletions src/backend/import/downloadChromium.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
import download, { OnProgress } from 'download-chromium';
import { getPuppeteerConfig } from 'israeli-bank-scrapers-core';
import puppeteer from 'puppeteer-core';

const getIntegerPercent = (callback: OnProgress): OnProgress => {
type PuppeteerProgressCallback = (downloadBytes: number, totalBytes: number) => void
type PercentCallback = (percent: number) => void

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

return ({ percent, ...rest }) => {
const p = Math.floor(percent * 10);
return (downloadBytes: number, totalBytes: number) => {
const p = Math.floor((downloadBytes / totalBytes) * 100);
if (p > prevPercent) {
prevPercent = p;
callback({ percent: p, ...rest });
callback(p);
}
};
};

const revision = getPuppeteerConfig().chromiumRevision;

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

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

downloadProm = download({
revision,
installPath,
onProgress: onProgress && getIntegerPercent(onProgress),
log: true
});
const progressCallback = onProgress && getIntegerPercent(onProgress);

const browserFetcher = puppeteer.createBrowserFetcher({ path: installPath });
downloadProm = browserFetcher.download(revision, progressCallback)
.then(({ executablePath }) => executablePath);

downloadProm.then(() => downloadProm = null);

return downloadProm;
}
2 changes: 1 addition & 1 deletion src/backend/import/importTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const TRANSACTION_STATUS_COMPLETED = 'completed';
export async function scrapeFinancialAccountsAndFetchTransactions(scrapingConfig: ScrapingConfig, startDate: Date, eventPublisher: EventPublisher) {
const companyIdToTransactions: Record<string, EnrichedTransaction[]> = {};

const dowloadedChrome = await getChrome(userDataPath, ({ percent }) => emitChromeDownload(eventPublisher, percent));
const dowloadedChrome = await getChrome(userDataPath, (percent) => emitChromeDownload(eventPublisher, percent));

const accountsToScrape = scrapingConfig.accountsToScrape.filter((accountToScrape) => accountToScrape.active !== false);
const scrapingPromises = accountsToScrape.map(async (accountToScrape) => {
Expand Down
17 changes: 0 additions & 17 deletions src/types/download-chromium.d.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/ui/components/app/exporters/YnabExporter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
type="password"
label="Access Token"
outlined
:rules="rules.required"
:rules="[rules.required]"
@change="changed = true"
/>
<v-text-field
v-model="exporter.options.budgetId"
label="Budget id"
outlined
:rules="rules.required"
:rules="[rules.required]"
Comment on lines +17 to +24
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix bug

@change="changed = true"
/>
<ynab-account-mapping-table
Expand Down
Loading