Skip to content

Commit

Permalink
Improvement: Add message for autoupdate
Browse files Browse the repository at this point in the history
  • Loading branch information
jane-rose committed Nov 12, 2020
1 parent 6a5fa2e commit 5ca0ede
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 14 deletions.
6 changes: 6 additions & 0 deletions src/app/containers/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class App extends PureComponent {
saveAsFile: PropTypes.func.isRequired,
openProject: PropTypes.func.isRequired,
updateIsDownloading: PropTypes.func.isRequired,
updateAutoupdateMessage: PropTypes.func.isRequired,
shouldCheckForUpdate: PropTypes.bool.isRequired
};

Expand Down Expand Up @@ -140,6 +141,10 @@ class App extends PureComponent {
UniApi.File.openProjectFile();
},
initUniEvent: () => {
UniApi.Event.on('message', (event, message) => {
console.log('message', message);
this.props.updateAutoupdateMessage(message);
});
UniApi.Event.on('download-has-started', () => {
this.props.updateIsDownloading(true);
});
Expand Down Expand Up @@ -373,6 +378,7 @@ const mapStateToProps = (state) => {
const mapDispatchToProps = (dispatch) => {
return {
machineInit: () => dispatch(machineActions.init()),
updateAutoupdateMessage: (message) => dispatch(machineActions.updateAutoupdateMessage(message)),
updateIsDownloading: (isDownloading) => dispatch(machineActions.updateIsDownloading(isDownloading)),
developToolsInit: () => dispatch(developToolsActions.init()),
keyboardShortcutInit: () => dispatch(keyboardShortcutActions.init()),
Expand Down
16 changes: 13 additions & 3 deletions src/app/containers/Settings/General/General.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class General extends PureComponent {
stateChanged: PropTypes.bool,
shouldCheckForUpdate: PropTypes.bool,
isDownloading: PropTypes.bool,
autoupdateMessage: PropTypes.string,
updateShouldCheckForUpdate: PropTypes.func.isRequired,
actions: PropTypes.object
};
Expand Down Expand Up @@ -84,7 +85,8 @@ class General extends PureComponent {
}

render() {
const { state, stateChanged, shouldCheckForUpdate } = this.props;
const { state, stateChanged, shouldCheckForUpdate, autoupdateMessage } = this.props;
console.log('general autoupdateMessage', autoupdateMessage);
const lang = get(state, 'lang', 'en');

if (state.api.loading) {
Expand Down Expand Up @@ -129,8 +131,12 @@ class General extends PureComponent {
<div className={styles['autoupdate-wrapper']}>
<p className={styles['update-title']}>{i18n._('Software Update')}</p>
<button
className={classNames(
'btn',
'btn-outline-secondary',
styles['autoupdate-button'],
)}
type="button"
className="btn btn-outline-secondary"
onClick={this.actions.handleCheckForUpdate}
>
{i18n._('Check for update')}
Expand All @@ -146,6 +152,9 @@ class General extends PureComponent {
{i18n._('Automatically check for update')}
</span>
</div>
<div className={styles['autoupdate-message']}>
{autoupdateMessage}
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -183,10 +192,11 @@ class General extends PureComponent {
const mapStateToProps = (state) => {
const machine = state.machine;

const { shouldCheckForUpdate, isDownloading } = machine;
const { shouldCheckForUpdate, isDownloading, autoupdateMessage } = machine;

return {
shouldCheckForUpdate,
autoupdateMessage,
isDownloading
};
};
Expand Down
23 changes: 17 additions & 6 deletions src/app/containers/Settings/General/index.styl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
@import '../form';

.form-control {
margin-top: 5px;
}
.learn-more {
color: #0060AC;
font-size: 14px;
Expand Down Expand Up @@ -33,16 +35,25 @@
.autoupdate-wrapper {
margin-top: 10px;
.update-title{
margin: 0;
margin: 0 0 5px 0;
}
.autoupdate-auto {
height: 15px;
line-height: 15px;
vertical-align: middle;
display: inline-block;
.autoupdate-checkbox {
margin-left: 10px;
margin-right: 5px;
vertical-align: middle;
}
}
.autoupdate-button{
color: #282828;
vertical-align: middle;
}
.autoupdate-checkbox {
margin-left: 10px;
margin-right: 5px;
vertical-align: middle;
.autoupdate-message{
color: #808080;
margin: 5px 0 0;
}
}
4 changes: 4 additions & 0 deletions src/app/flux/machine/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ const INITIAL_STATE = {
connectionTimeout: 3000,

// autoUpdate
autoupdateMessage: '',
// Whether to check for available updates when the software is opened
shouldCheckForUpdate: true,
// Whether an update is being downloaded
Expand Down Expand Up @@ -331,6 +332,9 @@ export const actions = {
});
},

updateAutoupdateMessage: (autoupdateMessage) => (dispatch) => {
dispatch(actions.updateState({ autoupdateMessage: autoupdateMessage }));
},
updateIsDownloading: (isDownloading) => (dispatch) => {
dispatch(actions.updateState({ isDownloading: isDownloading }));
},
Expand Down
10 changes: 5 additions & 5 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,18 @@ function sendUpdateMessage(text) {
// handle update issue
function updateHandle() {
const message = {
error: 'update error',
checking: 'updating...',
updateAva: 'fetch new version and downloading...',
updateNotAva: 'do not to update'
error: 'An error occurred while checking for updates.',
checking: 'Checking for updates.',
updateAva: 'Updates are available.',
updateNotAva: 'Snapmaker Luban is up to date.'
};
// Official document: https://www.electron.build/auto-update.html
autoUpdater.autoDownload = false;
// Whether to automatically install a downloaded update on app quit. Applicable only on Windows and Linux.
autoUpdater.autoInstallOnAppQuit = false;

autoUpdater.on('error', (err) => {
sendUpdateMessage(message.error, err);
sendUpdateMessage(message.error + err.message);
});
// Emitted when checking if an update has started.
autoUpdater.on('checking-for-update', () => {
Expand Down

0 comments on commit 5ca0ede

Please sign in to comment.