11// src/components/Desktop.js
22
3- import { useState } from 'react' ;
3+ import React , { useState , useEffect } from 'react' ;
44import { useApp } from '@/context/AppContext' ;
55import { useTheme } from '@/context/ThemeContext' ;
66import { useSettings } from '@/context/SettingsContext' ;
@@ -24,6 +24,7 @@ import SettingsApp from '@/pages/apps/settings';
2424import MonitorApp from '@/pages/apps/monitor' ;
2525import FilemanagerApp from '@/pages/apps/filemanager' ;
2626import Calculator from '@/pages/apps/calculator' ;
27+ import AppStoreApp from '@/pages/apps/appstore' ;
2728import TabManager from './TabManager' ;
2829
2930const appComponents = {
@@ -33,9 +34,68 @@ const appComponents = {
3334 monitor : MonitorApp ,
3435 filemanager : FilemanagerApp ,
3536 calculator : Calculator ,
37+ appstore : AppStoreApp ,
3638 'tab-manager' : TabManager ,
3739} ;
3840
41+ // Dynamic app component for installed apps
42+ const DynamicApp = ( { appId } ) => {
43+ const [ AppComponent , setAppComponent ] = useState ( null ) ;
44+ const [ loading , setLoading ] = useState ( true ) ;
45+ const [ error , setError ] = useState ( null ) ;
46+
47+ useEffect ( ( ) => {
48+ const loadApp = async ( ) => {
49+ try {
50+ // Get app code from GitHub
51+ const response = await fetch (
52+ `https://raw.githubusercontent.com/codehubbers/OrbitOSPackages/main/${ appId } /App.jsx` ,
53+ ) ;
54+ const appCode = await response . text ( ) ;
55+
56+ // Create sandboxed component
57+ const componentFactory = new Function (
58+ 'React' ,
59+ `
60+ ${ appCode }
61+ return App;
62+ ` ,
63+ ) ;
64+
65+ const Component = componentFactory ( React ) ;
66+ setAppComponent ( ( ) => Component ) ;
67+ } catch ( err ) {
68+ setError ( err . message ) ;
69+ } finally {
70+ setLoading ( false ) ;
71+ }
72+ } ;
73+
74+ loadApp ( ) ;
75+ } , [ appId ] ) ;
76+
77+ if ( loading )
78+ return React . createElement (
79+ 'div' ,
80+ { style : { padding : '20px' } } ,
81+ 'Loading app...' ,
82+ ) ;
83+ if ( error )
84+ return React . createElement (
85+ 'div' ,
86+ { style : { padding : '20px' , color : 'red' } } ,
87+ `Error: ${ error } ` ,
88+ ) ;
89+ if ( ! AppComponent )
90+ return React . createElement (
91+ 'div' ,
92+ { style : { padding : '20px' } } ,
93+ 'App not found' ,
94+ ) ;
95+
96+ return React . createElement ( AppComponent ) ;
97+ } ;
98+
3999export default function Desktop ( ) {
40100 const { state } = useApp ( ) ;
41101 const { theme } = useTheme ( ) ;
@@ -135,6 +195,15 @@ export default function Desktop() {
135195 const services = createAppServices ( app ) ;
136196 const AppComponent = appComponents [ app . component ] ;
137197
198+ // Handle dynamic installed apps
199+ if ( ! AppComponent && app . component ) {
200+ return (
201+ < Window key = { app . id } app = { app } >
202+ < DynamicApp appId = { app . component } />
203+ </ Window >
204+ ) ;
205+ }
206+
138207 if ( ! AppComponent )
139208 return (
140209 < div key = { app . id } > App component not found for: { app . component } </ div >
0 commit comments