Add notification feature with permission handling and UI toggle
This commit is contained in:
@@ -813,4 +813,6 @@ export const languageEnglish = {
|
|||||||
retranslate: "Retranslate",
|
retranslate: "Retranslate",
|
||||||
loading: "Loading",
|
loading: "Loading",
|
||||||
autoTranslateCachedOnly: "Auto Translate Cached Only",
|
autoTranslateCachedOnly: "Auto Translate Cached Only",
|
||||||
|
notification: "Notification",
|
||||||
|
permissionDenied: "Permission Denied by Your Browser or OS",
|
||||||
}
|
}
|
||||||
@@ -18,6 +18,7 @@
|
|||||||
import Arcodion from "src/lib/UI/Arcodion.svelte";
|
import Arcodion from "src/lib/UI/Arcodion.svelte";
|
||||||
import Button from "src/lib/UI/GUI/Button.svelte";
|
import Button from "src/lib/UI/GUI/Button.svelte";
|
||||||
import { CustomGUISettingMenuStore } from "src/ts/stores.svelte";
|
import { CustomGUISettingMenuStore } from "src/ts/stores.svelte";
|
||||||
|
import { alertError } from "src/ts/alert";
|
||||||
|
|
||||||
const onSchemeInputChange = (e:Event) => {
|
const onSchemeInputChange = (e:Event) => {
|
||||||
changeColorScheme((e.target as HTMLInputElement).value)
|
changeColorScheme((e.target as HTMLInputElement).value)
|
||||||
@@ -362,6 +363,27 @@
|
|||||||
<Help key="betaMobileGUI"/>
|
<Help key="betaMobileGUI"/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="flex items-center mt-2">
|
||||||
|
<Check bind:check={DBState.db.notification} name={language.notification} onChange={async (e) => {
|
||||||
|
let hasPermission = {state: 'denied'}
|
||||||
|
try {
|
||||||
|
hasPermission = await navigator.permissions.query({name: 'notifications'})
|
||||||
|
} catch (error) {
|
||||||
|
//for browsers that do not support permissions api
|
||||||
|
}
|
||||||
|
if(!DBState.db.notification){
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if(hasPermission.state === 'denied'){
|
||||||
|
const permission = await Notification.requestPermission()
|
||||||
|
if(permission === 'denied'){
|
||||||
|
alertError(language.permissionDenied)
|
||||||
|
DBState.db.notification = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}}/>
|
||||||
|
</div>
|
||||||
|
|
||||||
{#if DBState.db.showUnrecommended}
|
{#if DBState.db.showUnrecommended}
|
||||||
<div class="flex items-center mt-2">
|
<div class="flex items-center mt-2">
|
||||||
<Check bind:check={DBState.db.useChatSticker} name={language.useChatSticker}/>
|
<Check bind:check={DBState.db.useChatSticker} name={language.useChatSticker}/>
|
||||||
|
|||||||
@@ -1330,6 +1330,22 @@ export async function sendChat(chatProcessIndex = -1,arg:{
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(DBState.db.notification){
|
||||||
|
try {
|
||||||
|
const permission = await Notification.requestPermission()
|
||||||
|
if(permission === 'granted'){
|
||||||
|
const noti = new Notification('RisuAI', {
|
||||||
|
body: result
|
||||||
|
})
|
||||||
|
noti.onclick = () => {
|
||||||
|
window.focus()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
chatProcessStage.set(4)
|
chatProcessStage.set(4)
|
||||||
|
|
||||||
peerSync()
|
peerSync()
|
||||||
|
|||||||
@@ -848,6 +848,7 @@ export interface Database{
|
|||||||
translateBeforeHTMLFormatting:boolean
|
translateBeforeHTMLFormatting:boolean
|
||||||
autoTranslateCachedOnly:boolean
|
autoTranslateCachedOnly:boolean
|
||||||
lightningRealmImport:boolean
|
lightningRealmImport:boolean
|
||||||
|
notification: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SeparateParameters{
|
interface SeparateParameters{
|
||||||
|
|||||||
Reference in New Issue
Block a user