File tree 7 files changed +63
-18
lines changed
7 files changed +63
-18
lines changed Original file line number Diff line number Diff line change @@ -55,6 +55,7 @@ import {
55
55
import { setupClipboardEvents } from './clipboard'
56
56
import { checkForUpdate } from 'shared/data/slices/update'
57
57
import path from 'path'
58
+ import { setupOneTimeFetchEvent } from './one-time-fetch'
58
59
59
60
makeAppWithSingleInstanceLock ( async ( ) => {
60
61
app . setName ( APP_CONFIG . TITLE )
@@ -90,6 +91,7 @@ makeAppWithSingleInstanceLock(async () => {
90
91
setupFileSystemEvents ( )
91
92
setupClipboardEvents ( )
92
93
setupLogEvents ( )
94
+ setupOneTimeFetchEvent ( )
93
95
buildMenu ( )
94
96
95
97
store . subscribe ( ( ) => {
@@ -149,11 +151,12 @@ function buildMenu() {
149
151
store . dispatch ( selectJob ( job ) )
150
152
} ,
151
153
onRunJob : async ( job ) => {
152
- store . dispatch (
153
- runJob ( {
154
- ...job ,
155
- } )
156
- )
154
+ MainWindow ( ) . then ( ( w ) => w . webContents . send ( 'run-job' ) )
155
+ // store.dispatch(
156
+ // runJob({
157
+ // ...job,
158
+ // })
159
+ // )
157
160
} ,
158
161
onRemoveJob : async ( job ) => {
159
162
store . dispatch ( removeJob ( job ) )
Original file line number Diff line number Diff line change
1
+ // fetch a resource and return the result to the renderer
2
+ // this is meant as a one-off utility for special cases
3
+ import { ipcMain } from 'electron'
4
+ import { IPC_EVENT_oneTimeFetch } from '../shared/main-renderer-events'
5
+ import fetch from 'node-fetch'
6
+
7
+ async function oneTimeFetch ( url ) {
8
+ if ( url . length == 0 ) return false
9
+
10
+ let res = await fetch ( url )
11
+ if ( res ) {
12
+ return res . json ( )
13
+ }
14
+ else {
15
+ return null
16
+ }
17
+ }
18
+
19
+ function setupOneTimeFetchEvent ( ) {
20
+ // comes from the renderer process (ipcRenderer.send())
21
+ ipcMain . on ( IPC_EVENT_oneTimeFetch , async ( event , payload ) => {
22
+ let res = await oneTimeFetch ( payload )
23
+ event . sender . send ( IPC_EVENT_oneTimeFetch , res )
24
+ } )
25
+ }
26
+ export { setupOneTimeFetchEvent , oneTimeFetch }
Original file line number Diff line number Diff line change @@ -44,6 +44,7 @@ const API = {
44
44
sniffEncoding : ipcs . sniffEncoding ,
45
45
copyToClipboard : ipcs . copyToClipboard ,
46
46
log : ipcs . log ,
47
+ oneTimeFetch : ipcs . oneTimeFetch ,
47
48
// we can add on to this API and restructure it as we move more commands to the redux side
48
49
store : {
49
50
dispatch,
Original file line number Diff line number Diff line change @@ -15,3 +15,4 @@ export * from './file/save'
15
15
export * from './file/unzip'
16
16
17
17
export * from './log'
18
+ export * from './oneTimeFetch'
Original file line number Diff line number Diff line change
1
+ import { ipcRenderer } from 'electron'
2
+ import * as events from 'shared/main-renderer-events'
3
+
4
+ // get JSON data from an arbitrary endpoint
5
+ export function oneTimeFetch ( url ) {
6
+ return new Promise < JSON > ( ( resolve , reject ) => {
7
+ ipcRenderer . send ( events . IPC_EVENT_oneTimeFetch , url )
8
+ ipcRenderer . once ( events . IPC_EVENT_oneTimeFetch , ( event , res : JSON ) => {
9
+ resolve ( res )
10
+ } )
11
+ } )
12
+ }
Original file line number Diff line number Diff line change
1
+ const { App } = window
2
+
1
3
// default message
2
4
let defaultSponsorshipMessage = {
3
5
active : true ,
@@ -9,18 +11,17 @@ let defaultSponsorshipMessage = {
9
11
10
12
async function updateSponsorshipMessage ( ) {
11
13
// fetch the latest sponsorship message
12
- // try {
13
- // let sponsorshipData = await window.fetch(
14
- // 'https://dl.daisy.org/tools/sponsorship.json'
15
- // )
16
- // if (sponsorshipData) {
17
- // return sponsorshipData['PipelineApp']['en']
18
- // } else {
19
- // return defaultSponsorshipMessage
20
- // }
21
- // } catch (err) {
22
- // return defaultSponsorshipMessage
23
- // }
24
- return defaultSponsorshipMessage
14
+ try {
15
+ let sponsorshipData = await App . oneTimeFetch (
16
+ 'https://dl.daisy.org/tools/sponsorship.json'
17
+ )
18
+ if ( sponsorshipData ) {
19
+ return sponsorshipData [ 'PipelineApp' ] [ 'en' ]
20
+ } else {
21
+ return defaultSponsorshipMessage
22
+ }
23
+ } catch ( err ) {
24
+ return defaultSponsorshipMessage
25
+ }
25
26
}
26
27
export { defaultSponsorshipMessage , updateSponsorshipMessage }
Original file line number Diff line number Diff line change @@ -6,3 +6,4 @@ export const IPC_EVENT_pathExists = 'IPC_EVENT_pathExists'
6
6
export const IPC_EVENT_openInBrowser = 'IPC_EVENT_openInBrowser'
7
7
export const IPC_EVENT_sniffEncoding = 'IPC_EVENT_sniffEncoding'
8
8
export const IPC_EVENT_log = 'IPC_EVENT_log'
9
+ export const IPC_EVENT_oneTimeFetch = 'IPC_EVENT_oneTimeFetch'
You can’t perform that action at this time.
0 commit comments