-
-
Notifications
You must be signed in to change notification settings - Fork 513
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support npmmirror(China) mirror and switch mirror (#991)
- Loading branch information
1 parent
f19b774
commit 4737544
Showing
12 changed files
with
317 additions
and
19 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
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,82 @@ | ||
import { observer } from 'mobx-react'; | ||
import * as React from 'react'; | ||
import { AppState } from '../state'; | ||
import { Callout, InputGroup, Radio, RadioGroup } from '@blueprintjs/core'; | ||
import { FormEvent } from 'react'; | ||
import { Mirrors, Sources } from '../mirror-constants'; | ||
|
||
interface MirrorSettingsProps { | ||
appState: AppState; | ||
} | ||
|
||
type IMirrorSettingsState = Mirrors; | ||
|
||
/** | ||
* Settings electron mirror | ||
* | ||
* @class MirrorSettings | ||
* @extends {React.Component<MirrorSettingsProps, IMirrorSettingsState>} | ||
*/ | ||
@observer | ||
export class MirrorSettings extends React.Component< | ||
MirrorSettingsProps, | ||
IMirrorSettingsState | ||
> { | ||
constructor(props: MirrorSettingsProps) { | ||
super(props); | ||
|
||
this.changeSourceType = this.changeSourceType.bind(this); | ||
} | ||
|
||
private modifyMirror(isNightly: boolean, value: string) { | ||
this.props.appState.electronMirror.sources.CUSTOM[ | ||
isNightly ? 'electronNightlyMirror' : 'electronMirror' | ||
] = value; | ||
} | ||
|
||
private changeSourceType(e: FormEvent<HTMLInputElement>) { | ||
this.props.appState.electronMirror.sourceType = (e.target as HTMLInputElement) | ||
.value as Sources; | ||
} | ||
|
||
private get notCustomSource() { | ||
return this.props.appState.electronMirror.sourceType !== 'CUSTOM'; | ||
} | ||
|
||
public render() { | ||
const { sourceType, sources } = this.props.appState.electronMirror; | ||
const electronMirrorLabel = `If you don't have access to Electron's GitHub releases, you can tell Fiddle to download Electron binaries from an alternate source.`; | ||
|
||
return ( | ||
<div> | ||
<h4>Electron Mirrors</h4> | ||
<Callout> | ||
<RadioGroup | ||
label={electronMirrorLabel} | ||
inline={true} | ||
onChange={this.changeSourceType} | ||
selectedValue={sourceType} | ||
> | ||
<Radio label="Default" value="DEFAULT" /> | ||
<Radio label="China" value="CHINA" /> | ||
<Radio label="Custom" value="CUSTOM" /> | ||
</RadioGroup> | ||
<InputGroup | ||
value={sources[sourceType].electronMirror} | ||
disabled={this.notCustomSource} | ||
onChange={(e) => { | ||
this.modifyMirror(false, e.target.value); | ||
}} | ||
/> | ||
<InputGroup | ||
value={sources[sourceType].electronNightlyMirror} | ||
disabled={this.notCustomSource} | ||
onChange={(e) => { | ||
this.modifyMirror(true, e.target.value); | ||
}} | ||
/> | ||
</Callout> | ||
</div> | ||
); | ||
} | ||
} |
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,26 @@ | ||
const sources = { | ||
DEFAULT: { | ||
electronMirror: 'https://github.com/electron/electron/releases/download/', | ||
electronNightlyMirror: | ||
'https://github.com/electron/nightlies/releases/download/', | ||
}, | ||
CHINA: { | ||
electronMirror: 'https://npmmirror.com/mirrors/electron/', | ||
electronNightlyMirror: 'https://npmmirror.com/mirrors/electron-nightly/', | ||
}, | ||
CUSTOM: { | ||
electronMirror: '', | ||
electronNightlyMirror: '', | ||
}, | ||
}; | ||
|
||
export const ELECTRON_MIRROR = { | ||
sourceType: 'DEFAULT' as keyof typeof sources, | ||
sources, | ||
}; | ||
|
||
export type Sources = keyof typeof sources; | ||
export type Mirrors = { | ||
electronMirror: string; | ||
electronNightlyMirror: string; | ||
}; |
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 |
---|---|---|
|
@@ -12,6 +12,7 @@ import { EditorMosaic } from '../../src/renderer/editor-mosaic'; | |
import { objectDifference } from '../utils'; | ||
import { BisectorMock } from './bisector'; | ||
import { VersionsMock } from './electron-versions'; | ||
import { ELECTRON_MIRROR } from '../../src/renderer/mirror-constants'; | ||
|
||
export class StateMock { | ||
@observable public acceleratorsToBlock: BlockableAccelerator[] = []; | ||
|
@@ -55,6 +56,7 @@ export class StateMock { | |
@observable public versions: Record<string, RunnableVersion>; | ||
@observable public versionsToShow: RunnableVersion[] = []; | ||
@observable public packageAuthor = 'electron<[email protected]>'; | ||
@observable public electronMirror = ELECTRON_MIRROR; | ||
@observable public isBisectCommandShowing = false; | ||
|
||
public Bisector = new BisectorMock(); | ||
|
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
40 changes: 40 additions & 0 deletions
40
tests/renderer/components/__snapshots__/settings-general-mirror-spec.tsx.snap
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,40 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`MirrorSettings component renders 1`] = ` | ||
<div> | ||
<h4> | ||
Electron Mirrors | ||
</h4> | ||
<Blueprint3.Callout> | ||
<Blueprint3.RadioGroup | ||
inline={true} | ||
label="If you don't have access to Electron's GitHub releases, you can tell Fiddle to download Electron binaries from an alternate source." | ||
onChange={[Function]} | ||
selectedValue="DEFAULT" | ||
> | ||
<Blueprint3.Radio | ||
label="Default" | ||
value="DEFAULT" | ||
/> | ||
<Blueprint3.Radio | ||
label="China" | ||
value="CHINA" | ||
/> | ||
<Blueprint3.Radio | ||
label="Custom" | ||
value="CUSTOM" | ||
/> | ||
</Blueprint3.RadioGroup> | ||
<Blueprint3.InputGroup | ||
disabled={true} | ||
onChange={[Function]} | ||
value="https://github.com/electron/electron/releases/download/" | ||
/> | ||
<Blueprint3.InputGroup | ||
disabled={true} | ||
onChange={[Function]} | ||
value="https://github.com/electron/nightlies/releases/download/" | ||
/> | ||
</Blueprint3.Callout> | ||
</div> | ||
`; |
Oops, something went wrong.