Skip to content
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

Fix broken system notifications #1071

Merged
merged 1 commit into from
Oct 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions _locales/_untranslated_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,17 @@
},
"ask_delete_chat_desktop": {
"message": "Are you sure you want to delete \"%1$s\"?"
},
"pref_notifications": {
"message": "Enable notifications"
},
"pref_notifications_explain": {
"message": "Enable system notifications on new messages"
},
"pref_show_notification_content": {
"message": "Show message content in notification"
},
"pref_show_notification_content_explain": {
"message": "Shows sender and first words of message content in notification"
}
}
19 changes: 13 additions & 6 deletions src/main/deltachat/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ const DeltaChat = require('deltachat-node')
const C = require('deltachat-node/constants')
const log = require('../../logger').getLogger('main/deltachat/login', true)
const path = require('path')
const setupNotifications = require('../notifications')
const setupUnreadBadgeCounter = require('../unread-badge')
const { setupMarkseenFix } = require('../markseenFix')
const { app } = require('electron')

const SplitOut = require('./splitout')
module.exports = class DCLoginController extends SplitOut {
Expand All @@ -24,8 +28,8 @@ module.exports = class DCLoginController extends SplitOut {
// Creates a separate DB file for each login
this._controller.fullCwd = this.getPath(credentials.addr)
log.info(`Using deltachat instance ${this._controller.fullCwd}`)
this._controller._dc = new DeltaChat()
const dc = this._dc
const dc = new DeltaChat()
this._controller._dc = dc
this._controller.credentials = credentials
this._controller._render = render

Expand All @@ -36,7 +40,7 @@ module.exports = class DCLoginController extends SplitOut {
return
}

dc.open(this._controller.fullCwd, err => {
this._dc.open(this._controller.fullCwd, err => {
if (err) throw err
const onReady = () => {
log.info('Ready')
Expand All @@ -46,16 +50,19 @@ module.exports = class DCLoginController extends SplitOut {
log.info('dc_get_info', dc.getInfo())
render()
}
if (!dc.isConfigured()) {
dc.once('ready', onReady)
if (!this._dc.isConfigured()) {
this._dc.once('ready', onReady)
this._controller.configuring = true
dc.configure(addServerFlags(credentials))
this._dc.configure(addServerFlags(credentials))
render()
} else {
onReady()
}
})
this._controller.registerEventHandler(dc)
setupNotifications(this._controller, app.state.saved)
setupUnreadBadgeCounter(this._controller)
setupMarkseenFix(this._controller)
}

logout () {
Expand Down
8 changes: 0 additions & 8 deletions src/main/ipc.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ const DeltaChat = (() => {
}
})()
const C = require('deltachat-node/constants')
const setupNotifications = require('./notifications')
const setupUnreadBadgeCounter = require('./unread-badge')

const { setupMarkseenFix } = require('./markseenFix')

function init (cwd, state, logHandler) {
const main = windows.main
Expand Down Expand Up @@ -97,10 +93,6 @@ function init (cwd, state, logHandler) {

ipcMain.on('handleLogMessage', (e, ...args) => logHandler.log(...args))

setupNotifications(dc, state.saved)
setupUnreadBadgeCounter(dc)
setupMarkseenFix(dc)

ipcMain.on('login', (e, credentials) => {
dc.loginController.login(credentials, render, txCoreStrings())
})
Expand Down
2 changes: 1 addition & 1 deletion src/main/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = function (dc, settings) {
return `${summary.text1 || json.contact.displayName}: ${summary.text2}`
}

dc.on('DC_EVENT_INCOMING_MSG', (chatId, msgId) => {
dc._dc.on('DC_EVENT_INCOMING_MSG', (chatId, msgId) => {
if (!notify && settings.notifications && windows.main.win.hidden) {
notify = new Notification({
title: appName(),
Expand Down
4 changes: 2 additions & 2 deletions src/main/unread-badge.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = function (dc) {
app.setBadgeCount(count)
}

dc.on('DC_EVENT_INCOMING_MSG', (chatId, msgId) => {
dc._dc.on('DC_EVENT_INCOMING_MSG', (chatId, msgId) => {
// don't update imidiately if the app is in focused
if (windows.main.win.hidden) update()

Expand All @@ -24,7 +24,7 @@ module.exports = function (dc) {
}, 4000)
})

dc.on('ready', () => {
dc._dc.on('ready', () => {
// for start and after account switch
update()
})
Expand Down
10 changes: 10 additions & 0 deletions src/renderer/components/dialogs/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ export default class Settings extends React.Component {
*/
handleDesktopSettingsChange (key, value) {
ipcRenderer.send('updateDesktopSetting', key, value)
if (key === 'notifications' && value === false) {
ipcRenderer.send('updateDesktopSetting', 'showNotificationContent', false)
}
}

/** Saves settings to deltachat core */
Expand Down Expand Up @@ -203,6 +206,7 @@ export default class Settings extends React.Component {
checked={settings[configKey]}
className={settings[configKey] ? 'active' : 'inactive'}
label={label}
disabled={configKey === 'showNotificationContent' && !settings['notifications']}
onChange={() => this.handleDesktopSettingsChange(configKey, !settings[configKey])}
/>
)}
Expand Down Expand Up @@ -288,6 +292,12 @@ export default class Settings extends React.Component {
<br />
{ this.renderDTSettingSwitch('enterKeySends', this.translate('pref_enter_sends')) }
<p>{this.translate('pref_enter_sends_explain')}</p>
<br />
{ this.renderDTSettingSwitch('notifications', this.translate('pref_notifications')) }
<p>{this.translate('pref_notifications_explain')}</p>
<br />
{ this.renderDTSettingSwitch('showNotificationContent', this.translate('pref_show_notification_content')) }
<p>{this.translate('pref_show_notification_content_explain')}</p>
</Card>
<Card elevation={Elevation.ONE}>
<H5>{this.translate('pref_experimental_features')}</H5>
Expand Down