-
Notifications
You must be signed in to change notification settings - Fork 147
Check update instead of force download #49
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
Open
jhen0409
wants to merge
10
commits into
MarshallOfSound:main
Choose a base branch
from
jhen0409:check-update
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8a9a732
Check update instead of force download
jhen0409 948290a
Add tests for checkUpdate option
jhen0409 12fb889
Merge branch 'master' into check-update
jhen0409 a2f7cb3
fetchData: reassign to new object for result
jhen0409 6354a40
needUpdate: Remove reject statement
jhen0409 64e5ea3
needUpdate: log message if status is error-invalidAppId
jhen0409 bcd1cfe
Merge branch 'master' into check-update
MarshallOfSound af92396
Merge branch 'master' into check-update
jhen0409 8e9415e
Merge branch 'master' into check-update
MarshallOfSound 747e897
Merge branch 'master' into check-update
MarshallOfSound File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,23 @@ | ||
| import { parseString } from 'xml2js'; | ||
| import { fetchData } from './utils'; | ||
|
|
||
| export default (chromeStoreID, currentVersion) => new Promise((resolve, reject) => | ||
| fetchData( | ||
| `https://clients2.google.com/service/update2/crx?x=id%3D${chromeStoreID}%26uc&prodversion=32`, | ||
| ).then((res) => { | ||
| if (res.statusCode === 200) { | ||
| parseString(res.body, (err, result) => { | ||
| const app = result.gupdate.app[0].$; | ||
| if (app.status !== 'ok') return resolve(false); | ||
|
|
||
| const { status, version: newestVersion } = result.gupdate.app[0].updatecheck[0].$; | ||
| if (status !== 'ok') return resolve(false); | ||
|
|
||
| if (newestVersion !== currentVersion) return resolve(true); | ||
| return resolve(false); | ||
| }); | ||
| } else { | ||
| reject(`Failed to check current version of ${chromeStoreID}.`); | ||
| } | ||
| }), | ||
| ); | ||
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -9,20 +9,34 @@ export const getPath = () => { | |
| }; | ||
|
|
||
| // Use https.get fallback for Electron < 1.4.5 | ||
| const { net } = (remote || electron); | ||
| const { net } = remote || electron; | ||
| const request = net ? net.request : https.get; | ||
|
|
||
| export const downloadFile = (from, to) => new Promise((resolve, reject) => { | ||
| const req = request(from); | ||
| const sendRequest = url => new Promise((resolve, reject) => { | ||
| const req = request(url); | ||
| req.on('response', (res) => { | ||
| // Shouldn't handle redirect with `electron.net`, this is for https.get fallback | ||
| if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) { | ||
| return downloadFile(res.headers.location, to) | ||
| .then(resolve) | ||
| .catch(reject); | ||
| return sendRequest(res.headers.location); | ||
| } | ||
| res.pipe(fs.createWriteStream(to)).on('close', resolve); | ||
| resolve(res); | ||
| }); | ||
| req.on('error', reject); | ||
| req.end(); | ||
| }); | ||
|
|
||
| export const downloadFile = (from, to) => new Promise((resolve, reject) => | ||
| sendRequest(from) | ||
| .then(res => res.pipe(fs.createWriteStream(to)).on('close', resolve)) | ||
| .catch(reject), | ||
| ); | ||
|
|
||
| export const fetchData = url => new Promise((resolve, reject) => | ||
| sendRequest(url) | ||
| .then((res) => { | ||
| let body = ''; | ||
| res.on('data', (chunk) => { body += chunk; }); | ||
| res.on('end', () => resolve(Object.assign(res, { body }))); | ||
|
||
| }) | ||
| .catch(reject), | ||
| ); | ||
This file contains hidden or 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 hidden or 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,19 @@ | ||
| // Pre-run | ||
| import chai from 'chai'; | ||
| import chaiAsPromised from 'chai-as-promised'; | ||
| import { given } from 'mocha-testdata'; | ||
|
|
||
| // Actual Test Imports | ||
| import needUpdate from '../src/needUpdate'; | ||
| import knownExtensions from './testdata/knownExtensions'; | ||
|
|
||
| chai.use(chaiAsPromised); | ||
| chai.should(); | ||
|
|
||
| describe('Extension Update Checker', () => { | ||
| describe('when given a valid extension ID', () => { | ||
| given(...knownExtensions).it('should need to update (with different version)', item => | ||
| needUpdate(item.id, '0.0.0').should.become(true), | ||
| ); | ||
| }); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should log something and
resolve(true)just in case? Rejecting this promise will simply mess with developers, we can try to help them out as much as possible 👍Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked the API again, it should always response status
200if there is no any network errors, so I just remove the line, and log message if responseapp.statusiserror-invalidAppId.