-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #172 from brafdlog/baruchiro/issue170
Bug: ENOTDIR, not a directory
- Loading branch information
Showing
7 changed files
with
73 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { app, remote } from 'electron'; | ||
|
||
const App = app || remote.app; | ||
|
||
export const userDataPath = App.getPath('userData'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,31 @@ | ||
import download from 'download-chromium'; | ||
import download, { OnProgress } from 'download-chromium'; | ||
import { getPuppeteerConfig } from 'israeli-bank-scrapers-core'; | ||
|
||
type OnProgress = ({ percent, transferred, total }) => void | ||
type DownloadOptions = { | ||
platform: string, | ||
revision: string, | ||
log: boolean, | ||
onProgress: OnProgress | ||
installPath: string | ||
} | ||
type Download = (options: Partial<DownloadOptions>) => string | ||
const getIntegerPercent = (callback: OnProgress): OnProgress => { | ||
let prevPercent = -1; | ||
|
||
return ({ percent, ...rest }) => { | ||
const p = Math.floor(percent * 10); | ||
if (p > prevPercent) { | ||
prevPercent = p; | ||
callback({ percent: p, ...rest }); | ||
} | ||
}; | ||
}; | ||
|
||
const revision = getPuppeteerConfig().chromiumRevision; | ||
|
||
let downloadProm: ReturnType<typeof download>; | ||
|
||
export default async function downloadChromium(installPath?: string, onProgress?: OnProgress) { | ||
const func: Download = download; | ||
return func({ | ||
if (downloadProm) return downloadProm; | ||
|
||
downloadProm = download({ | ||
revision, | ||
installPath, | ||
onProgress, | ||
onProgress: onProgress && getIntegerPercent(onProgress), | ||
log: true | ||
}); | ||
|
||
return downloadProm; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
declare module 'download-chromium' { | ||
type Progress = { | ||
percent: number, | ||
transferred: number, | ||
total: number | ||
} | ||
export type OnProgress = (progress: Progress) => void; | ||
type DownloadOptions = { | ||
platform: string, | ||
revision: string, | ||
log: boolean, | ||
onProgress: OnProgress | ||
installPath: string | ||
} | ||
function download(options: Partial<DownloadOptions>): Promise<string> | ||
export default download | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
import { tmpdir } from 'os'; | ||
|
||
export const ipcRenderer = { | ||
on: jest.fn(), | ||
send: jest.fn(), | ||
}; | ||
|
||
export const app = { | ||
getPath: jest.fn().mockReturnValue(tmpdir()) | ||
}; |