Skip to content

Commit 4ec2cb4

Browse files
committed
feat: manage update manually
1 parent c0d83d8 commit 4ec2cb4

File tree

5 files changed

+88
-58
lines changed

5 files changed

+88
-58
lines changed

package-lock.json

Lines changed: 19 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "electron-qa",
33
"private": true,
4-
"version": "0.0.2",
4+
"version": "0.0.1",
55
"description": "Electron updater E2E test",
66
"scripts": {
77
"start": "electron ./src/main.js",
@@ -19,13 +19,16 @@
1919
"type": "git",
2020
"url": "[email protected]:UltimateHackingKeyboard/electron-qa.git"
2121
},
22+
"dependencies": {
23+
"electron-updater": "4.2.5",
24+
"electron-is-dev": "1.2.0",
25+
"electron-log": "4.2.0",
26+
"electron-settings": "3.1.4"
27+
},
2228
"devDependencies": {
2329
"electron": "8.2.3",
2430
"electron-builder": "22.5.1",
25-
"electron-is-dev": "1.2.0",
2631
"electron-notarize": "0.3.0",
27-
"electron-settings": "3.1.4",
28-
"electron-updater": "4.2.5",
2932
"fs-extra": "8.1.0"
3033
}
3134
}

scripts/release.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
const exec = require('child_process').execSync
33

44
const TEST_BUILD = process.env.TEST_BUILD // set true if you would like to test on your local machine
5-
const DIR = process.env.DIR
65

76
// electron-builder security override.
87
// Need if wanna create test release build from PR
@@ -65,7 +64,6 @@ if (TEST_BUILD || gitTag) {
6564
prepareDistDir()
6665

6766
builder.build({
68-
dir: DIR,
6967
targets: target,
7068
config: {
7169
afterPack,
@@ -117,10 +115,7 @@ async function afterPack(context) {
117115
const launcherScript = path.join(__dirname, 'launcher-script.sh')
118116
const chromeSandbox = path.join(context.appOutDir, 'chrome-sandbox')
119117

120-
// rename uhk-agent to the-uhk-agent
121118
await fs.rename(sourceExecutable, targetExecutable)
122-
123-
// copy launcher script to uhk-agent
124119
await fs.copy(launcherScript, sourceExecutable)
125120
await fs.chmod(sourceExecutable, 0o755)
126121

@@ -137,7 +132,7 @@ async function afterSign(context) {
137132
const appName = context.packager.appInfo.productFilename
138133

139134
return await notarize({
140-
appBundleId: 'com.ultimategadgetlabs.agent',
135+
appBundleId: 'com.ultimategadgetlabs.electron-qa',
141136
appPath: `${appOutDir}/${appName}.app`,
142137
appleId: process.env.APPLE_ID,
143138
appleIdPassword: process.env.APPLE_ID_PASS,
@@ -158,5 +153,6 @@ function prepareDistDir() {
158153
const rootJson = fs.readJsonSync(path.join(__dirname, '../package.json'))
159154
const electronJson = fs.readJsonSync(path.join(__dirname, '../src/package.json'))
160155
electronJson.version = rootJson.version
156+
electronJson.dependencies = rootJson.dependencies
161157
fs.writeJsonSync(path.join(ELECTRON_BUILD_FOLDER, 'package.json'), electronJson, { spaces: 2 })
162158
}

src/index.html

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
.status.success {
2323
color: green;
2424
}
25+
26+
.d-none {
27+
display: none;
28+
}
2529
</style>
2630
</head>
2731
<body>
@@ -41,8 +45,11 @@ <h3>Auto update</h3>
4145
<div>
4246
<button type="submit">Save Settings</button>
4347
<button id="checkForUpdateBtn" type="button">Check for update</button>
48+
<button id="downloadUpdateBtn" class="d-none" type="button">Download update</button>
49+
<button id="quitAndUpdateBtn" class="d-none" type="button">Quit and update</button>
4450
</div>
4551
</form>
52+
4653
<div id="status" class="status">
4754

4855
</div>
@@ -53,8 +60,11 @@ <h3>Auto update</h3>
5360

5461
<script>
5562
const autoUpdateForm = document.getElementById('autoUpdateForm')
56-
const statusDiv = document.getElementById('status'
57-
)
63+
const statusDiv = document.getElementById('status')
64+
const checkForUpdateBtn = document.getElementById('checkForUpdateBtn')
65+
const downloadUpdateBtn = document.getElementById('downloadUpdateBtn')
66+
const quitAndUpdateBtn = document.getElementById('quitAndUpdateBtn')
67+
5868
ipcRenderer.on('app-settings', function processAppSettings(event, settings) {
5969
document.getElementById('versionPlaceHolder').innerText = settings.version
6070
setAutoUpdateForm(settings.autoUpdate)
@@ -64,6 +74,18 @@ <h3>Auto update</h3>
6474
statusDiv.innerText = status.message
6575
statusDiv.classList.remove('info', 'error', 'success')
6676
statusDiv.classList.add(status.type)
77+
78+
switch (status.event) {
79+
case 'update-available':
80+
checkForUpdateBtn.classList.add('d-none')
81+
downloadUpdateBtn.classList.remove('d-none')
82+
break;
83+
84+
case 'update-downloaded':
85+
downloadUpdateBtn.classList.add('d-none')
86+
quitAndUpdateBtn.classList.remove('d-none')
87+
break;
88+
}
6789
})
6890

6991
autoUpdateForm.addEventListener('submit', function submitAutoUpdateForm(event) {
@@ -73,15 +95,23 @@ <h3>Auto update</h3>
7395
ipcRenderer.send('save-settings', settings)
7496
})
7597

76-
document
77-
.getElementById('checkForUpdateBtn')
78-
.addEventListener('click', function checkForUpdate(event) {
98+
downloadUpdateBtn.addEventListener('click', function downloadUpdate(){
99+
ipcRenderer.send('download-update')
100+
downloadUpdateBtn.disabled = true
101+
})
102+
103+
quitAndUpdateBtn.addEventListener('click', function quitAndUpdate(){
104+
ipcRenderer.send('quit-update')
105+
})
106+
107+
checkForUpdateBtn.addEventListener('click', function checkForUpdate(event) {
79108
event.preventDefault()
80109

81110
const settings = getAutoUpdateSettingsFromForm()
82111
ipcRenderer.send('check-for-update', settings.preReleaseAllowed)
83112
})
84113

114+
85115
function getAutoUpdateSettingsFromForm() {
86116
const settings = {
87117
checkForUpdateAtStartup: false,

0 commit comments

Comments
 (0)