Skip to content

Commit 710429b

Browse files
committed
#99 Updates to App Manager
Use a Record<string, ClassicyStoreSystemApp> type instead of an array to store Classicy App Manager records
1 parent 7f5f615 commit 710429b

File tree

17 files changed

+265
-247
lines changed

17 files changed

+265
-247
lines changed

src/app/Applications/EPG/EPG.module.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
}
9595

9696
.epgGridAnimatedBackground {
97-
animation: stripeSlide 1s linear infinite;
97+
animation: stripeSlide 3s linear infinite;
9898
animation-play-state: running;
9999
background-color: var(--color-system-03);
100100
background-repeat: repeat;

src/app/Applications/QuickTime/QuickTimeContext.tsx

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { classicyAppEventHandler, ClassicyStore } from '@/app/SystemFolder/ControlPanels/AppManager/ClassicyAppManager'
21
import { QuickTimeAppInfo } from '@/app/Applications/QuickTime/QuickTimeMoviePlayer'
2+
import { classicyAppEventHandler, ClassicyStore } from '@/app/SystemFolder/ControlPanels/AppManager/ClassicyAppManager'
33

44
type classicyQuickTimeDocument = {
55
url: string
@@ -16,39 +16,38 @@ type classicyQuickTimeEvent = {
1616

1717
export const classicyQuickTimeEventHandler = (ds: ClassicyStore, action: classicyQuickTimeEvent) => {
1818
const { id: appId } = QuickTimeAppInfo
19-
const appIndex = ds.System.Manager.App.apps.findIndex((app) => app.id === appId)
20-
if (appIndex === -1) {
19+
if (!ds.System.Manager.App.apps[appId]) {
2120
ds = classicyAppEventHandler(ds, {
2221
type: 'ClassicyAppLoad',
2322
app: QuickTimeAppInfo,
2423
})
2524
}
26-
if (!ds.System.Manager.App.apps[appIndex]?.hasOwnProperty('data')) {
27-
ds.System.Manager.App.apps[appIndex].data = {}
25+
if (!ds.System.Manager.App.apps[appId]?.hasOwnProperty('data')) {
26+
ds.System.Manager.App.apps[appId].data = {}
2827
}
29-
if (!ds.System.Manager.App.apps[appIndex]?.data?.hasOwnProperty('openFiles')) {
30-
ds.System.Manager.App.apps[appIndex].data['openFiles'] = []
28+
if (!ds.System.Manager.App.apps[appId]?.data?.hasOwnProperty('openFiles')) {
29+
ds.System.Manager.App.apps[appId].data['openFiles'] = []
3130
}
32-
const openDocUrls = ds.System.Manager.App.apps[appIndex].data['openFiles'].map((app) => app.url)
31+
const openDocUrls = ds.System.Manager.App.apps[appId].data['openFiles'].map((app) => app.url)
3332

3433
switch (action.type) {
3534
case 'ClassicyAppQuickTimeOpenDocument': {
3635
if (Array.isArray(openDocUrls) && !openDocUrls.includes(action.document.url)) {
37-
ds.System.Manager.App.apps[appIndex].data['openFiles'] = Array.from(
38-
new Set([...ds.System.Manager.App.apps[appIndex].data['openFiles'], action.document])
36+
ds.System.Manager.App.apps[appId].data['openFiles'] = Array.from(
37+
new Set([...ds.System.Manager.App.apps[appId].data['openFiles'], action.document])
3938
)
4039
}
4140
break
4241
}
4342
case 'ClassicyAppQuickTimeOpenDocuments': {
4443
const docs = action.documents.filter((doc) => !openDocUrls.includes(doc.url))
45-
ds.System.Manager.App.apps[appIndex].data['openFiles'] = Array.from(
46-
new Set([...ds.System.Manager.App.apps[appIndex].data['openFiles'], ...docs])
44+
ds.System.Manager.App.apps[appId].data['openFiles'] = Array.from(
45+
new Set([...ds.System.Manager.App.apps[appId].data['openFiles'], ...docs])
4746
)
4847
break
4948
}
5049
case 'ClassicyAppQuickTimeCloseDocument': {
51-
ds.System.Manager.App.apps[appIndex].data['openFiles'] = ds.System.Manager.App.apps[appIndex].data[
50+
ds.System.Manager.App.apps[appId].data['openFiles'] = ds.System.Manager.App.apps[appId].data[
5251
'openFiles'
5352
].filter((p: classicyQuickTimeDocument) => p.url != action.document.url)
5453
break

src/app/Applications/QuickTime/QuickTimeMoviePlayer.tsx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
import quickTimeStyles from '@/app/Applications/QuickTime/QuickTime.module.scss'
2+
import { useDesktop, useDesktopDispatch } from '@/app/SystemFolder/ControlPanels/AppManager/ClassicyAppManagerContext'
13
import ClassicyApp from '@/app/SystemFolder/SystemResources/App/ClassicyApp'
24
import { quitAppHelper } from '@/app/SystemFolder/SystemResources/App/ClassicyAppUtils'
3-
import { useDesktop, useDesktopDispatch } from '@/app/SystemFolder/ControlPanels/AppManager/ClassicyAppManagerContext'
45
import ClassicyWindow from '@/app/SystemFolder/SystemResources/Window/ClassicyWindow'
6+
import { parse } from '@plussub/srt-vtt-parser'
57
import React, { Suspense, useCallback, useEffect, useRef, useState } from 'react'
68
import ReactPlayer from 'react-player'
7-
import quickTimeStyles from '@/app/Applications/QuickTime/QuickTime.module.scss'
89
import screenfull from 'screenfull'
9-
import { parse } from '@plussub/srt-vtt-parser'
1010
import { getVolumeIcon, timeFriendly } from './QuickTimeUtils'
1111

1212
export type QuickTimeDocument = {
@@ -31,12 +31,11 @@ const QuickTimeMoviePlayer: React.FC = () => {
3131
const desktop = useDesktop()
3232

3333
const defaultDocumentIcon = `${process.env.NEXT_PUBLIC_BASE_PATH || ''}/img/icons/system/quicktime/movie.png`
34-
const appIndex = desktop.System.Manager.App.apps.findIndex((app) => app.id === appId)
35-
const openDocuments = desktop.System.Manager.App.apps[appIndex]?.data['openFiles']
34+
const openDocuments = desktop.System.Manager.App.apps[appId]?.data['openFiles']
3635

3736
// Load Default Demo documents on open
3837
useEffect(() => {
39-
const appData = desktop.System.Manager.App.apps[appIndex]?.data || {}
38+
const appData = desktop.System.Manager.App.apps[appId]?.data || {}
4039
if (!appData['openDocuments'] || appData['openDocuments'].length === 0) {
4140
const defaultDocs = [
4241
{
@@ -75,10 +74,10 @@ const QuickTimeMoviePlayer: React.FC = () => {
7574
document: { name, url: url, icon: iconUrl || defaultDocumentIcon },
7675
})
7776

78-
const windowIndex = desktop.System.Manager.App.apps[appIndex].windows.findIndex(
77+
const windowIndex = desktop.System.Manager.App.apps[appId].windows.findIndex(
7978
(w) => w.id === appId + '_VideoPlayer_' + url
8079
)
81-
const ws = desktop.System.Manager.App.apps[appIndex].windows[windowIndex]
80+
const ws = desktop.System.Manager.App.apps[appId].windows[windowIndex]
8281
if (ws) {
8382
ws.closed = false
8483
desktopEventDispatch({
@@ -230,8 +229,7 @@ const QuickTimeVideoEmbed: React.FC<QuickTimeVideoEmbed> = ({ appId, name, url,
230229

231230
useEffect(() => {
232231
const handleKeyDown = (event) => {
233-
const appIndex = desktop.System.Manager.App.apps.findIndex((app) => app.id === appId)
234-
const { windows } = desktop.System.Manager.App.apps[appIndex]
232+
const { windows } = desktop.System.Manager.App.apps[appId]
235233
const a = windows.find((w) => (w.id = appId + '_VideoPlayer_' + url))
236234
if (!a.focused) {
237235
return

src/app/SystemFolder/ControlPanels/AppManager/ClassicyAppManager.ts

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
import { ClassicyMenuItem } from '@/app/SystemFolder/SystemResources/Menu/ClassicyMenu'
1+
import { classicyQuickTimeEventHandler } from '@/app/Applications/QuickTime/QuickTimeContext'
22
import {
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'
611
import {
712
classicyDesktopEventHandler,
813
ClassicyStoreSystemDesktopManager,
914
} from '@/app/SystemFolder/SystemResources/Desktop/ClassicyDesktopManager'
1015
import { 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

1818
export interface ClassicyStoreSystemAppManager extends ClassicyStoreSystemManager {
19-
apps: ClassicyStoreSystemApp[]
19+
apps: Record<string, ClassicyStoreSystemApp>
2020
}
2121

2222
export interface ClassicyStoreSystemApp {
@@ -90,94 +90,92 @@ export interface ClassicyStoreSystemManager {}
9090

9191
export 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[],
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
'use client'
22

3-
import React from 'react'
4-
53
import { ClassicyAppearanceManager } from '@/app/SystemFolder/ControlPanels/AppearanceManager/ClassicyAppearanceManager'
4+
import { ClassicyDateAndTimeManager } from '@/app/SystemFolder/ControlPanels/DateAndTimeManager/ClassicyDateAndTimeManager.app'
65
import { ClassicySoundManager } from '@/app/SystemFolder/ControlPanels/SoundManager/ClassicySoundManager'
7-
import { ClassicyDateAndTimeManagerApp } from '@/app/SystemFolder/ControlPanels/DateAndTimeManager/ClassicyDateAndTimeManager.app'
6+
import React from 'react'
87

98
export default function ClassicyControlPanels() {
109
return (
1110
<>
1211
<ClassicyAppearanceManager />
1312
<ClassicySoundManager />
14-
<ClassicyDateAndTimeManagerApp />
13+
<ClassicyDateAndTimeManager />
1514
</>
1615
)
1716
}

src/app/SystemFolder/ControlPanels/DateAndTimeManager/ClassicyDateAndTimeManager.app.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ import ClassicyWindow from '@/app/SystemFolder/SystemResources/Window/ClassicyWi
1414
import React, { ChangeEvent, useState } from 'react'
1515
import ClassicyControlGroup from '../../SystemResources/ControlGroup/ClassicyControlGroup'
1616

17-
export const ClassicyDateAndTimeManagerApp: React.FC = () => {
17+
export const ClassicyDateAndTimeManager: React.FC = () => {
1818
const appName: string = 'Date and Time Manager'
1919
const appId: string = 'DateAndTimeManager.app'
2020
const appIcon: string = `${process.env.NEXT_PUBLIC_BASE_PATH || ''}/img/icons/control-panels/date-time-manager/date-time-manager.png`
2121

22+
const [period, setPeriod] = useState<string>('am')
23+
2224
const desktopContext = useDesktop(),
2325
desktopEventDispatch = useDesktopDispatch()
2426

@@ -29,20 +31,33 @@ export const ClassicyDateAndTimeManagerApp: React.FC = () => {
2931
}
3032

3133
const updateSystemTime = (updatedDate: Date) => {
34+
const date = new Date(desktopContext.System.Manager.DateAndTime.dateTime)
35+
36+
let hoursToSet = period == 'am' ? updatedDate.getHours() : updatedDate.getHours() + 12
37+
if (period == 'am' && updatedDate.getHours() == 12) {
38+
hoursToSet = 0
39+
}
40+
date.setHours(hoursToSet, updatedDate.getMinutes(), updatedDate.getSeconds())
3241
desktopEventDispatch({
3342
type: 'ClassicyManagerDateTimeSet',
34-
dateTime: updatedDate,
43+
dateTime: date,
3544
})
3645
}
3746

3847
const updateDate = (updatedDate: Date) => {
48+
const date = new Date(desktopContext.System.Manager.DateAndTime.dateTime)
49+
date.setMonth(updatedDate.getMonth())
50+
date.setDate(updatedDate.getDate())
51+
date.setFullYear(updatedDate.getFullYear())
52+
3953
desktopEventDispatch({
4054
type: 'ClassicyManagerDateTimeSet',
41-
dateTime: updatedDate,
55+
dateTime: date,
4256
})
4357
}
4458

4559
const updateTimeZone = (e: ChangeEvent<HTMLSelectElement>) => {
60+
setPeriod(e.target.value)
4661
desktopEventDispatch({
4762
type: 'ClassicyManagerDateTimeTZSet',
4863
tzOffset: e.target.value,

0 commit comments

Comments
 (0)