Skip to content

Commit

Permalink
fix: user icon in notification
Browse files Browse the repository at this point in the history
  • Loading branch information
SpikeHD committed Oct 26, 2024
1 parent 92e3002 commit 4cf1885
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 172 deletions.
176 changes: 13 additions & 163 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ tauri-plugin-shell = "=2.0.1"
tauri-plugin-single-instance = "2.0"
tauri-plugin-process = "2.0"
tauri-plugin-autostart = "2.0"
tauri-plugin-notification = { version = "2.0", features = ["win7-notifications", "windows7-compat"] }
tauri-plugin-http = "2.0"
tauri-winrt-notification = "0.6"
# window blur
window-vibrancy = { version = "0.5.0", optional = true }

Expand Down
1 change: 0 additions & 1 deletion src-tauri/capabilities/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"process:default",
"autostart:default",
"window-state:default",
"notification:default",
{
"identifier": "http:default",
"allow": [
Expand Down
3 changes: 2 additions & 1 deletion src-tauri/injection/preinject.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { badPostMessagePatch, createLocalStorage, proxyFetch, proxyXHR, proxyAddEventListener, proxyOpen } from './shared/recreate'
import { badPostMessagePatch, createLocalStorage, proxyFetch, proxyXHR, proxyAddEventListener, proxyOpen, proxyNotification } from './shared/recreate'
import { extraCssChangeWatch, safemodeTimer, typingAnim } from './shared/ui'
import { cssSanitize, fetchImage, isJson, waitForApp, waitForElm, saferEval } from './shared/util'
import { applyNotificationCount } from './shared/window'
Expand Down Expand Up @@ -41,6 +41,7 @@ if (!window.__DORION_INITIALIZED__) window.__DORION_INITIALIZED__ = false
proxyFetch()
proxyXHR()
proxyAddEventListener()
proxyNotification()

while (!window.__TAURI__) {
console.log('Waiting for definition...')
Expand Down
37 changes: 37 additions & 0 deletions src-tauri/injection/shared/recreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,40 @@ export function badPostMessagePatch() {
return null
}
}

export function proxyNotification() {
let permVal = 'granted'

// @ts-expect-error shut up
window.nativeNotification = window.Notification

// @ts-expect-error shut up
window.Notification = function(title, options) {
const { invoke } = window.__TAURI__.core
const body = options?.body || ''
let icon = options?.icon || ''

// If the icon is a relative path, convert to full path using URI
if (icon.startsWith('/')) {
icon = window.location.origin + icon
}

invoke('send_notification', {
title,
body,
icon,
})

// return new window.nativeNotification(title, options)
}

window.Notification.requestPermission = async () => 'granted'

Object.defineProperty(window.Notification, 'permission', {
enumerable: true,
get: () => permVal,
set: (v) => {
permVal = v
}
})
}
Loading

0 comments on commit 4cf1885

Please sign in to comment.