Skip to content

Commit

Permalink
Merge pull request #1094 from cozy-labs/tos-notification
Browse files Browse the repository at this point in the history
Show user action required notification on first check
  • Loading branch information
aenario committed Jul 17, 2018
2 parents a85b00c + fca5a84 commit 0e215d5
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
1 change: 1 addition & 0 deletions gui/elm/Window/Tray/UserActionRequiredPage.elm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ include_GDPR_link base_text url =
view : Helpers -> UserActionRequiredError -> msg -> Html msg
view helpers { code, title, detail, links } msg =
div [ class "two-panes two-panes__content user-action-required" ]
-- Same logic as gui/js/components/UserActionRequiredDialog.js
(if code == "tos-updated" then
[ img [ class "error_img", src "images/tos_updated.svg" ] []
, h2 [] [ text (helpers.t "CGU Updated") ]
Expand Down
49 changes: 49 additions & 0 deletions gui/js/components/UserActionRequiredDialog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
const { dialog } = require('electron')
const opn = require('opn')
const { translate } = require('../i18n')
const { logger } = require('../../../core/app')

const log = logger({
component: 'UserActionRequiredDialog'
})

module.exports = {
show
}

function show (err) {
const userChoice = dialog.showMessageBox(null, options(err))
if (userChoice === 0) opn(err.links.self)
else log.warn({userChoice}, 'Unexpected user choice')
}

function options (err) {
const type = 'warning'

// Same logic as gui/elm/UserActionRequiredPage.elm
if (err.code === 'tos-updated') {
return {
type,
title: translate('CGU Updated'),
message: translate('CGU Updated'),
detail: [
'CGU Updated Detail',
'CGU Updated Required strong',
'CGU Updated Required rest'
].map(translate).join('. '),
buttons: [
translate('CGU Updated See')
]
}
} else {
return {
type,
title: err.title,
message: err.message,
detail: err.detail,
buttons: [
translate('Error Ok')
]
}
}
}
6 changes: 5 additions & 1 deletion gui/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const {buildAppMenu} = require('./js/appmenu')
const i18n = require('./js/i18n')
const {translate} = i18n
const {incompatibilitiesErrorMessage} = require('./js/incompatibilitiesmsg')
const UserActionRequiredDialog = require('./js/components/UserActionRequiredDialog')
const {app, Menu, Notification, ipcMain, dialog} = require('electron')

// FIXME: https://github.com/electron/electron/issues/10864
Expand Down Expand Up @@ -263,8 +264,11 @@ const startSync = (force, ...args) => {
desktop.synchronize(desktop.config.config.mode)
.then(() => sendErrorToMainWindow('stopped'))
.catch((err) => {
log.error({status: err.status}, 'RIGHT RIGHT HERE')
if (err.status === 402) {
// Only show notification popup on the first check (the GUI will
// include a warning anyway).
if (!userActionRequired) UserActionRequiredDialog.show(err)

userActionRequired = pick(err,
['title', 'code', 'detail', 'links', 'message']
)
Expand Down

0 comments on commit 0e215d5

Please sign in to comment.