Skip to content

Commit

Permalink
Expose sendUpdateInterval & sendUpdateMaxSize
Browse files Browse the repository at this point in the history
- don't open webxdc on notification click
  • Loading branch information
nicodh committed Dec 11, 2024
1 parent 3edca1f commit a0a45f9
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 33 deletions.
13 changes: 1 addition & 12 deletions packages/frontend/src/components/RuntimeAdapter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import useDialog from '../hooks/dialog/useDialog'
import WebxdcSaveToChatDialog from './dialogs/WebxdcSendToChat'
import { saveLastChatId } from '../backend/chat'
import useChat from '../hooks/chat/useChat'
import { internalOpenWebxdc } from '../system-integration/webxdc'
import { BackendRemote } from '../backend-com'

type Props = {
accountId?: number
Expand Down Expand Up @@ -44,12 +42,7 @@ export default function RuntimeAdapter({
}

runtime.setNotificationCallback(
async ({
accountId: notificationAccountId,
msgId,
chatId,
isWebxdcInfo,
}) => {
async ({ accountId: notificationAccountId, msgId, chatId }) => {
if (accountId !== notificationAccountId) {
closeAllDialogs()
// selectAccount always loads the last used chat
Expand All @@ -59,10 +52,6 @@ export default function RuntimeAdapter({
await window.__selectAccount(notificationAccountId)
} else if (chatId !== 0) {
await selectChat(accountId, chatId)
if (isWebxdcInfo) {
const message = await BackendRemote.rpc.getMessage(accountId, msgId)
internalOpenWebxdc(accountId, message)
}
clearNotificationsForChat(notificationAccountId, chatId)
}
if (msgId) {
Expand Down
7 changes: 1 addition & 6 deletions packages/runtime/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,7 @@ export interface Runtime {
clearNotifications(chatId: number): void
// enables to set a callback (used in frontend RuntimeAdapter)
setNotificationCallback(
cb: (data: {
accountId: number
chatId: number
msgId: number
isWebxdcInfo: boolean
}) => void
cb: (data: { accountId: number; chatId: number; msgId: number }) => void
): void
/** @param name optional name needed for browser */
writeClipboardToTempFile(name?: string): Promise<string>
Expand Down
7 changes: 1 addition & 6 deletions packages/target-browser/runtime-browser/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,12 +384,7 @@ class BrowserRuntime implements Runtime {
}

setNotificationCallback(
cb: (data: {
accountId: number
chatId: number
msgId: number
isWebxdcInfo: boolean
}) => void
cb: (data: { accountId: number; chatId: number; msgId: number }) => void
): void {
this.notificationCB = cb
}
Expand Down
7 changes: 1 addition & 6 deletions packages/target-electron/runtime-electron/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,7 @@ class ElectronRuntime implements Runtime {
isWebxdcInfo: boolean
}) => void = () => {}
setNotificationCallback(
cb: (data: {
accountId: number
chatId: number
msgId: number
isWebxdcInfo: boolean
}) => void
cb: (data: { accountId: number; chatId: number; msgId: number }) => void
): void {
this.notificationCallback = cb
}
Expand Down
5 changes: 4 additions & 1 deletion packages/target-electron/src/deltachat/webxdc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export default class DCWebxdc extends SplitOut {
) => {
const { webxdcInfo, chatName, displayname, accountId, href } = p
const addr = webxdcInfo.selfAddr
const { sendUpdateInterval, sendUpdateMaxSize } = webxdcInfo
let base64EncodedHref = ''
const appURL = `webxdc://${accountId}.${msg_id}.webxdc`
if (href && href !== '') {
Expand Down Expand Up @@ -222,7 +223,9 @@ export default class DCWebxdc extends SplitOut {
// initializes the preload script, the actual implementation of `window.webxdc` is found there: static/webxdc-preload.js
return makeResponse(
Buffer.from(
`window.parent.webxdc_internal.setup("${selfAddr}","${displayName}")
`window.parent.webxdc_internal.setup("${selfAddr}","${displayName}", ${Number(
sendUpdateInterval
)}, ${Number(sendUpdateMaxSize)})
window.webxdc = window.parent.webxdc
window.webxdc_custom = window.parent.webxdc_custom`
),
Expand Down
2 changes: 1 addition & 1 deletion packages/target-electron/src/notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ if (Notification.isSupported()) {

function createNotification(data: DcNotification): Notification {
let icon: NativeImage | undefined = data.icon
? data.icon.indexOf('base64') > -1
? data.icon.startsWith('data:')
? nativeImage.createFromDataURL(data.icon)
: nativeImage.createFromPath(data.icon)
: undefined
Expand Down
4 changes: 3 additions & 1 deletion packages/target-electron/static/webxdc-preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,14 @@ class RealtimeListener {
const connections = []

contextBridge.exposeInMainWorld('webxdc_internal', {
setup: (selfAddr, selfName) => {
setup: (selfAddr, selfName, sendUpdateInterval, sendUpdateMaxSize) => {
if (is_ready) {
return
}
api.selfAddr = Buffer.from(selfAddr, 'base64').toString('utf-8')
api.selfName = Buffer.from(selfName, 'base64').toString('utf-8')
api.sendUpdateInterval = sendUpdateInterval ? sendUpdateInterval : 1000
api.sendUpdateMaxSize = sendUpdateMaxSize ? sendUpdateMaxSize : 18874368

// be sure that webxdc.js was included
contextBridge.exposeInMainWorld('webxdc', api)
Expand Down

0 comments on commit a0a45f9

Please sign in to comment.