Skip to content

Commit a2c63d8

Browse files
committed
1.0.3
1 parent a267c5b commit a2c63d8

File tree

4 files changed

+103
-33
lines changed

4 files changed

+103
-33
lines changed

build/notarize.js

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,77 @@
1-
require('dotenv').config();
21
const { notarize } = require('electron-notarize');
32
const path = require('path');
3+
const fs = require('fs');
4+
const jsYaml = require('js-yaml');
5+
6+
function findPackageJsonPath() {
7+
let dirName = process.cwd();
8+
9+
while(dirName) {
10+
const packageJsonFilePath = path.join(dirName, 'package.json');
11+
if (fs.existsSync(packageJsonFilePath)) {
12+
return packageJsonFilePath;
13+
} else if (dirName === '/') {
14+
break;
15+
}
16+
dirName = path.dirname(dirName);
17+
}
18+
return undefined;
19+
}
20+
21+
function getAppId(context) {
22+
// Try to get the appId from the packager
23+
const config = context.packager.info._configuration;
24+
if (config && config.appId) {
25+
console.log('Found appId in packager');
26+
return config.appId;
27+
}
28+
29+
// Try to get the appId from the builder-effective-config.yml file
30+
const builderEffectiveConfigPath = path.join(context.outDir, 'builder-effective-config.yaml');
31+
if (fs.existsSync(builderEffectiveConfigPath)) {
32+
const builderEffectiveConfigText = fs.readFileSync(builderEffectiveConfigPath);
33+
const builderEffectiveConfig = jsYaml.load(builderEffectiveConfigText);
34+
if (builderEffectiveConfig['appId']) {
35+
console.log('Found appId in %s', builderEffectiveConfigPath);
36+
return builderEffectiveConfig['appId'];
37+
}
38+
}
39+
40+
// Try to get the appId from the package.json file
41+
const packageJsonFilePath = findPackageJsonPath();
42+
if (packageJsonFilePath) {
43+
try {
44+
const packageJson = require(packageJsonFilePath);
45+
if (packageJson['build'] && packageJson['build']['appId']) {
46+
console.log('Found appId in %s', packageJsonFilePath);
47+
return packageJson['build']['appId'];
48+
}
49+
} catch (err) {
50+
// swallow the error
51+
console.log('Failed to read %s: %s', packageJsonFilePath, err);
52+
}
53+
}
54+
55+
// finally, check the APP_ID environment variable
56+
if (process.env.APP_ID) {
57+
console.log('Found appId in APP_ID environment variable');
58+
return process.env.APP_ID;
59+
}
60+
throw new Error('Unable to find the application ID');
61+
}
462

563
exports.default = async function notarizing(context) {
664
const { electronPlatformName, appOutDir } = context;
7-
if (electronPlatformName !== 'darwin') {
65+
if (electronPlatformName !== 'darwin' || process.env.CSC_IDENTITY_AUTO_DISCOVERY === 'false') {
866
return;
967
}
1068

69+
const appId = getAppId(context);
1170
const appName = context.packager.appInfo.productFilename;
12-
const appPath = path.normalize(path.join(process.cwd(), 'dist', 'mac', `${appName}.app`));
13-
console.log('calling notarize with appPath = %s', appPath);
14-
return await notarize({
15-
appBundleId: 'com.github.robertpatrick.electronupdaterexample',
71+
const appPath = path.normalize(path.join(context.outDir, 'mac', `${appName}.app`));
72+
console.log('calling notarize for appId = %s with appPath = %s', appId, appPath);
73+
return notarize({
74+
appBundleId: appId,
1675
appPath: appPath,
1776
appleId: process.env.APPLEID,
1877
appleIdPassword: process.env.APPLEIDPASS,

main.js

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// This is free and unencumbered software released into the public domain.
22
// See LICENSE for details
33

4-
const {app, BrowserWindow, Menu, protocol, ipcMain} = require('electron');
4+
const {app, BrowserWindow, dialog, Menu, protocol, ipcMain} = require('electron');
55
if (process.platform === 'linux') {
66
let proxy;
77
if (process.env.HTTPS_PROXY) {
@@ -96,6 +96,7 @@ function createDefaultWindow() {
9696
win.loadURL(`file://${__dirname}/version.html#v${app.getVersion()}`);
9797
return win;
9898
}
99+
99100
autoUpdater.on('checking-for-update', () => {
100101
sendStatusToWindow('Checking for update...');
101102
})
@@ -138,9 +139,9 @@ app.on('window-all-closed', () => {
138139
// This will immediately download an update, then install when the
139140
// app quits.
140141
//-------------------------------------------------------------------
141-
app.on('ready', function() {
142-
autoUpdater.checkForUpdatesAndNotify();
143-
});
142+
// app.on('ready', function() {
143+
// autoUpdater.checkForUpdatesAndNotify();
144+
// });
144145

145146
//-------------------------------------------------------------------
146147
// Auto updates - Option 2 - More control
@@ -153,19 +154,29 @@ app.on('ready', function() {
153154
// Uncomment any of the below events to listen for them. Also,
154155
// look in the previous section to see them being used.
155156
//-------------------------------------------------------------------
156-
// app.on('ready', function() {
157-
// autoUpdater.checkForUpdates();
158-
// });
159-
// autoUpdater.on('checking-for-update', () => {
160-
// })
161-
// autoUpdater.on('update-available', (info) => {
162-
// })
163-
// autoUpdater.on('update-not-available', (info) => {
164-
// })
165-
// autoUpdater.on('error', (err) => {
166-
// })
167-
// autoUpdater.on('download-progress', (progressObj) => {
168-
// })
169-
// autoUpdater.on('update-downloaded', (info) => {
170-
// autoUpdater.quitAndInstall();
171-
// })
157+
autoUpdater.autoDownload = false;
158+
autoUpdater.autoInstallOnAppQuit = false;
159+
160+
app.on('ready', function() {
161+
autoUpdater.checkForUpdates().then();
162+
});
163+
164+
autoUpdater.on('checking-for-update', (foo) => {
165+
log.info('got checking-for-update event: %s', JSON.stringify(foo));
166+
});
167+
autoUpdater.on('update-available', (info) => {
168+
log.info('got update-available event: %s', JSON.stringify(info));
169+
})
170+
autoUpdater.on('update-not-available', (info) => {
171+
log.info('got update-not-available event: %s', JSON.stringify(info));
172+
})
173+
autoUpdater.on('error', (err) => {
174+
log.info('got error event: %s', JSON.stringify(err));
175+
})
176+
autoUpdater.on('download-progress', (progressObj) => {
177+
log.info('got download-progress event: %s', JSON.stringify(progressObj));
178+
})
179+
autoUpdater.on('update-downloaded', (info) => {
180+
log.info('got update-downloaded event: %s', JSON.stringify(info));
181+
autoUpdater.autoInstallOnAppQuit = true;
182+
})

package-lock.json

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

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "electron-updater-example",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"main": "main.js",
55
"description": "electron-updater example project",
66
"author": {
@@ -12,10 +12,10 @@
1212
"publish": "electron-builder --config electron-builder.yaml -p always"
1313
},
1414
"devDependencies": {
15-
"dotenv": "^9.0.2",
1615
"electron": "^14.0.1",
1716
"electron-builder": "^22.11.7",
18-
"electron-notarize": "^1.1.1"
17+
"electron-notarize": "^1.1.1",
18+
"js-yaml": "^4.1.0"
1919
},
2020
"dependencies": {
2121
"electron-log": "^4.4.1",

0 commit comments

Comments
 (0)