Skip to content

Commit

Permalink
Various Bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsRiprod committed Aug 4, 2024
1 parent 0a0e3f2 commit 9f54c1a
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 88 deletions.
3 changes: 0 additions & 3 deletions AppExamples/discord/discordweb/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import IframeComponent from './IframeComponent';
import { Call } from './components/Call'

function App() {
return (
<div className="bg-zinc-900 h-screen w-screen flex justify-center items-center">
<IframeComponent>
<Call />
</IframeComponent>
</div>
);
}
Expand Down
80 changes: 0 additions & 80 deletions AppExamples/discord/discordweb/src/IframeComponent.tsx

This file was deleted.

2 changes: 2 additions & 0 deletions AppExamples/discord/discordweb/src/components/Call.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import messageStore from '../stores/messageStore'
import Controls from './Controls'
import Profile from './Profile'
import discordStore, { userData } from '../stores/discordStore'
Expand All @@ -7,6 +8,7 @@ export const Call = () => {
const [callData, setCallData] = useState<userData[]>([])

useEffect(() => {
messageStore.sendMessageToParent('server', 'message', 'message', 'Helloooooo')
const handleCallDataUpdate = (data: userData[]) => {
setCallData(data)
console.log('Callback data',data)
Expand Down
11 changes: 9 additions & 2 deletions AppExamples/discord/discordweb/src/stores/messageStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class MessageStore {

constructor() {
this.initialize();
this.sendMessageToParent('server', 'message', undefined, 'Hello from the discord app!')
}

private initialize() {
Expand Down Expand Up @@ -75,9 +76,15 @@ class MessageStore {
this.listeners = this.listeners.filter(listener => listener !== callback);
}

public sendMessageToParent() {
public sendMessageToParent(app?: string, request?: string, type?: string, data?: any) {
const payload = {
app: app || 'discord',
type: type || 'message',
request: request || null,
data: data || null
};
window.parent.postMessage(
{ type: 'IFRAME_ACTION', payload: 'Some data from iframe' },
{ type: 'IFRAME_ACTION', payload: payload },
'*' // Use a specific origin if possible for security
);
}
Expand Down
15 changes: 13 additions & 2 deletions DeskThing/src/views/web/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,24 @@ const WebView: React.FC<WebViewProps> = ({ currentView }) => {
if (event.origin != `http://${ip}:${port}`) return

console.log('Received message from iframe:', event)
};
if (socket.is_ready()) {
const payload = event.data.payload
const data = {
app: payload.app || currentView,
type: payload.type || null,
request: payload.request || null,
data: payload.data || null,
};
socket.post(data);
}
}

window.addEventListener('message', handleMessage);

return () => {
window.removeEventListener('message', handleMessage);
};
}, []);
}, [currentView, ip, port, socket]);

const sendMessageToIframe = (data: any) => {
if (iframeRef.current && iframeRef.current.contentWindow) {
Expand All @@ -52,6 +62,7 @@ const WebView: React.FC<WebViewProps> = ({ currentView }) => {

const handleTouchStart = () => {
setSwipeVisible(true)
sendMessageToIframe({ type: 'message', data: 'hello' })
}

const handleTouchEnd = () => {
Expand Down
16 changes: 15 additions & 1 deletion DeskThingServer/src/renderer/src/components/Dev/Apps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useAppStore, App } from '../../store/appStore'
import { IconX, IconPause, IconPlay, IconDetails, IconPulsing } from '../icons'
import DisplayAppData from '../Overlays/DisplayAppData'
import RequestStoreInstance, { Request } from '../../store/requestStore'
import AppRequestOverlay from '../Overlays/AppRequest'

export type View = 'apps' | 'local' | 'web'

Expand All @@ -13,6 +14,8 @@ const Apps = (): JSX.Element => {
const [enabled, setEnabled] = useState(false)
const [appIndex, setAppIndex] = useState(-1)
const [appsWithActiveRequests, setAppsWithActiveRequests] = useState<string[]>([])
const [currentRequest, setCurrentRequest] = useState<Request | null>(null)
const [displayRequest, setDisplayRequest] = useState(false)
const [path, setPath] = useState('')

const handleAddAndRunApp = (appName: string): void => {
Expand Down Expand Up @@ -63,12 +66,23 @@ const Apps = (): JSX.Element => {
}, [])

const handleRequestTrigger = (appName: string): void => {
RequestStoreInstance.triggerRequestDisplay(appName)
const request = RequestStoreInstance.getRequestByAppName(appName)
if (request) {
setCurrentRequest(request)
setDisplayRequest(true)
}
}

return (
<div className="h-svh w-[100%] flex flex-col justify-between items-center">
<div className="pt-5 w-full flex justify-center">
{displayRequest && currentRequest && app && (
<AppRequestOverlay
requestName={app.name}
request={currentRequest}
onClose={() => setDisplayRequest(false)}
/>
)}
{enabled && <DisplayAppData appIndex={appIndex} setEnabled={setEnabled} app={app} />}
<div className="pt-5 w-full flex 2xl:flex-row 2xl:flex-wrap flex-col items-center gap-2">
<p className="italic text-red-700 font-geistMono">
Expand Down

0 comments on commit 9f54c1a

Please sign in to comment.