1- import { ClassicyMenuItem } from '@/app/SystemFolder/SystemResources/Menu/ClassicyMenu '
1+ import { classicyQuickTimeEventHandler } from '@/app/Applications/QuickTime/QuickTimeContext '
22import {
33 ClassicyStoreSystemAppearanceManager ,
44 ClassicyTheme ,
55} from '@/app/SystemFolder/ControlPanels/AppearanceManager/ClassicyAppearance'
6+ import themesData from '@/app/SystemFolder/ControlPanels/AppearanceManager/styles/themes.json'
7+ import { classicyDateTimeManagerEventHandler } from '@/app/SystemFolder/ControlPanels/DateAndTimeManager/ClassicyDateAndTimeManager.app'
8+ import { ClassicyStoreSystemSoundManager } from '@/app/SystemFolder/ControlPanels/SoundManager/ClassicySoundManagerContext'
9+ import { classicyFinderEventHandler } from '@/app/SystemFolder/Finder/FinderContext'
10+ import { classicyDesktopIconEventHandler } from '@/app/SystemFolder/SystemResources/Desktop/ClassicyDesktopIconContext'
611import {
712 classicyDesktopEventHandler ,
813 ClassicyStoreSystemDesktopManager ,
914} from '@/app/SystemFolder/SystemResources/Desktop/ClassicyDesktopManager'
1015import { classicyWindowEventHandler } from '@/app/SystemFolder/SystemResources/Desktop/ClassicyDesktopWindowManagerContext'
11- import { classicyDesktopIconEventHandler } from '@/app/SystemFolder/SystemResources/Desktop/ClassicyDesktopIconContext'
12- import themesData from '@/app/SystemFolder/ControlPanels/AppearanceManager/styles/themes.json'
13- import { classicyDateTimeManagerEventHandler } from '@/app/SystemFolder/ControlPanels/DateAndTimeManager/ClassicyDateAndTimeManager.app'
14- import { classicyFinderEventHandler } from '@/app/SystemFolder/Finder/FinderContext'
15- import { ClassicyStoreSystemSoundManager } from '@/app/SystemFolder/ControlPanels/SoundManager/ClassicySoundManagerContext'
16- import { classicyQuickTimeEventHandler } from '@/app/Applications/QuickTime/QuickTimeContext'
16+ import { ClassicyMenuItem } from '@/app/SystemFolder/SystemResources/Menu/ClassicyMenu'
1717
1818export interface ClassicyStoreSystemAppManager extends ClassicyStoreSystemManager {
19- apps : ClassicyStoreSystemApp [ ]
19+ apps : Record < string , ClassicyStoreSystemApp >
2020}
2121
2222export interface ClassicyStoreSystemApp {
@@ -90,94 +90,92 @@ export interface ClassicyStoreSystemManager {}
9090
9191export class ClassicyAppManagerHandler {
9292 public getAppIndex ( ds : ClassicyStore , appId : string ) {
93- return ds . System . Manager . App . apps . findIndex ( ( d ) => d . id === appId )
93+ return ds . System . Manager . App . apps [ appId ]
9494 }
9595
9696 public deFocusApps ( ds : ClassicyStore ) {
97- ds . System . Manager . App . apps = ds . System . Manager . App . apps . map ( ( a ) => {
98- a . focused = false
99- a . windows = a . windows . map ( ( w ) => {
97+ Object . entries ( ds . System . Manager . App . apps ) . forEach ( ( [ key ] ) => {
98+ ds . System . Manager . App . apps [ key ] . focused = false
99+ ds . System . Manager . App . apps [ key ] . windows = ds . System . Manager . App . apps [ key ] . windows . map ( ( w ) => {
100100 w . focused = false
101101 return w
102102 } )
103- return a
104103 } )
105104 return ds
106105 }
107106
108107 public focusApp ( ds : ClassicyStore , appId : string ) {
109- const findApp = this . getAppIndex ( ds , appId )
110108 ds = this . deFocusApps ( ds )
111- ds . System . Manager . App . apps [ findApp ] . focused = true
112- const focusedWindow = ds . System . Manager . App . apps [ findApp ] . windows . findIndex ( ( w ) => w . default )
109+ if ( ds . System . Manager . App . apps [ appId ] ) {
110+ ds . System . Manager . App . apps [ appId ] . focused = true
111+ }
112+ const focusedWindow = ds . System . Manager . App . apps [ appId ] ?. windows . findIndex ( ( w ) => w . default )
113113 if ( focusedWindow >= 0 ) {
114- ds . System . Manager . App . apps [ findApp ] . windows [ focusedWindow ] . closed = false
115- ds . System . Manager . App . apps [ findApp ] . windows [ focusedWindow ] . focused = true
116- ds . System . Manager . Desktop . appMenu = ds . System . Manager . App . apps [ findApp ] . appMenu
117- } else if ( ds . System . Manager . App . apps [ findApp ] . windows . length > 0 ) {
118- ds . System . Manager . App . apps [ findApp ] . windows [ 0 ] . closed = false
119- ds . System . Manager . App . apps [ findApp ] . windows [ 0 ] . focused = true
120- ds . System . Manager . Desktop . appMenu = ds . System . Manager . App . apps [ findApp ] . appMenu
114+ ds . System . Manager . App . apps [ appId ] . windows [ focusedWindow ] . closed = false
115+ ds . System . Manager . App . apps [ appId ] . windows [ focusedWindow ] . focused = true
116+ ds . System . Manager . Desktop . appMenu = ds . System . Manager . App . apps [ appId ] . appMenu
117+ } else if ( ds . System . Manager . App . apps [ appId ] ? .windows . length > 0 ) {
118+ ds . System . Manager . App . apps [ appId ] . windows [ 0 ] . closed = false
119+ ds . System . Manager . App . apps [ appId ] . windows [ 0 ] . focused = true
120+ ds . System . Manager . Desktop . appMenu = ds . System . Manager . App . apps [ appId ] . appMenu
121121 }
122122 }
123123
124124 public openApp ( ds : ClassicyStore , appId : string , appName : string , appIcon : string ) {
125- const findApp = this . getAppIndex ( ds , appId )
126- if ( findApp >= 0 ) {
127- ds . System . Manager . App . apps [ findApp ] . open = true
128- ds . System . Manager . App . apps [ findApp ] . windows = ds . System . Manager . App . apps [ findApp ] . windows . map ( ( w ) => {
125+ const findApp = ds . System . Manager . App . apps [ appId ]
126+ if ( findApp ) {
127+ ds . System . Manager . App . apps [ appId ] . open = true
128+ ds . System . Manager . App . apps [ appId ] . windows = ds . System . Manager . App . apps [ appId ] . windows . map ( ( w ) => {
129129 w . closed = false
130130 return w
131131 } )
132132 this . focusApp ( ds , appId )
133133 } else {
134- ds . System . Manager . App . apps . push ( {
134+ ds . System . Manager . App . apps [ appId ] = {
135135 id : appId ,
136136 name : appName ,
137137 icon : appIcon ,
138138 windows : [ ] ,
139139 open : true ,
140140 data : { } ,
141- } )
141+ }
142142 }
143143 }
144144
145145 public loadApp ( ds : ClassicyStore , appId : string , appName : string , appIcon : string ) {
146- const findApp = this . getAppIndex ( ds , appId )
147- if ( findApp < 0 ) {
148- ds . System . Manager . App . apps . push ( {
146+ const findApp = ds . System . Manager . App . apps [ appId ]
147+ if ( ! findApp ) {
148+ ds . System . Manager . App . apps [ appId ] = {
149149 id : appId ,
150150 name : appName ,
151151 icon : appIcon ,
152152 windows : [ ] ,
153153 open : false ,
154154 data : { } ,
155- } )
155+ }
156156 }
157157 }
158158
159159 public closeApp ( ds : ClassicyStore , appId : string ) {
160- const findApp = this . getAppIndex ( ds , appId )
161- if ( findApp >= 0 ) {
162- ds . System . Manager . App . apps [ findApp ] . open = false
163- ds . System . Manager . App . apps [ findApp ] . focused = false
164- ds . System . Manager . App . apps [ findApp ] . windows . map ( ( w ) => ( w . closed = true ) )
160+ const findApp = ds . System . Manager . App . apps [ appId ]
161+ if ( findApp ) {
162+ ds . System . Manager . App . apps [ appId ] . open = false
163+ ds . System . Manager . App . apps [ appId ] . focused = false
164+ ds . System . Manager . App . apps [ appId ] . windows ? .map ( ( w ) => ( w . closed = true ) )
165165 }
166166 }
167167
168168 public activateApp ( ds : ClassicyStore , appId : string ) {
169- ds . System . Manager . App . apps = ds . System . Manager . App . apps . map ( ( a ) => {
170- a . focused = a . id === appId
171- return a
169+ Object . entries ( ds . System . Manager . App . apps ) . forEach ( ( [ key ] ) => {
170+ ds . System . Manager . App . apps [ key ] . focused = key === appId
172171 } )
173- ds . System . Manager . App . apps = ds . System . Manager . App . apps . map ( ( a ) => {
174- if ( a . id !== appId ) {
175- a . windows = a . windows . map ( ( w ) => {
172+ Object . entries ( ds . System . Manager . App . apps ) . forEach ( ( [ key ] ) => {
173+ if ( key !== appId ) {
174+ ds . System . Manager . App . apps [ key ] . windows = ds . System . Manager . App . apps [ key ] . windows . map ( ( w ) => {
176175 w . focused = false
177176 return w
178177 } )
179178 }
180- return a
181179 } )
182180 }
183181}
@@ -197,8 +195,10 @@ export const classicyAppEventHandler = (ds: ClassicyStore, action) => {
197195 case 'ClassicyAppClose' : {
198196 handler . closeApp ( ds , action . app . id )
199197 const lastOpenApp = ( ) => {
200- const openApps = ds . System . Manager . App . apps . filter ( ( w ) => w . open )
201- return openApps [ 0 ] . id
198+ const openApps = Object . values ( ds . System . Manager . App . apps ) . find ( ( value ) => {
199+ return value . open === true
200+ } )
201+ return openApps [ 0 ] ?. id
202202 }
203203 handler . focusApp ( ds , lastOpenApp ( ) )
204204 break
@@ -290,8 +290,8 @@ export const DefaultDesktopState: ClassicyStore = {
290290 } ,
291291 } ,
292292 App : {
293- apps : [
294- {
293+ apps : {
294+ 'Finder.app' : {
295295 id : 'Finder.app' ,
296296 name : 'Finder' ,
297297 icon : `${ process . env . NEXT_PUBLIC_BASE_PATH || '' } /img/icons/system/macos.svg` ,
@@ -302,15 +302,15 @@ export const DefaultDesktopState: ClassicyStore = {
302302 openOnBoot : true ,
303303 data : { } ,
304304 } ,
305- {
305+ 'QuickTimePlayer.app' : {
306306 id : 'QuickTimePlayer.app' ,
307307 name : 'QuickTime Player' ,
308308 icon : `${ process . env . NEXT_PUBLIC_BASE_PATH || '' } /img/icons/system/quicktime/player.png` ,
309309 windows : [ ] ,
310310 open : false ,
311311 data : { } ,
312312 } ,
313- ] ,
313+ } ,
314314 } ,
315315 Appearance : {
316316 availableThemes : themesData as unknown as ClassicyTheme [ ] ,
0 commit comments