Skip to content

Commit

Permalink
feat(neuron-ui): make the alert of lacking remote module more clear
Browse files Browse the repository at this point in the history
The electron app is required explicitly
  • Loading branch information
Keith-CY committed Oct 12, 2019
1 parent 5d56aab commit a36abba
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type ControllerResponse = SuccessFromController | FailureFromController
export const RemoteNotLoadError = {
status: 0 as 0,
message: {
content: 'remote is not supported',
content: 'The remote module is not found, please make sure the UI is running inside the Electron App',
},
}

Expand Down
17 changes: 10 additions & 7 deletions packages/neuron-ui/src/services/remote/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,28 @@ export * from './networks'
export * from './transactions'
export * from './skipDataAndType'

const REMOTE_MODULE_NOT_FOUND =
'The remote module is not found, please make sure the UI is running inside the Electron App'

export const getLocale = () => {
if (!window.remote) {
console.warn('remote is not supported')
console.warn(REMOTE_MODULE_NOT_FOUND)
return window.navigator.language
}
return window.remote.require('electron').app.getLocale()
}

export const getWinID = () => {
if (!window.remote) {
console.warn('remote is not supported')
console.warn(REMOTE_MODULE_NOT_FOUND)
return -1
}
return window.remote.getCurrentWindow().id
}

export const validateMnemonic = (mnemonic: string): boolean => {
if (!window.remote) {
console.warn('remote is not supported')
console.warn(REMOTE_MODULE_NOT_FOUND)
return true
}
const { validateMnemonic: remoteValidateMnemonic } = window.remote.require('./models/keys/mnemonic')
Expand All @@ -31,7 +34,7 @@ export const validateMnemonic = (mnemonic: string): boolean => {

export const generateMnemonic = (): string => {
if (!window.remote) {
console.warn('remote is not supported')
console.warn(REMOTE_MODULE_NOT_FOUND)
return ''
}
const { generateMnemonic: remoteGenerateMnemonic } = window.remote.require('./models/keys/key')
Expand All @@ -40,7 +43,7 @@ export const generateMnemonic = (): string => {

export const showMessage = (options: any, callback: Function) => {
if (!window.remote) {
console.warn('remote is not supported')
console.warn(REMOTE_MODULE_NOT_FOUND)
window.alert(options.message)
} else {
window.remote.require('electron').dialog.showMessageBox(options, callback)
Expand All @@ -49,7 +52,7 @@ export const showMessage = (options: any, callback: Function) => {

export const showErrorMessage = (title: string, content: string) => {
if (!window.remote) {
console.warn('remote is not supported')
console.warn(REMOTE_MODULE_NOT_FOUND)
window.alert(`${title}: ${content}`)
} else {
window.remote.require('electron').dialog.showErrorBox(title, content)
Expand All @@ -58,7 +61,7 @@ export const showErrorMessage = (title: string, content: string) => {

export const showOpenDialog = (opt: { title: string; message?: string; onUpload: Function }) => {
if (!window.remote) {
window.alert('remote is not supported')
window.alert(REMOTE_MODULE_NOT_FOUND)
}
const { onUpload, ...options } = opt
return window.remote.require('electron').dialog.showOpenDialog(
Expand Down
2 changes: 1 addition & 1 deletion packages/neuron-ui/src/services/subjects.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const FallbackSubject = {
subscribe: (args: any) => {
console.warn('remote is not supported')
console.warn('The remote module is not found, please make sure the UI is running inside the Electron App')
console.info(JSON.stringify(args))
return {
unsubscribe: () => {
Expand Down

0 comments on commit a36abba

Please sign in to comment.