Skip to content

Commit b69d549

Browse files
committed
fix: fix major bugs in build
- ESP Web Tools wasn't loading due to the Content Security Policy - Sound files were not being bundled properly - fix permissions check on notifications
1 parent b7facc8 commit b69d549

File tree

12 files changed

+63
-114
lines changed

12 files changed

+63
-114
lines changed

GUI/ETVR/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
"tauri": "tauri",
1414
"tauri:dev": "tauri dev",
1515
"tauri:build": "tauri build",
16+
"tauri:build:dev": "tauri build --debug",
17+
"tauri:clean": "cd src-tauri && cargo clean",
1618
"docs": "jsdoc -c jsdoc.conf.json",
1719
"lint": "eslint --ext .js,.ts,.jsx,.tsx src",
1820
"format": "yarn run lint --fix & yarn prettier --write \"src/**/*.{js,jsx,ts,tsx}\""
@@ -74,4 +76,4 @@
7476
"yarn": "^1.22.19",
7577
"yup": "^0.32.11"
7678
}
77-
}
79+
}

GUI/ETVR/src-tauri/Cargo.lock

-68
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

GUI/ETVR/src-tauri/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ features = [ "derive",]
3131

3232
[dependencies.tauri]
3333
version = "1.1.1"
34-
features = [ "isolation", "protocol-asset", "fs-all", "shell-sidecar", "dialog-all", "http-all", "icon-ico", "notification-all", "os-all", "path-all", "process-relaunch", "shell-open", "system-tray", "window-center", "window-close", "window-hide", "window-maximize", "window-minimize", "window-set-decorations", "window-set-focus", "window-set-fullscreen", "window-set-size", "window-start-dragging", "window-unmaximize", "window-unminimize",]
34+
features = [ "protocol-asset", "fs-all", "shell-sidecar", "dialog-all", "http-all", "icon-ico", "notification-all", "os-all", "path-all", "process-relaunch", "shell-open", "system-tray", "window-center", "window-close", "window-hide", "window-maximize", "window-minimize", "window-set-decorations", "window-set-focus", "window-set-fullscreen", "window-set-size", "window-start-dragging", "window-unmaximize", "window-unminimize",]
3535

3636
[dependencies.tauri-plugin-window-state]
3737
git = "https://github.com/tauri-apps/tauri-plugin-window-state/"
@@ -59,7 +59,7 @@ features = [ "full",]
5959

6060
[build-dependencies.tauri-build]
6161
version = "1.1.1"
62-
features = [ "isolation",]
62+
features = []
6363

6464
[profile.dev]
6565
debug = 0

GUI/ETVR/src-tauri/tauri.conf.json

+5-8
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@
1111
"version": "1.0.0"
1212
},
1313
"tauri": {
14-
"pattern": {
15-
"use": "isolation",
16-
"options": {
17-
"dir": "../dist-isolation"
18-
}
19-
},
2014
"allowlist": {
2115
"all": false,
2216
"clipboard": {
@@ -165,7 +159,10 @@
165159
}
166160
},
167161
"security": {
168-
"csp": "default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self' img-src: 'self' asset: https://asset.localhost"
162+
"csp": "script-src: 'self' https://unpkg.com/esp-web-tools@9.2.0/dist/web/install-button.js?module; default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self' img-src: 'self' asset: https://asset.localhost",
163+
"dangerousDisableAssetCspModification": [
164+
"script-src"
165+
]
169166
},
170167
"updater": {
171168
"active": false,
@@ -203,4 +200,4 @@
203200
"iconAsTemplate": true
204201
}
205202
}
206-
}
203+
}

GUI/ETVR/src/components/Notifications/index.tsx

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
1-
import { isPermissionGranted, requestPermission } from '@tauri-apps/api/notification'
21
import { Toaster, ToasterStore, Transition, useToaster } from 'solid-headless'
32
import { createEffect, createSignal, For, onCleanup } from 'solid-js'
43
import CustomToast from './CustomToast'
54
import { INotifications } from '@static/types/interfaces'
6-
import { notifications } from '@store/ui/selectors'
7-
8-
let permissionGranted = await isPermissionGranted()
9-
if (!permissionGranted) {
10-
const permission = await requestPermission()
11-
permissionGranted = permission === 'granted'
12-
}
5+
import { notifications, showNotifications } from '@store/ui/selectors'
136

147
const ToastNotificationWindow = () => {
158
const notifs = useToaster(notifications() as ToasterStore<INotifications>)
@@ -24,7 +17,7 @@ const ToastNotificationWindow = () => {
2417
}
2518

2619
createEffect(() => {
27-
if (permissionGranted) {
20+
if (showNotifications()) {
2821
if (notifs().length > 0) {
2922
console.log('[Notifications]: Notifcations Added', notifs().length)
3023
setIsOpen(true)

GUI/ETVR/src/store/ui/selectors.ts

+1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ export const menuOpenStatus = createMemo(() => uiState().menuOpen)
88
export const connectedUserName = createMemo(() => uiState().connectedUser)
99
export const showCameraView = createMemo(() => uiState().showCameraView)
1010
export const notifications = createMemo(() => uiState().notifications)
11+
export const showNotifications = createMemo(() => uiState().showNotifications)
1112
export const hideHeaderButtons = createMemo(() => uiState().hideHeaderButtons)

GUI/ETVR/src/store/ui/ui.ts

+10-6
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@ interface IMenuOpen {
99
y: number
1010
}
1111

12-
interface IProgressBar {
13-
progress: number
14-
msg: string
15-
show: boolean
16-
}
17-
1812
export interface INewMenu {
1913
children: JSXElement
2014
ref: HTMLElement | null
@@ -35,6 +29,7 @@ export interface IUiStore {
3529
showCameraView?: boolean
3630
connectedUser: string
3731
notifications?: ToasterStore<INotifications>
32+
showNotifications?: boolean
3833
hideHeaderButtons: boolean
3934
}
4035

@@ -46,6 +41,7 @@ export const defaultState = {
4641
connectedUser: '',
4742
showCameraView: false,
4843
notifications: new ToasterStore<INotifications>(),
44+
showNotifications: false,
4945
hideHeaderButtons: false,
5046
}
5147

@@ -107,4 +103,12 @@ export const setShowCameraView = (showCameraView: boolean) => {
107103
)
108104
}
109105

106+
export const setShowNotifications = (showNotifications: boolean) => {
107+
setState(
108+
produce((s) => {
109+
s.showNotifications = showNotifications
110+
}),
111+
)
112+
}
113+
110114
export const uiState = createMemo(() => state)

GUI/ETVR/src/utils/hooks/app/index.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { invoke } from '@tauri-apps/api/tauri'
22
import { appWindow } from '@tauri-apps/api/window'
33
import { doGHRequest } from '@utils/hooks/api/useGHReleases'
4+
import { checkPermission } from '@utils/hooks/notifications'
45
import { generateWebsocketClients } from '@utils/hooks/websocket'
56

67
export const handleTitlebar = () => {
@@ -30,7 +31,7 @@ export const handleAppBoot = () => {
3031
})
3132

3233
// TODO: call these after the MDNS service is up and running and discoveres the camera's
33-
// TODO: Implement a websocket client that can be used to connect to the camera'susing the `tauri-plugin-websocket` rust crate
34+
checkPermission()
3435
generateWebsocketClients()
3536
doGHRequest()
3637
}
@@ -52,12 +53,12 @@ export const handleSound = async (
5253
if ('Audio' in window) {
5354
const a = new Audio()
5455
if (a.canPlayType && a.canPlayType('audio/ogg; codecs="vorbis"').replace(/no/, ''))
55-
a.src = ('assets/audio/' + soundfile_ogg) as string
56+
a.src = ('audio/' + soundfile_ogg) as string
5657
else if (a.canPlayType && a.canPlayType('audio/mpeg;').replace(/no/, ''))
57-
a.src = ('assets/audio/' + soundfile_mp) as string
58+
a.src = ('audio/' + soundfile_mp) as string
5859
else if (a.canPlayType && a.canPlayType('audio/mp4; codecs="mp4a.40.2"').replace(/no/, ''))
59-
a.src = ('assets/audio/' + soundfile_ma) as string
60-
else a.src = ('assets/audio/' + soundfile_mp) as string
60+
a.src = ('audio/' + soundfile_ma) as string
61+
else a.src = ('audio/' + soundfile_mp) as string
6162

6263
a.play()
6364
return
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
/* eslint-disable */
22

3-
import { sendNotification } from '@tauri-apps/api/notification'
3+
import {
4+
sendNotification,
5+
isPermissionGranted,
6+
requestPermission,
7+
} from '@tauri-apps/api/notification'
48
import { handleSound } from '../app'
59
import { ENotificationAction, ENotificationType } from '@static/types/enums'
610
import { INotifications, INotificationAction } from '@static/types/interfaces'
7-
import { notifications } from '@store/ui/selectors'
11+
import { notifications, showNotifications } from '@store/ui/selectors'
12+
import { setShowNotifications } from '@store/ui/ui'
813

914
/**
1015
* Send notification to the WebView Window using the browser API
@@ -20,19 +25,23 @@ export const notify = (title: string, body: string | undefined) => {
2025
* @param {INotifications} notification Notification message
2126
*/
2227
export const addNotification = (notification: INotifications) => {
23-
const { title, message, action } = notification
24-
NotificationType(action, {
25-
callbackOS: () => {
26-
sendNotification({
27-
title,
28-
body: message,
29-
})
30-
},
31-
callbackApp: () => {
32-
handleSound('EyeTrackApp_Audio_notif.mp3')
33-
notifications()?.create(notification)
34-
},
35-
})
28+
if (showNotifications()) {
29+
const { title, message, action } = notification
30+
NotificationType(action, {
31+
callbackOS: () => {
32+
sendNotification({
33+
title,
34+
body: message,
35+
})
36+
},
37+
callbackApp: () => {
38+
handleSound('EyeTrackApp_Audio_notif.mp3')
39+
notifications()?.create(notification)
40+
},
41+
})
42+
return
43+
}
44+
checkPermission()
3645
}
3746

3847
const NotificationType = (
@@ -47,5 +56,15 @@ const NotificationType = (
4756
}
4857
}
4958

59+
export const checkPermission = async () => {
60+
let permissionGranted = await isPermissionGranted()
61+
62+
if (!permissionGranted) {
63+
const permission = await requestPermission()
64+
permissionGranted = permission === 'granted'
65+
}
66+
setShowNotifications(permissionGranted)
67+
}
68+
5069
// export imported enum
5170
export { ENotificationType, ENotificationAction }

0 commit comments

Comments
 (0)