Skip to content

Commit 12f35ea

Browse files
committed
fixed electron-builder
1 parent 549cd39 commit 12f35ea

File tree

22 files changed

+219
-140
lines changed

22 files changed

+219
-140
lines changed

.travis.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ osx_image: xcode9.2
44
language: node_js
55
node_js: "8"
66

7+
cache:
8+
directories:
9+
- node_modules
10+
- $HOME/.cache/electron
11+
- $HOME/.cache/electron-builder
12+
713
install:
814
- |
915
security create-keychain -p travis build.keychain
@@ -19,3 +25,6 @@ install:
1925
notifications:
2026
email: false
2127

28+
branches:
29+
except:
30+
- "/^v\\d+\\.\\d+\\.\\d+$/"

packages/graphql-playground-electron/package.json

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
"description": "GraphQL IDE for better development workflows (GraphQL Subscriptions, interactive docs & collaboration)",
77
"version": "v1.3.13",
88
"author": {
9-
"name": "Graphcool",
10-
"email": "[email protected]",
11-
"url": "https://www.graph.cool"
9+
"name": "Graphcool"
1210
},
1311
"main": "lib/main",
1412
"build": {
@@ -20,28 +18,11 @@
2018
"win": {
2119
"icon": "static/icons/icon.ico"
2220
},
23-
"nsis": {
24-
"oneClick": false,
25-
"perMachine": true,
26-
"allowElevation": true,
27-
"allowToChangeInstallationDirectory": true,
28-
"runAfterFinish": false
29-
},
3021
"linux": {
31-
"category": "DeveloperTools",
22+
"category": "Development",
3223
"target": [
33-
{
34-
"target": "deb",
35-
"arch": [
36-
"x64"
37-
]
38-
},
39-
{
40-
"target": "AppImage",
41-
"arch": [
42-
"x64"
43-
]
44-
}
24+
"AppImage",
25+
"deb"
4526
]
4627
},
4728
"files": [
@@ -66,7 +47,8 @@
6647
"build:ts": "rimraf lib && tsc",
6748
"build:webpack": "rimraf ./dist && NODE_ENV=production GRAPHQL_ENDPOINT=$BACKEND_ADDR/system webpack --config webpack.config.build.js && cp -r static/* dist",
6849
"build": "npm run build:ts && npm run build:webpack && cp -r dist lib && rimraf ./build:electron",
69-
"release": "npm run build && electron-builder -lmw",
50+
"release": "npm run build && electron-builder",
51+
"release:all": "npm run build && electron-builder -lmw",
7052
"release:mac": "npm run build && electron-builder -m",
7153
"release:win": "npm run build && electron-builder -w",
7254
"release:linux": "npm run build && electron-builder -l",
@@ -91,11 +73,13 @@
9173
"test-quick"
9274
],
9375
"dependencies": {
76+
"@types/ms": "^0.7.30",
9477
"classnames": "^2.2.5",
9578
"date-fns": "^1.29.0",
9679
"electron-is-dev": "^0.3.0",
9780
"electron-localshortcut": "^2.0.2",
9881
"electron-log": "^2.2.13",
82+
"electron-squirrel-startup": "^1.0.0",
9983
"electron-updater": "^2.17.6",
10084
"find-up": "^2.1.0",
10185
"graphcool-styles": "^0.2.5",
@@ -106,6 +90,7 @@
10690
"js-yaml": "^3.10.0",
10791
"lodash.merge": "^4.6.0",
10892
"minimist": "^1.2.0",
93+
"ms": "^2.1.1",
10994
"query-string": "^5.0.1",
11095
"react": "^16.2.0",
11196
"react-dom": "^16.2.0",
@@ -136,7 +121,7 @@
136121
"concurrently": "^3.5.1",
137122
"css-loader": "^0.23.1",
138123
"electron": "^1.7.10",
139-
"electron-builder": "19.45.5",
124+
"electron-builder": "^19.49.2",
140125
"electron-devtools-installer": "^2.2.3",
141126
"extract-text-webpack-plugin": "^2.0.0-beta.3",
142127
"file-loader": "^0.11.2",

packages/graphql-playground-electron/src/main/index.ts

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,17 @@ import {
1010
} from 'electron'
1111
import * as queryString from 'query-string'
1212
import * as fs from 'fs'
13-
import dev = require('electron-is-dev')
14-
import { autoUpdater } from 'electron-updater'
1513
import { log } from '../shared/utils'
1614
import { buildTemplate } from './menu'
1715
import { createWindow } from './createWindow'
1816
import { WindowContext } from './types'
17+
import { startUpdates } from './updates'
18+
import squirrelStartup = require('electron-squirrel-startup')
19+
20+
// Immediately quit the app if squirrel is launching it
21+
if (squirrelStartup) {
22+
app.quit()
23+
}
1924

2025
const windowContext: WindowContext = {
2126
readyWindowsPromises: {},
@@ -64,6 +69,10 @@ app.on('open-file', (event, filePath) => {
6469
forceSend('OpenSelectedFile', filePath, filePath)
6570
})
6671

72+
ipcMain.on('online-status-changed', (event, status) => {
73+
process.env.CONNECTION = status
74+
})
75+
6776
ipcMain.on('async', (event, arg) => {
6877
const focusedWindow = BrowserWindow.getFocusedWindow()
6978
if (focusedWindow) {
@@ -83,19 +92,18 @@ ipcMain.on('cwd', (event, msg) => {
8392
app.on('ready', () => {
8493
createWindow(windowContext)
8594

86-
if (!dev) {
87-
const logger = require('electron-log')
88-
logger.transports.file.level = 'info'
89-
autoUpdater.logger = logger
95+
startUpdates()
96+
// const logger = require('electron-log')
97+
// logger.transports.file.level = 'info'
98+
// autoUpdater.logger = logger
9099

91-
forceSend('SettingsRequest', '')
100+
// forceSend('SettingsRequest', '')
92101

93-
ipcMain.once('SettingsResponse', (event, settingsString) => {
94-
log.info('settings', settingsString)
95-
autoUpdater.allowPrerelease = getBetaUpdates(settingsString)
96-
autoUpdater.checkForUpdatesAndNotify()
97-
})
98-
}
102+
// ipcMain.once('SettingsResponse', (event, settingsString) => {
103+
// log.info('settings', settingsString)
104+
// autoUpdater.allowPrerelease = getBetaUpdates(settingsString)
105+
// autoUpdater.checkForUpdatesAndNotify()
106+
// })
99107

100108
const menu = Menu.buildFromTemplate(buildTemplate(windowContext))
101109
Menu.setApplicationMenu(menu)
@@ -170,13 +178,13 @@ async function forceSend(channel: string, arg: string, byPath?: string) {
170178
window.webContents.send(channel, arg)
171179
}
172180

173-
function getBetaUpdates(settingsString: string | undefined): boolean {
174-
try {
175-
const settings = JSON.parse(settingsString)
176-
return !!settings['general.betaUpdates']
177-
} catch (e) {
178-
//
179-
}
181+
// function getBetaUpdates(settingsString: string | undefined): boolean {
182+
// try {
183+
// const settings = JSON.parse(settingsString)
184+
// return !!settings['general.betaUpdates']
185+
// } catch (e) {
186+
// //
187+
// }
180188

181-
return false
182-
}
189+
// return false
190+
// }
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { shell, Notification } from 'electron'
2+
3+
export const notify = ({ title, body, url, onClick }) => {
4+
const notification = new Notification({
5+
title,
6+
body,
7+
silent: true,
8+
})
9+
10+
if (url || onClick) {
11+
notification.on('click', () => {
12+
if (onClick) {
13+
return onClick()
14+
}
15+
16+
shell.openExternal(url)
17+
})
18+
}
19+
20+
notification.show()
21+
console.log(`[Notification] ${title}: ${body}`)
22+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { app, autoUpdater } from 'electron'
2+
import ms = require('ms')
3+
import dev = require('electron-is-dev')
4+
5+
const setUpdateURL = () => {
6+
const server = 'https://hazel-server-ppbimurjwk.now.sh/update'
7+
autoUpdater.setFeedURL(`${server}/${process.platform}/${app.getVersion()}`)
8+
}
9+
10+
const checkForUpdates = () => {
11+
if (process.env.CONNECTION === 'offline') {
12+
// Try again after half an hour
13+
setTimeout(checkForUpdates, ms('30m'))
14+
return
15+
}
16+
17+
// Ensure we're pulling from the correct channel
18+
try {
19+
setUpdateURL()
20+
} catch (err) {
21+
// Retry later if setting the update URL failed
22+
return
23+
}
24+
25+
// Then ask the server for updates
26+
autoUpdater.checkForUpdates()
27+
}
28+
29+
const startAppUpdates = () => {
30+
autoUpdater.on('error', error => {
31+
// Report errors to console. We can't report
32+
// to Slack and restart here, because it will
33+
// cause the app to never start again
34+
console.error(error)
35+
36+
// Then check again for update after 15 minutes
37+
setTimeout(checkForUpdates, ms('15m'))
38+
})
39+
40+
// Check for app update after startup
41+
setTimeout(checkForUpdates, ms('10s'))
42+
43+
autoUpdater.on('update-downloaded', () => {
44+
autoUpdater.quitAndInstall()
45+
app.quit()
46+
})
47+
48+
autoUpdater.on('checking-for-update', () => {
49+
console.log('Checking for app updates...')
50+
})
51+
52+
autoUpdater.on('update-available', () => {
53+
console.log('Found update for the app! Downloading...')
54+
})
55+
56+
autoUpdater.on('update-not-available', () => {
57+
console.log('No updates found. Checking again in 5 minutes...')
58+
setTimeout(checkForUpdates, ms('5m'))
59+
})
60+
}
61+
62+
export const startUpdates = () => {
63+
if (process.platform === 'linux') {
64+
return
65+
}
66+
67+
if (!dev) {
68+
startAppUpdates()
69+
}
70+
}

0 commit comments

Comments
 (0)