2025-08-26 10:33:41 +08:00
|
|
|
import ProcessImpl from '@/core/process/impl/ProcessImpl.ts'
|
2025-08-19 14:56:38 +08:00
|
|
|
import { BasicSystemProcess } from '@/core/system/BasicSystemProcess.ts'
|
|
|
|
|
import { createApp, h } from 'vue'
|
|
|
|
|
import DesktopComponent from '@/core/desktop/ui/DesktopComponent.vue'
|
|
|
|
|
import { naiveUi } from '@/core/common/naive-ui/components.ts'
|
|
|
|
|
import { debounce } from 'lodash'
|
2025-08-26 17:04:31 +08:00
|
|
|
import type { IProcessInfo } from '@/core/process/IProcessInfo.ts'
|
2025-08-29 14:22:20 +08:00
|
|
|
import { processManager } from '@/core/process/ProcessManager.ts'
|
2025-09-19 11:49:04 +08:00
|
|
|
import './ui/DesktopElement.ts'
|
2025-09-22 13:23:12 +08:00
|
|
|
import { ObservableImpl } from '@/core/state/impl/ObservableImpl.ts'
|
|
|
|
|
|
|
|
|
|
interface IDesktopDataState {
|
|
|
|
|
/** 显示器宽度 */
|
|
|
|
|
monitorWidth: number;
|
|
|
|
|
/** 显示器高度 */
|
|
|
|
|
monitorHeight: number;
|
|
|
|
|
}
|
2025-08-19 14:56:38 +08:00
|
|
|
|
2025-08-26 10:33:41 +08:00
|
|
|
export class DesktopProcess extends ProcessImpl {
|
2025-09-22 13:23:12 +08:00
|
|
|
/** 桌面根dom,类似显示器 */
|
|
|
|
|
private readonly _monitorDom: HTMLElement
|
|
|
|
|
private _isMounted: boolean = false
|
|
|
|
|
private _data = new ObservableImpl<IDesktopDataState>({
|
|
|
|
|
monitorWidth: 0,
|
|
|
|
|
monitorHeight: 0,
|
|
|
|
|
})
|
2025-08-19 14:56:38 +08:00
|
|
|
|
2025-09-22 13:23:12 +08:00
|
|
|
public get monitorDom() {
|
|
|
|
|
return this._monitorDom
|
2025-08-19 14:56:38 +08:00
|
|
|
}
|
|
|
|
|
public get isMounted() {
|
2025-09-22 13:23:12 +08:00
|
|
|
return this._isMounted
|
2025-08-19 14:56:38 +08:00
|
|
|
}
|
|
|
|
|
public get basicSystemProcess() {
|
2025-08-29 14:22:20 +08:00
|
|
|
return processManager.findProcessByName<BasicSystemProcess>('basic-system')
|
2025-08-19 14:56:38 +08:00
|
|
|
}
|
|
|
|
|
|
2025-09-22 13:23:12 +08:00
|
|
|
get data() {
|
|
|
|
|
return this._data
|
2025-08-19 14:56:38 +08:00
|
|
|
}
|
|
|
|
|
|
2025-09-22 13:23:12 +08:00
|
|
|
constructor(info: IProcessInfo, dom: HTMLDivElement) {
|
2025-08-19 14:56:38 +08:00
|
|
|
super(info)
|
|
|
|
|
console.log('DesktopProcess')
|
2025-08-28 08:05:16 +08:00
|
|
|
dom.style.position = 'relative'
|
2025-09-01 16:31:47 +08:00
|
|
|
dom.style.overflow = 'hidden'
|
2025-09-22 13:23:12 +08:00
|
|
|
dom.style.width = `${window.innerWidth}px`
|
|
|
|
|
dom.style.height = `${window.innerHeight}px`
|
2025-08-19 14:56:38 +08:00
|
|
|
|
2025-09-22 13:23:12 +08:00
|
|
|
this._monitorDom = dom
|
|
|
|
|
this._data.state.monitorWidth = window.innerWidth
|
|
|
|
|
this._data.state.monitorHeight = window.innerHeight
|
|
|
|
|
window.addEventListener('resize', this.onResize)
|
|
|
|
|
|
|
|
|
|
this.createDesktopUI()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private onResize = debounce(() => {
|
|
|
|
|
this._monitorDom.style.width = `${window.innerWidth}px`
|
|
|
|
|
this._monitorDom.style.height = `${window.innerHeight}px`
|
|
|
|
|
this._data.state.monitorWidth = window.innerWidth
|
|
|
|
|
this._data.state.monitorHeight = window.innerHeight
|
|
|
|
|
}, 300)
|
|
|
|
|
|
|
|
|
|
private createDesktopUI() {
|
|
|
|
|
if (this._isMounted) return
|
2025-08-19 14:56:38 +08:00
|
|
|
const app = createApp(DesktopComponent, { process: this })
|
|
|
|
|
app.use(naiveUi)
|
2025-09-22 13:23:12 +08:00
|
|
|
app.mount(this._monitorDom)
|
2025-08-19 16:59:58 +08:00
|
|
|
this._isMounted = true
|
2025-08-19 14:56:38 +08:00
|
|
|
}
|
2025-09-19 11:49:04 +08:00
|
|
|
|
|
|
|
|
private initDesktop(dom: HTMLDivElement) {
|
|
|
|
|
const d = document.createElement('desktop-element')
|
|
|
|
|
dom.appendChild(d)
|
|
|
|
|
}
|
2025-09-22 13:23:12 +08:00
|
|
|
|
|
|
|
|
override destroy() {
|
|
|
|
|
super.destroy()
|
|
|
|
|
window.removeEventListener('resize', this.onResize)
|
|
|
|
|
}
|
2025-08-19 14:56:38 +08:00
|
|
|
}
|