Skip to content

Commit

Permalink
Update xo and apply corrections (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
mquevill authored Oct 8, 2021
1 parent a51f0fd commit 972e0e8
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 22 deletions.
19 changes: 10 additions & 9 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ declare namespace electronDl {
transferredBytes: number;
totalBytes: number;
}

interface File {
filename: string,
path: string,
fileSize: number,
mimeType: string,
url: string
filename: string;
path: string;
fileSize: number;
mimeType: string;
url: string;
}

interface Options {
Expand Down Expand Up @@ -68,10 +68,10 @@ declare namespace electronDl {
Optional callback that receives an object containing information about the progress of the current download item.
*/
readonly onProgress?: (progress: Progress) => void;

/**
Optional callback that receives an object containing information about the combined progress of all download items done within any registered window.
Each time a new download is started, the next callback will include it. The progress percentage could therefore become smaller again.
This callback provides the same data that is used for the progress bar on the app icon.
*/
Expand All @@ -81,7 +81,7 @@ declare namespace electronDl {
Optional callback that receives the [download item](https://electronjs.org/docs/api/download-item) for which the download has been cancelled.
*/
readonly onCancel?: (item: DownloadItem) => void;

/**
Optional callback that receives an object with information about an item that has been completed. It is called for each completed item.
*/
Expand Down Expand Up @@ -112,6 +112,7 @@ declare namespace electronDl {
}
}

// eslint-disable-next-line no-redeclare
declare const electronDl: {
/**
Register the helper for all windows.
Expand Down
9 changes: 3 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const getFilenameFromMime = (name, mime) => {

const majorElectronVersion = () => {
const version = process.versions.electron.split('.');
return parseInt(version[0], 10);
return Number.parseInt(version[0], 10);
};

const getWindowFromBrowserView = webContents => {
Expand Down Expand Up @@ -75,11 +75,7 @@ function registerListener(session, options, callback = () => {}) {
const filename = item.getFilename();
const name = path.extname(filename) ? filename : getFilenameFromMime(filename, item.getMimeType());

if (options.overwrite) {
filePath = path.join(directory, name);
} else {
filePath = unusedFilename.sync(path.join(directory, name));
}
filePath = options.overwrite ? path.join(directory, name) : unusedFilename.sync(path.join(directory, name));
}

const errorMessage = options.errorMessage || 'The download of {filename} was interrupted';
Expand Down Expand Up @@ -147,6 +143,7 @@ function registerListener(session, options, callback = () => {}) {
session.removeListener('will-download', listener);
}

// eslint-disable-next-line unicorn/prefer-switch
if (state === 'cancelled') {
if (typeof options.onCancel === 'function') {
options.onCancel(item);
Expand Down
4 changes: 2 additions & 2 deletions lib/samples.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ const {v4: uuidv4} = require('uuid');

const fixtureDir = path.join(__dirname, '../mock/fixtures');

const setup = async numFiles => {
const setup = async numberFiles => {
const promises = [];
const files = [];

while (files.length < numFiles) {
while (files.length < numberFiles) {
const filename = `${uuidv4()}.zip`;
promises.push(cpFile(path.join(fixtureDir, 'electron-master.zip'), path.join(fixtureDir, filename)));
files.push(filename);
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@
"pify": "^4.0.1",
"spectron": "^9.0.0",
"tsd": "^0.17.0",
"typescript": "^4.4.3",
"uuid": "^8.3.2",
"xo": "^0.25.3"
"xo": "^0.39.0"
},
"xo": {
"envs": [
Expand Down
8 changes: 4 additions & 4 deletions run.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';
const electron = require('electron');
const minimist = require('minimist');
const samples = require('./lib/samples');
const server = require('./lib/server');
const samples = require('./lib/samples.js');
const server = require('./lib/server.js');
const electronDl = require('.');

electronDl();
Expand All @@ -27,8 +27,8 @@ const argv = minimist(process.argv.slice(2));
downloadThroughput: 1024 * 1024
});

const numSampleFiles = 'files' in argv ? argv.files : 5;
const files = await samples.setup(numSampleFiles);
const numberSampleFiles = 'files' in argv ? argv.files : 5;
const files = await samples.setup(numberSampleFiles);
await win.loadURL(`http://localhost:8080/index.html?files=${JSON.stringify(files)}`);
})();

Expand Down

0 comments on commit 972e0e8

Please sign in to comment.