Skip to content

Commit

Permalink
fix(app-shell): Update Electron and add macOS app notarization (#4011)
Browse files Browse the repository at this point in the history
Closes #3997, closes #2567
  • Loading branch information
mcous authored Sep 10, 2019
1 parent be68032 commit 246d6db
Show file tree
Hide file tree
Showing 11 changed files with 658 additions and 454 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ jobs:
<<: *app_stage_build
name: 'Build/deploy Opentrons App for macOS'
os: osx
osx_image: xcode10.3
script: make -C app-shell dist-osx
if: tag =~ ^v OR branch =~ ^(edge|release_.+)$

Expand Down
9 changes: 3 additions & 6 deletions app-shell/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ babel := babel $(src_dir) --root-mode upward --out-dir $(lib_dir) --ignore $(src
ui_dir := ../app
discovery_client_dir := ../discovery-client

# directories for robot API update bundled in production build
api_dist_dir := ../api/dist

# cross-platform noop command
noop := cd .

Expand All @@ -40,7 +37,9 @@ publish_update := $(filter v%,$(OT_TAG))
branch_suffix := $(if $(publish_update),,-$(OT_BRANCH))
build_id := $(or $(and $(OT_BUILD),b$(OT_BUILD)$(branch_suffix)),dev)

builder := electron-builder -p never
builder := electron-builder \
--config electron-builder.config.js \
--publish never

electron := electron . \
--devtools \
Expand Down Expand Up @@ -72,9 +71,7 @@ lib:
$(babel)

.PHONY: deps
deps: wheel = $(wildcard $(api_dist_dir)/*.whl)
deps:
$(if $(wheel),@echo "Packaging $(wheel)",$(error API wheel required))
$(MAKE) -C $(ui_dir)
$(MAKE) -C $(discovery_client_dir)

Expand Down
57 changes: 57 additions & 0 deletions app-shell/electron-builder.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
'use strict'
const path = require('path')

const { OT_APP_DEPLOY_BUCKET, OT_APP_DEPLOY_FOLDER } = process.env
const DEV_MODE = process.env.NODE_ENV !== 'production'

module.exports = {
appId: 'com.opentrons.app',
electronVersion: '6.0.7',
files: [
'**/*',
{
from: '../app/dist',
to: './ui',
filter: ['**/*'],
},
'build/release-notes.md',
'build/br-premigration-wheels',
'!Makefile',
],
/* eslint-disable no-template-curly-in-string */
artifactName: DEV_MODE
? '${productName}-v${version}-${os}-${dev}.${ext}'
: '${productName}-v${version}-${os}-${env.BUILD_ID}.${ext}',
/* eslint-enable no-template-curly-in-string */
asar: true,
mac: {
target: process.platform === 'darwin' ? ['dmg', 'zip'] : ['zip'],
category: 'public.app-category.productivity',
type: DEV_MODE ? 'development' : 'distribution',
},
dmg: {
icon: null,
},
win: {
target: ['nsis'],
publisherName: 'Opentrons Labworks Inc.',
},
nsis: {
oneClick: false,
},
linux: {
target: ['AppImage'],
executableName: 'opentrons',
category: 'Science',
},
publish:
OT_APP_DEPLOY_BUCKET && OT_APP_DEPLOY_FOLDER
? {
provider: 's3',
bucket: OT_APP_DEPLOY_FOLDER,
path: OT_APP_DEPLOY_FOLDER,
}
: null,
generateUpdatesFilesForAllChannels: true,
afterSign: path.join(__dirname, './scripts/after-sign.js'),
}
37 changes: 0 additions & 37 deletions app-shell/electron-builder.json

This file was deleted.

6 changes: 3 additions & 3 deletions app-shell/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
"@opentrons/discovery-client": "3.11.4",
"@thi.ng/paths": "^1.6.5",
"dateformat": "^3.0.3",
"electron-debug": "^2.0.0",
"electron-debug": "^3.0.1",
"electron-devtools-installer": "^2.2.4",
"electron-store": "^2.0.0",
"electron-updater": "^3.1.2",
"electron-store": "^4.0.0",
"electron-updater": "^4.1.2",
"form-data": "^2.5.0",
"fs-extra": "^6.0.1",
"get-stream": "^5.1.0",
Expand Down
47 changes: 47 additions & 0 deletions app-shell/scripts/after-sign.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'use strict'

const path = require('path')
const { notarize } = require('electron-notarize')
const { appId } = require('../electron-builder.config')

const { APPLE_ID, APPLE_ID_PASSWORD } = process.env
const DEV_MODE = process.env.NODE_ENV !== 'production'
const PLATFORM_DARWIN = 'darwin'

module.exports = function afterSign(context) {
const { electronPlatformName, appOutDir } = context

if (
process.platform !== PLATFORM_DARWIN ||
electronPlatformName !== PLATFORM_DARWIN
) {
console.log(
'Not running on and/or building for macOS; skipping notarization'
)
return Promise.resolve()
}

if (DEV_MODE) {
console.log('Not in a production environment; skipping notarization')
return Promise.resolve()
}

if (!APPLE_ID || !APPLE_ID_PASSWORD) {
console.warn(
'No Apple Account credentials available; skipping notarization'
)
return Promise.resolve()
}

const appName = context.packager.appInfo.productFilename
const appPath = path.join(appOutDir, `${appName}.app`)

console.log(`Submitting app for notarization: ${appPath}`)

return notarize({
appBundleId: appId,
appleId: APPLE_ID,
appleIdPassword: APPLE_ID_PASSWORD,
appPath,
})
}
2 changes: 1 addition & 1 deletion app-shell/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ log.debug('App config', {
})

if (config.devtools) {
require('electron-debug')({ enabled: true, showDevTools: true })
require('electron-debug')({ isEnabled: true, showDevTools: true })
}

// hold on to references so they don't get garbage collected
Expand Down
57 changes: 5 additions & 52 deletions app-shell/src/menu.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,18 @@
// application menu
import { app, Menu } from 'electron'
import { Menu } from 'electron'

import pkg from '../package.json'
import { getConfig } from './config'

const config = getConfig()

// file or application menu
const firstMenu = {
label: 'File',
submenu: [{ role: 'quit' }],
}

if (process.platform === 'darwin') {
// if mac, first menu is application menu
Object.assign(firstMenu, {
label: app.getName(),
submenu: [
{ role: 'about' },
{ type: 'separator' },
{ role: 'services', submenu: [] },
{ type: 'separator' },
{ role: 'hide' },
{ role: 'hideothers' },
{ role: 'unhide' },
{ type: 'separator' },
...firstMenu.submenu,
],
})
}

const editMenu = {
label: 'Edit',
submenu: [
{ role: 'cut' },
{ role: 'copy' },
{ role: 'paste' },
{ role: 'selectall' },
],
role: process.platform === 'darwin' ? 'appMenu' : 'fileMenu',
}

const viewMenu = {
label: 'View',
submenu: [{ role: 'togglefullscreen' }],
}
const editMenu = { role: 'editMenu' }

if (config.devtools) {
Object.assign(viewMenu, {
submenu: [
{ role: 'reload' },
{ role: 'forcereload' },
{ type: 'separator' },
...viewMenu.submenu,
],
})
}
const viewMenu = { role: 'viewMenu' }

const windowMenu = {
role: 'window',
submenu: [{ role: 'minimize' }, { type: 'separator' }, { role: 'front' }],
}
const windowMenu = { role: 'windowMenu' }

const helpMenu = {
role: 'help',
Expand Down
3 changes: 3 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ install:
- ps: Install-Product node $env:nodejs_version x64
# install dev dependencies
- cmd: '%MAKE% -j 2 install'
# TODO(mc, 2019-09-09): remove this workaround when this issue is fixed:
# https://github.com/electron-userland/electron-builder/issues/4092
- cmd: 'yarn add -DW [email protected]'

# do not run MSBuild
build: false
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@
"concurrently": "^4.0.1",
"css-loader": "^1.0.0",
"cz-conventional-changelog": "2.1.0",
"electron": "3.0.2",
"electron-builder": "^20.28.4",
"electron": "^6.0.7",
"electron-builder": "^21.2.0",
"electron-notarize": "^0.1.1",
"electron-publisher-s3": "^20.17.2",
"enzyme": "^3.10.0",
"enzyme-adapter-react-16": "^1.14.0",
Expand Down
Loading

0 comments on commit 246d6db

Please sign in to comment.