Skip to content
This repository was archived by the owner on Jun 5, 2019. It is now read-only.

Commit a72bc29

Browse files
committed
Adds missing files from refactor. Time for tests I guess.
1 parent f6847bc commit a72bc29

File tree

2 files changed

+112
-0
lines changed

2 files changed

+112
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { BrowserWindow } from 'electron'
2+
import { join } from 'path'
3+
import { format } from 'url'
4+
5+
// default dimensions
6+
const DIMENSIONS = { width: 600, height: 500, minWidth: 450, minHeight: 450 }
7+
8+
/**
9+
* Creates the main window.
10+
*
11+
* @param appPath The path to the bundle root.
12+
* @return The main BrowserWindow.
13+
*/
14+
export function createMainWindow(appPath: string) {
15+
const window = new BrowserWindow({
16+
...DIMENSIONS,
17+
show: false,
18+
useContentSize: true,
19+
titleBarStyle: 'hidden'
20+
})
21+
22+
// load entry html page in the renderer.
23+
window.loadURL(
24+
format({
25+
pathname: join(appPath, 'out/index.html'),
26+
protocol: 'file:',
27+
slashes: true
28+
})
29+
)
30+
31+
// only appear once we've loaded
32+
window.webContents.on('did-finish-load', () => {
33+
window.show()
34+
window.focus()
35+
})
36+
37+
return window
38+
}

src/main/updater/updater.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { autoUpdater } from 'electron-updater'
2+
import { ProgressInfo } from 'electron-builder-http/out/ProgressCallbackTransform'
3+
import * as log from 'electron-log'
4+
import * as isDev from 'electron-is-dev'
5+
6+
/**
7+
* Should we peform the auto-update check?
8+
*/
9+
const shouldCheck = !isDev
10+
11+
/*
12+
# Testing In Development
13+
14+
You may want to enable this in dev-mode the ensure everything
15+
is working properly. To do this, you'll need to have a config
16+
file called "dev-app-update.yml" in the project's root.
17+
18+
If you're shipping via S3 or another provider, please the
19+
[electron-builder docs](https://github.com/electron-userland/electron-builder/wiki/Publishing-Artifacts).
20+
21+
# Example File
22+
23+
```yml
24+
provider: 'github'
25+
repo: 'electron-starter'
26+
owner: 'skellock'
27+
```
28+
29+
Heads up: dev-app-update.yml is in the .gitignore file.
30+
*/
31+
32+
/**
33+
* Setup the auto-update capabilities.
34+
*
35+
* @param app The electron app.
36+
*/
37+
export function createUpdater(app: Electron.App): void {
38+
// jet if we shoulldn't be here
39+
if (!shouldCheck) return
40+
41+
// configure the autoUpdater's logger
42+
autoUpdater.logger = log
43+
44+
// fires when the app is ready
45+
app.on('ready', () => {
46+
autoUpdater.checkForUpdates()
47+
})
48+
49+
autoUpdater.on('checking-for-update', () => {
50+
log.info('checking for update')
51+
})
52+
53+
autoUpdater.on('update-available', info => {
54+
log.info('update available')
55+
})
56+
57+
autoUpdater.on('update-not-available', info => {
58+
log.info('update not available')
59+
})
60+
61+
autoUpdater.on('error', err => {
62+
log.error('error updating', err.message)
63+
})
64+
65+
autoUpdater.on('download-progress', (progressObj: ProgressInfo) => {
66+
log.info(`${progressObj.percent}%`)
67+
})
68+
69+
// fires when an update has been downloaded
70+
autoUpdater.on('update-downloaded', info => {
71+
log.info('update downloaded')
72+
autoUpdater.quitAndInstall()
73+
})
74+
}

0 commit comments

Comments
 (0)