@owdproject/core 3.1.2 → 3.1.4-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/README.md +9 -10
- package/bin/owd.js +14 -14
- package/index.ts +5 -2
- package/module.ts +64 -55
- package/package.json +19 -17
- package/project.json +4 -0
- package/runtime/components/Core/Application/CoreApplicationRender.vue +6 -5
- package/runtime/components/Core/Application/CoreApplicationWindowsRender.vue +8 -8
- package/runtime/components/Core/Background/CoreBackground.vue +1 -1
- package/runtime/components/Core/Desktop/CoreDesktop.vue +23 -20
- package/runtime/components/Core/Explorer/CoreExplorerFile.vue +47 -38
- package/runtime/components/Core/Explorer/CoreExplorerFolder.vue +0 -1
- package/runtime/components/Core/Time/CoreTime.vue +10 -7
- package/runtime/components/Core/Window/CoreWindow.vue +46 -34
- package/runtime/components/Core/Window/CoreWindowContent.vue +3 -5
- package/runtime/components/Core/Window/CoreWindowNav.vue +12 -7
- package/runtime/composables/useApplicationEntries.ts +51 -0
- package/runtime/composables/useApplicationManager.ts +3 -3
- package/runtime/composables/useClipboardFs.ts +11 -11
- package/runtime/composables/useDesktopManager.ts +2 -2
- package/runtime/composables/useTerminalManager.ts +3 -3
- package/runtime/core/controllers/ApplicationController.ts +211 -200
- package/runtime/core/controllers/WindowController.ts +349 -312
- package/runtime/core/managers/ApplicationManager.ts +240 -196
- package/runtime/core/managers/DesktopManager.ts +35 -25
- package/runtime/core/managers/TerminalManager.ts +36 -32
- package/runtime/plugins/resize.client.ts +4 -4
- package/runtime/stores/storeApplication.ts +235 -0
- package/runtime/stores/storeApplicationMeta.ts +12 -8
- package/runtime/stores/storeApplicationWindows.ts +16 -12
- package/runtime/stores/storeDesktop.ts +33 -29
- package/runtime/stores/storeDesktopVolume.ts +12 -12
- package/runtime/stores/storeDesktopWindow.ts +13 -13
- package/runtime/stores/storeDesktopWorkspace.ts +35 -31
- package/runtime/utils/utilApp.ts +27 -22
- package/runtime/utils/utilCommon.ts +43 -43
- package/runtime/utils/utilDebug.ts +17 -17
- package/runtime/utils/utilDesktop.ts +4 -4
- package/runtime/utils/utilTerminal.ts +6 -5
- package/runtime/utils/utilWindow.ts +11 -11
- package/test/fixtures/basic/app.vue +1 -2
- package/test/fixtures/basic/nuxt.config.ts +1 -3
- package/tsconfig.app.json +1 -1
- package/tsconfig.json +1 -1
- package/types/index.d.ts +235 -207
- package/vitest.config.ts +3 -3
- package/.editorconfig +0 -12
- package/eslint.config.mjs +0 -30
- package/runtime/composables/useAppEntries.ts +0 -36
|
@@ -1,244 +1,255 @@
|
|
|
1
|
-
import {nanoid} from
|
|
2
|
-
import {WindowController} from
|
|
3
|
-
import {useApplicationManager} from
|
|
4
|
-
import {useApplicationWindowsStore} from
|
|
5
|
-
import {useApplicationMetaStore} from
|
|
6
|
-
import {useTerminalManager} from
|
|
7
|
-
import {useDesktopManager} from
|
|
8
|
-
import {debugLog, debugError} from
|
|
9
|
-
import {useDesktopWorkspaceStore} from
|
|
10
|
-
import {reactive} from '@vue/reactivity'
|
|
1
|
+
import { nanoid } from 'nanoid'
|
|
2
|
+
import { WindowController } from './WindowController'
|
|
3
|
+
import { useApplicationManager } from '../../composables/useApplicationManager'
|
|
4
|
+
import { useApplicationWindowsStore } from '../../stores/storeApplicationWindows'
|
|
5
|
+
import { useApplicationMetaStore } from '../../stores/storeApplicationMeta'
|
|
6
|
+
import { useTerminalManager } from '../../composables/useTerminalManager'
|
|
7
|
+
import { useDesktopManager } from '../../composables/useDesktopManager'
|
|
8
|
+
import { debugLog, debugError } from '../../utils/utilDebug'
|
|
9
|
+
import { useDesktopWorkspaceStore } from '../../stores/storeDesktopWorkspace'
|
|
10
|
+
import { reactive } from '@vue/reactivity'
|
|
11
11
|
|
|
12
12
|
export class ApplicationController implements IApplicationController {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
13
|
+
private readonly applicationManager: IApplicationManager
|
|
14
|
+
private readonly desktopManager: IDesktopManager
|
|
15
|
+
private readonly terminalManager: ITerminalManager
|
|
16
|
+
|
|
17
|
+
public readonly id
|
|
18
|
+
public readonly config
|
|
19
|
+
public readonly storeWindows
|
|
20
|
+
public readonly storeMeta
|
|
21
|
+
|
|
22
|
+
public windows = reactive(new Map<string, IWindowController>())
|
|
23
|
+
|
|
24
|
+
public isRunning = false
|
|
25
|
+
|
|
26
|
+
constructor(id: string, config: ApplicationConfig) {
|
|
27
|
+
this.applicationManager = useApplicationManager()
|
|
28
|
+
this.terminalManager = useTerminalManager()
|
|
29
|
+
this.desktopManager = useDesktopManager()
|
|
30
|
+
|
|
31
|
+
this.id = id
|
|
32
|
+
this.config = config
|
|
33
|
+
this.storeWindows = useApplicationWindowsStore(id)
|
|
34
|
+
this.storeMeta = useApplicationMetaStore(id)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public async initApplication(): Promise<void> {
|
|
38
|
+
// provides
|
|
39
|
+
|
|
40
|
+
// set as default app for specific purposes
|
|
41
|
+
// todo improve this and move it in a store
|
|
42
|
+
if (this.config.provides) {
|
|
43
|
+
const existingDefault = this.desktopManager.getDefaultApp(
|
|
44
|
+
this.config.provides.name,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
if (!existingDefault) {
|
|
48
|
+
this.desktopManager.setDefaultApp(
|
|
49
|
+
this.config.provides.name,
|
|
50
|
+
this,
|
|
51
|
+
this.config.provides.command,
|
|
52
|
+
)
|
|
24
53
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
this.applicationManager = useApplicationManager()
|
|
30
|
-
this.terminalManager = useTerminalManager()
|
|
31
|
-
this.desktopManager = useDesktopManager()
|
|
32
|
-
|
|
33
|
-
this.id = id
|
|
34
|
-
this.config = config
|
|
35
|
-
this.storeWindows = useApplicationWindowsStore(id)
|
|
36
|
-
this.storeMeta = useApplicationMetaStore(id)
|
|
54
|
+
debugLog(
|
|
55
|
+
`${this.config.title} has been set as predefined app for "${this.config.provides.name}"`,
|
|
56
|
+
)
|
|
57
|
+
}
|
|
37
58
|
}
|
|
38
59
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
// provides
|
|
42
|
-
|
|
43
|
-
// set as default app for specific purposes
|
|
44
|
-
// todo improve this and move it in a store
|
|
45
|
-
if (this.config.provides) {
|
|
46
|
-
const existingDefault = this.desktopManager.getDefaultApp(this.config.provides.name)
|
|
47
|
-
|
|
48
|
-
if (!existingDefault) {
|
|
49
|
-
this.desktopManager.setDefaultApp(
|
|
50
|
-
this.config.provides.name,
|
|
51
|
-
this,
|
|
52
|
-
this.config.entries[this.config.provides.entry] as ApplicationEntry
|
|
53
|
-
)
|
|
54
|
-
|
|
55
|
-
debugLog(`${this.config.title} has been set as predefined app for "${this.config.provides.name}"`)
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// terminal
|
|
60
|
+
// terminal
|
|
60
61
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// store
|
|
71
|
-
|
|
72
|
-
if (this.storeWindows.$persistedState) {
|
|
73
|
-
await this.storeWindows.$persistedState.isReady()
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (this.storeMeta.$persistedState) {
|
|
77
|
-
await this.storeMeta.$persistedState.isReady()
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// set default meta values
|
|
81
|
-
// this.storeMeta.meta = this.config.meta ?? {}
|
|
82
|
-
|
|
83
|
-
// restore application state
|
|
84
|
-
await this.restoreApplication()
|
|
85
|
-
|
|
86
|
-
// once app is defined, always run "onReady"
|
|
87
|
-
if (typeof this.config.onReady === 'function') {
|
|
88
|
-
// todo transform in hook
|
|
89
|
-
this.config.onReady(this)
|
|
90
|
-
}
|
|
62
|
+
if (this.config.commands) {
|
|
63
|
+
for (const commandKey of Object.keys(this.config.commands)) {
|
|
64
|
+
this.terminalManager.addCommand({
|
|
65
|
+
applicationId: this.id,
|
|
66
|
+
name: commandKey,
|
|
67
|
+
})
|
|
68
|
+
}
|
|
91
69
|
}
|
|
92
70
|
|
|
93
|
-
|
|
94
|
-
* App always tries to restore previous windows
|
|
95
|
-
* and returns a boolean if it succeeded
|
|
96
|
-
*/
|
|
97
|
-
public async restoreApplication() {
|
|
98
|
-
if (typeof this.config.onRestore === 'function') {
|
|
99
|
-
// todo transform in hook
|
|
100
|
-
await this.config.onRestore(this)
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
if (!this.storeWindows.windows || Object.keys(this.storeWindows.windows).length === 0) {
|
|
104
|
-
return false
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
this.restoreWindows()
|
|
71
|
+
// store
|
|
108
72
|
|
|
109
|
-
|
|
73
|
+
if (this.storeWindows.$persistedState) {
|
|
74
|
+
await this.storeWindows.$persistedState.isReady()
|
|
75
|
+
}
|
|
110
76
|
|
|
111
|
-
|
|
77
|
+
if (this.storeMeta.$persistedState) {
|
|
78
|
+
await this.storeMeta.$persistedState.isReady()
|
|
112
79
|
}
|
|
113
80
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
const windowStore: WindowStoredState | undefined = this.storeWindows.windows[windowId]
|
|
81
|
+
// set default meta values
|
|
82
|
+
// this.storeMeta.meta = this.config.meta ?? {}
|
|
117
83
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
})
|
|
84
|
+
// restore application state
|
|
85
|
+
await this.restoreApplication()
|
|
122
86
|
|
|
123
|
-
|
|
87
|
+
// once app is defined, always run "onReady"
|
|
88
|
+
if (typeof this.config.onReady === 'function') {
|
|
89
|
+
// todo transform in hook
|
|
90
|
+
this.config.onReady(this)
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* App always tries to restore previous windows
|
|
96
|
+
* and returns a boolean if it succeeded
|
|
97
|
+
*/
|
|
98
|
+
public async restoreApplication() {
|
|
99
|
+
if (typeof this.config.onRestore === 'function') {
|
|
100
|
+
// todo transform in hook
|
|
101
|
+
await this.config.onRestore(this)
|
|
124
102
|
}
|
|
125
103
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
let windowId: string
|
|
104
|
+
if (
|
|
105
|
+
!this.storeWindows.windows ||
|
|
106
|
+
Object.keys(this.storeWindows.windows).length === 0
|
|
107
|
+
) {
|
|
108
|
+
return false
|
|
109
|
+
}
|
|
135
110
|
|
|
136
|
-
|
|
111
|
+
this.restoreWindows()
|
|
137
112
|
|
|
138
|
-
|
|
113
|
+
this.setRunning(true)
|
|
139
114
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
const centerY = (screenHeight - Number(windowConfig.size.height)) / 2
|
|
143
|
-
const positionY = windowConfig.position?.y !== undefined
|
|
144
|
-
? window.scrollY + windowConfig.position.y
|
|
145
|
-
: window.scrollY + centerY
|
|
115
|
+
return true
|
|
116
|
+
}
|
|
146
117
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
active: true,
|
|
152
|
-
focused: false,
|
|
153
|
-
position: {
|
|
154
|
-
x: windowConfig.position?.x,
|
|
155
|
-
y: positionY,
|
|
156
|
-
},
|
|
157
|
-
createdAt: +new Date(),
|
|
158
|
-
workspace: desktopWorkspaceStore.active
|
|
159
|
-
},
|
|
160
|
-
meta
|
|
161
|
-
}
|
|
118
|
+
private restoreWindows() {
|
|
119
|
+
Object.keys(this.storeWindows.windows).map((windowId) => {
|
|
120
|
+
const windowStore: WindowStoredState | undefined =
|
|
121
|
+
this.storeWindows.windows[windowId]
|
|
162
122
|
|
|
163
|
-
|
|
123
|
+
if (windowStore) {
|
|
124
|
+
this.openWindow(windowStore.model, windowStore, {
|
|
125
|
+
isRestoring: true,
|
|
126
|
+
})
|
|
127
|
+
}
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
debugLog('Windows have been restored', this.windows)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
public openWindow(
|
|
134
|
+
model: string,
|
|
135
|
+
windowStoredState: WindowStoredState | undefined,
|
|
136
|
+
meta?: any,
|
|
137
|
+
) {
|
|
138
|
+
const desktopWorkspaceStore = useDesktopWorkspaceStore()
|
|
139
|
+
|
|
140
|
+
if (!this.config.windows || !this.config.windows.hasOwnProperty(model)) {
|
|
141
|
+
debugError(`Window model "${model}" not found`)
|
|
142
|
+
return
|
|
143
|
+
}
|
|
164
144
|
|
|
165
|
-
|
|
145
|
+
let windowId: string
|
|
146
|
+
|
|
147
|
+
if (!windowStoredState) {
|
|
148
|
+
windowId = `${model}-${nanoid(6)}`
|
|
149
|
+
|
|
150
|
+
const windowConfig: WindowConfig = this.config.windows[
|
|
151
|
+
model
|
|
152
|
+
] as WindowConfig
|
|
153
|
+
const screenHeight = window.innerHeight
|
|
154
|
+
const centerY = (screenHeight - Number(windowConfig.size.height)) / 2
|
|
155
|
+
const positionY =
|
|
156
|
+
windowConfig.position?.y !== undefined
|
|
157
|
+
? window.scrollY + windowConfig.position.y
|
|
158
|
+
: window.scrollY + centerY
|
|
159
|
+
|
|
160
|
+
this.storeWindows.windows[windowId] = {
|
|
161
|
+
model,
|
|
162
|
+
state: {
|
|
163
|
+
id: windowId,
|
|
164
|
+
active: true,
|
|
165
|
+
focused: false,
|
|
166
|
+
position: {
|
|
167
|
+
x: windowConfig.position?.x,
|
|
168
|
+
y: positionY,
|
|
169
|
+
},
|
|
170
|
+
createdAt: +new Date(),
|
|
171
|
+
workspace: desktopWorkspaceStore.active,
|
|
172
|
+
},
|
|
173
|
+
meta,
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
windowStoredState = this.storeWindows.windows[windowId]
|
|
177
|
+
} else {
|
|
178
|
+
// restore previous id if state is defined
|
|
179
|
+
windowId = windowStoredState.state.id
|
|
180
|
+
}
|
|
166
181
|
|
|
167
|
-
|
|
168
|
-
windowId = windowStoredState.state.id
|
|
182
|
+
const windowConfig = this.config.windows[model] as WindowConfig
|
|
169
183
|
|
|
170
|
-
|
|
184
|
+
const windowController = new WindowController(
|
|
185
|
+
this,
|
|
186
|
+
model,
|
|
187
|
+
windowConfig,
|
|
188
|
+
windowStoredState!,
|
|
189
|
+
)
|
|
171
190
|
|
|
172
|
-
|
|
191
|
+
if (!meta?.isRestoring) {
|
|
192
|
+
windowController.actions.bringToFront()
|
|
193
|
+
}
|
|
173
194
|
|
|
174
|
-
|
|
175
|
-
this,
|
|
176
|
-
model,
|
|
177
|
-
windowConfig,
|
|
178
|
-
windowStoredState!
|
|
179
|
-
)
|
|
195
|
+
this.windows.set(windowId, windowController)
|
|
180
196
|
|
|
181
|
-
|
|
182
|
-
windowController.actions.bringToFront()
|
|
183
|
-
}
|
|
197
|
+
this.setRunning(true)
|
|
184
198
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
windowController,
|
|
188
|
-
)
|
|
199
|
+
return windowController
|
|
200
|
+
}
|
|
189
201
|
|
|
190
|
-
|
|
202
|
+
public closeWindow(windowId: string) {
|
|
203
|
+
delete this.storeWindows.windows[windowId]
|
|
204
|
+
this.windows.delete(windowId)
|
|
191
205
|
|
|
192
|
-
|
|
206
|
+
if (this.windows.size === 0) {
|
|
207
|
+
this.applicationManager.closeApp(this.id)
|
|
193
208
|
}
|
|
209
|
+
}
|
|
194
210
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
211
|
+
public closeAllWindows() {
|
|
212
|
+
this.storeWindows.windows = {}
|
|
213
|
+
this.windows.clear()
|
|
214
|
+
}
|
|
198
215
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
}
|
|
216
|
+
get windowsOpened() {
|
|
217
|
+
return this.windows
|
|
218
|
+
}
|
|
203
219
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}
|
|
220
|
+
public getWindowById(id: string): IWindowController[] {
|
|
221
|
+
return this.windows.get(id)
|
|
222
|
+
}
|
|
208
223
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
224
|
+
public getWindowsByModel(model: string): IWindowController[] {
|
|
225
|
+
return Array.from(this.windows.values()).filter((w) => w.model === model)
|
|
226
|
+
}
|
|
212
227
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
228
|
+
public getFirstWindowByModel(model: string): IWindowController | undefined {
|
|
229
|
+
return Array.from(this.windows.values()).find((w) => w.model === model)
|
|
230
|
+
}
|
|
216
231
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
232
|
+
public setRunning(value: boolean): void {
|
|
233
|
+
this.isRunning = value
|
|
234
|
+
}
|
|
220
235
|
|
|
221
|
-
|
|
222
|
-
this.isRunning = value
|
|
223
|
-
}
|
|
236
|
+
// meta
|
|
224
237
|
|
|
225
|
-
|
|
238
|
+
get meta() {
|
|
239
|
+
return this.storeMeta.meta
|
|
240
|
+
}
|
|
226
241
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
242
|
+
getMeta(key: string) {
|
|
243
|
+
return this.meta[key]
|
|
244
|
+
}
|
|
230
245
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
246
|
+
setMeta(key: string, value: any) {
|
|
247
|
+
this.meta[key] = value
|
|
248
|
+
}
|
|
234
249
|
|
|
235
|
-
|
|
236
|
-
this.meta[key] = value
|
|
237
|
-
}
|
|
250
|
+
// commands
|
|
238
251
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
return this.applicationManager.execAppCommand(this.id, command)
|
|
243
|
-
}
|
|
252
|
+
async execCommand(command: string): Promise<CommandOutput | void> {
|
|
253
|
+
return this.applicationManager.execAppCommand(this.id, command)
|
|
254
|
+
}
|
|
244
255
|
}
|