Skip to content

Commit

Permalink
Improvement: Add message for autoupdate (#548)
Browse files Browse the repository at this point in the history
  • Loading branch information
jane-rose authored Nov 12, 2020
1 parent 2715d54 commit 03749a8
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 13 deletions.
5 changes: 5 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,9 @@ class App extends PureComponent {
UniApi.File.openProjectFile();
},
initUniEvent: () => {
UniApi.Event.on('message', (event, message) => {
this.props.updateAutoupdateMessage(message);
});
UniApi.Event.on('download-has-started', () => {
this.props.updateIsDownloading(true);
});
Expand Down Expand Up @@ -373,6 +377,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
15 changes: 12 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,7 @@ class General extends PureComponent {
}

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

if (state.api.loading) {
Expand Down Expand Up @@ -129,8 +130,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 +151,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 +191,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
8 changes: 4 additions & 4 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ 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;
Expand Down

0 comments on commit 03749a8

Please sign in to comment.