-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add auto-update on hide workflow for Electron on Mac #1318
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b735e46
Add auto-update on hide workflow
nbhargava e5f94fa
Remove electron-is-dev
nbhargava a0fd4cb
Fix package-lock
nbhargava 0b2362d
Fix rebase issues
nbhargava 99a612a
Respond to reviewer feedback
nbhargava 72b9003
Update props
nbhargava File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Testing Electron Auto-Update | ||
Testing the auto-update process can be a little involved. The most effective way to test this involves setting up your own release channel locally and making sure that you can notarize your builds. | ||
|
||
**Note:** In order to test with a notarized build you'll need to have a paid Apple developer account. | ||
|
||
## Setting up Min.IO | ||
Rather than pushing new builds to the production S3 bucket, the best way to test locally is to use [Min.IO](https://min.io). Min.IO is an S3-compatible service that you can set up and deploy locally. In order to set up a local Min.IO instance to emulate an S3 bucket, follow these steps: | ||
|
||
1. [Install Docker Desktop for Mac 🐳](https://docs.docker.com/docker-for-mac/install/) and make sure it's running. If you're not familiar with Docker, it might be a good idea to [follow the Docker quickstart](https://docs.docker.com/get-started/) and/or [learn more about Docker](https://docker-curriculum.com/). | ||
1. Next, you can [install Min.IO](https://docs.min.io/docs/minio-docker-quickstart-guide.html) using the command: `brew install minio/stable/mc` | ||
1. Now you can run Min.IO in a Docker container by executing this command: | ||
```bash | ||
docker run -p 9000:9000 \ | ||
-e "MINIO_ROOT_USER=USER" | ||
-e "MINIO_ROOT_PASSWORD=Password1" | ||
--name minio1 | ||
minio/minio server /data | ||
``` | ||
1. Next, confirm that the docker container is running using the command `docker ps` | ||
|
||
|
||
Once you're running a local Min.IO instance (which emulates an S3 instance), the next step is to point your electron config at the Min.IO server. To do so, edit the [`publish` block of electon.config.js](https://github.com/Expensify/Expensify.cash/blob/bd776babbfa196fa7b29cef07590b71fc1df73ab/config/electron.config.js#L21-L25) to look like: | ||
``` | ||
publish: [{ | ||
provider: 's3', | ||
endpoint: 'http://localhost:9000', | ||
bucket: 'minio1', | ||
channel: 'latest', | ||
}], | ||
``` | ||
|
||
**Note:** while the `electron-updater` docs tell you to create a file named `dev-app-update.yaml`, this will **not** be helpful. Setting that file will, in development, tell the auto-updater where to look for builds. Unfortunately, on Mac the auto-updater will not install the new bits unless the app that is currently running is signed. | ||
|
||
Now, you need to upload a build. Before you can do so, you need to make sure that you can notarize builds. For this you will need an [Apple Developer](https://developer.apple.com) account. Go to the [Certificates, Identifiers, and Profiles](https://developer.apple.com/account/resources/certificates/list) page and create a new certificate for a Developer ID Application. Follow the instructions to create a Certificate Signing Request, and once the certificate has been created, add it to your keychain with the Keychain Access app. | ||
|
||
You will need to pass your Apple ID (username) and an [app-specific password](https://appleid.apple.com/account/manage) to the environment of the local desktop build. Entering your normal password will not work, so generate an app-specific password before continuing. | ||
|
||
Now that your credentials have been set up properly, you can push a build to Min.IO. Start by updating the app version in `package.json` to something sufficiently high (i.e. `9.9.9-999`). Then run: | ||
|
||
```bash | ||
APPLE_ID=<your_apple_id_username> \ | ||
APPLE_ID_PASSWORD=<your_app_specific_password> \ | ||
npm run desktop-build | ||
``` | ||
|
||
This will push your new build to the server. | ||
|
||
Once this is done, revert the version update in `package.json`, remove `--publish always` from the `desktop-build` command and again run `npm run desktop-build`. From the `dist/` folder in the root of the project, you will find `Expensify.cash.dmg`. Open the `.dmg` and install the app. Your app will attempt to auto-update in the background. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import _ from 'underscore'; | ||
import React, {PureComponent} from 'react'; | ||
import { | ||
TouchableOpacity, Text, | ||
} from 'react-native'; | ||
import HeaderWithCloseButton from '../HeaderWithCloseButton'; | ||
import Modal from '../Modal'; | ||
import styles from '../../styles/styles'; | ||
import {propTypes, defaultProps} from './UpdateAppModalPropTypes'; | ||
|
||
class BaseUpdateAppModal extends PureComponent { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
isModalOpen: true, | ||
}; | ||
|
||
this.submitAndClose = this.submitAndClose.bind(this); | ||
} | ||
|
||
/** | ||
* Execute the onSubmit callback and close the modal. | ||
*/ | ||
submitAndClose() { | ||
this.props.onSubmit(this.state.file); | ||
this.setState({isModalOpen: false}); | ||
} | ||
|
||
render() { | ||
return ( | ||
<> | ||
<Modal | ||
onSubmit={this.submitAndClose} | ||
onClose={() => this.setState({isModalOpen: false})} | ||
isVisible={this.state.isModalOpen} | ||
> | ||
<HeaderWithCloseButton | ||
title="Update App" | ||
onCloseButtonPress={() => this.setState({isModalOpen: false})} | ||
/> | ||
<Text style={[styles.textLabel, styles.p4]}> | ||
A new version of Expensify.cash is available. | ||
Update now or restart the app at a later time to download the latest changes. | ||
</Text> | ||
{this.props.onSubmit && ( | ||
<TouchableOpacity | ||
style={[styles.button, styles.buttonSuccess, styles.buttonConfirm]} | ||
onPress={this.submitAndClose} | ||
> | ||
<Text | ||
style={[ | ||
styles.buttonText, | ||
styles.buttonSuccessText, | ||
styles.buttonConfirmText, | ||
]} | ||
> | ||
Update App | ||
</Text> | ||
</TouchableOpacity> | ||
)} | ||
</Modal> | ||
</> | ||
); | ||
} | ||
} | ||
|
||
BaseUpdateAppModal.propTypes = _.omit(propTypes, 'version'); | ||
BaseUpdateAppModal.defaultProps = _.omit(defaultProps, 'version'); | ||
export default BaseUpdateAppModal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import PropTypes from 'prop-types'; | ||
|
||
const propTypes = { | ||
// Callback to fire when we want to trigger the update. | ||
onSubmit: PropTypes.func, | ||
|
||
// Version string for the app to update to. | ||
// eslint-disable-next-line react/no-unused-prop-types | ||
version: PropTypes.string, | ||
}; | ||
|
||
const defaultProps = { | ||
onSubmit: null, | ||
version: '', | ||
}; | ||
|
||
export {propTypes, defaultProps}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from 'react'; | ||
import {ipcRenderer} from 'electron'; | ||
import BaseUpdateAppModal from './BaseUpdateAppModal'; | ||
import {propTypes} from './UpdateAppModalPropTypes'; | ||
|
||
const UpdateAppModal = (props) => { | ||
const updateApp = () => { | ||
if (props.onSubmit) { | ||
props.onSubmit(); | ||
} | ||
ipcRenderer.sendSync('start-update', props.version); | ||
}; | ||
return <BaseUpdateAppModal onSubmit={updateApp} />; | ||
}; | ||
UpdateAppModal.propTypes = propTypes; | ||
UpdateAppModal.displayName = 'UpdateAppModal'; | ||
export default UpdateAppModal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from 'react'; | ||
import BaseUpdateAppModal from './BaseUpdateAppModal'; | ||
import {propTypes} from './UpdateAppModalPropTypes'; | ||
|
||
const UpdateAppModal = props => ( | ||
<BaseUpdateAppModal | ||
// eslint-disable-next-line react/jsx-props-no-spreading | ||
{...props} | ||
/> | ||
); | ||
UpdateAppModal.propTypes = propTypes; | ||
UpdateAppModal.displayName = 'UpdateAppModal'; | ||
export default UpdateAppModal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
// Local Notifications are not currently supported on mobile so we'll just noop here. | ||
export default { | ||
showCommentNotification: () => {}, | ||
showUpdateAvailableNotification: () => {}, | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NAB, but might be nice to have a "Maybe later" cancel button too.