diff --git a/src/core/XSystem.ts b/src/core/XSystem.ts index 39485ab..6d0f853 100644 --- a/src/core/XSystem.ts +++ b/src/core/XSystem.ts @@ -1,9 +1,5 @@ -import ProcessImpl from './process/impl/ProcessImpl.ts' -import { isUndefined } from 'lodash' import { BasicSystemProcess } from '@/core/system/BasicSystemProcess.ts' import { DesktopProcess } from '@/core/desktop/DesktopProcess.ts' -import type { IProcess } from '@/core/process/IProcess.ts' -import type { IProcessInfo } from '@/core/process/IProcessInfo.ts' import { ObservableWeakRefImpl } from '@/core/state/impl/ObservableWeakRefImpl.ts' import type { IObservable } from '@/core/state/IObservable.ts' import { NotificationService } from '@/core/service/services/NotificationService.ts' @@ -44,35 +40,10 @@ export default class XSystem { public initialization(dom: HTMLDivElement) { this._desktopRootDom = dom - this.run('basic-system', BasicSystemProcess).then(() => { - this.run('desktop', DesktopProcess).then((proc) => { + processManager.runProcess('basic-system', BasicSystemProcess).then(() => { + processManager.runProcess('desktop', DesktopProcess).then((proc) => { proc.mount(dom) - // console.log(dom.querySelector('.desktop-root')) }) }) } - - // 运行进程 - public async run( - proc: string | IProcessInfo, - constructor?: new (info: IProcessInfo) => T, - ): Promise { - let info = typeof proc === 'string' ? processManager.findProcessInfoByName(proc)! : proc - if (isUndefined(info)) { - throw new Error(`未找到进程信息:${proc}`) - } - - // 是单例应用 - if (info.singleton) { - let process = processManager.findProcessByName(info.name) - if (process) { - return process as T - } - } - - // 创建进程 - let process = isUndefined(constructor) ? new ProcessImpl(info) : new constructor(info) - - return process as T - } } diff --git a/src/core/desktop/DesktopProcess.ts b/src/core/desktop/DesktopProcess.ts index 7e46763..6dea86c 100644 --- a/src/core/desktop/DesktopProcess.ts +++ b/src/core/desktop/DesktopProcess.ts @@ -7,6 +7,7 @@ import { debounce } from 'lodash' import type { IProcessInfo } from '@/core/process/IProcessInfo.ts' import { eventManager } from '@/core/events/EventManager.ts' import { processManager } from '@/core/process/ProcessManager.ts' +import './ui/DesktopElement.ts' export class DesktopProcess extends ProcessImpl { private _desktopRootDom: HTMLElement; @@ -91,6 +92,13 @@ export class DesktopProcess extends ProcessImpl { app.use(naiveUi) app.mount(dom) + // this.initDesktop(dom) + this._isMounted = true } + + private initDesktop(dom: HTMLDivElement) { + const d = document.createElement('desktop-element') + dom.appendChild(d) + } } \ No newline at end of file diff --git a/src/core/desktop/ui/DesktopComponent.vue b/src/core/desktop/ui/DesktopComponent.vue index 88e091c..0791d51 100644 --- a/src/core/desktop/ui/DesktopComponent.vue +++ b/src/core/desktop/ui/DesktopComponent.vue @@ -22,13 +22,13 @@ diff --git a/src/core/desktop/ui/DesktopElement.ts b/src/core/desktop/ui/DesktopElement.ts new file mode 100644 index 0000000..b5a7c23 --- /dev/null +++ b/src/core/desktop/ui/DesktopElement.ts @@ -0,0 +1,35 @@ +import { css, html, LitElement, unsafeCSS } from 'lit' +import { customElement } from 'lit/decorators.js' +import desktopStyle from './css/desktop.scss?inline' + +@customElement('desktop-element') +export class DesktopElement extends LitElement { + static override styles = css` + ${unsafeCSS(desktopStyle)} + ` + + private onContextMenu = (e: MouseEvent) => { + e.preventDefault() + e.stopPropagation() + console.log('contextmenu') + } + + override render() { + return html` +
+
+
+ +
+
+
+
测试
+
+
+ ` + } +} \ No newline at end of file diff --git a/src/core/desktop/ui/components/DesktopAppIconElement.ts b/src/core/desktop/ui/components/DesktopAppIconElement.ts new file mode 100644 index 0000000..6c5ecf4 --- /dev/null +++ b/src/core/desktop/ui/components/DesktopAppIconElement.ts @@ -0,0 +1,17 @@ +import { css, html, LitElement } from 'lit' + +export class DesktopAppIconElement extends LitElement { + static override styles = css` + :host { + width: 100%; + height: 100%; + @apply flex flex-col items-center justify-center bg-gray-200; + } + ` + + override render() { + return html`
+ +
` + } +} \ No newline at end of file diff --git a/src/core/desktop/ui/css/desktop.scss b/src/core/desktop/ui/css/desktop.scss new file mode 100644 index 0000000..213ee41 --- /dev/null +++ b/src/core/desktop/ui/css/desktop.scss @@ -0,0 +1,31 @@ +*, +*::before, +*::after { + box-sizing: border-box; /* 使用更直观的盒模型 */ + margin: 0; + padding: 0; +} + +$taskBarHeight: 40px; + +.desktop-root { + @apply w-full h-full flex flex-col; + + .desktop-container { + @apply w-full h-full flex-1 p-2 pos-relative; + background-image: url("../imgs/desktop-bg-2.jpeg"); + background-repeat: no-repeat; + background-size: cover; + height: calc(100% - #{$taskBarHeight}); + } + + .desktop-icons-container { + @apply w-full h-full flex-1 grid grid-auto-flow-col pos-relative; + } + + .task-bar { + @apply w-full bg-gray-200 flex justify-center items-center; + height: $taskBarHeight; + flex-shrink: 0; + } +} \ No newline at end of file diff --git a/src/core/process/impl/ProcessManagerImpl.ts b/src/core/process/impl/ProcessManagerImpl.ts index 0d42f88..2bb8731 100644 --- a/src/core/process/impl/ProcessManagerImpl.ts +++ b/src/core/process/impl/ProcessManagerImpl.ts @@ -1,4 +1,4 @@ -import type ProcessImpl from './ProcessImpl.ts' +import ProcessImpl from './ProcessImpl.ts' import { ProcessInfoImpl } from '@/core/process/impl/ProcessInfoImpl.ts' import { BasicSystemProcessInfo } from '@/core/system/BasicSystemProcessInfo.ts' import { DesktopProcessInfo } from '@/core/desktop/DesktopProcessInfo.ts' @@ -6,6 +6,8 @@ import type { IAppProcessInfoParams } from '@/core/process/types/IAppProcessInfo import type { IProcessManager } from '@/core/process/IProcessManager.ts' import type { IProcess } from '@/core/process/IProcess.ts' import type { IProcessInfo } from '@/core/process/IProcessInfo.ts' +import { processManager } from '@/core/process/ProcessManager.ts' +import { isUndefined } from 'lodash' /** * 进程管理 @@ -35,6 +37,29 @@ export default class ProcessManagerImpl implements IProcessManager { this._processInfos.push(...internalProcessInfos) } + public async runProcess( + proc: string | IProcessInfo, + constructor?: new (info: IProcessInfo) => T, + ): Promise { + let info = typeof proc === 'string' ? this.findProcessInfoByName(proc) : proc + if (isUndefined(info)) { + throw new Error(`未找到进程信息:${proc}`) + } + + // 是单例应用 + if (info.singleton) { + let process = this.findProcessByName(info.name) + if (process) { + return process as T + } + } + + // 创建进程 + let process = isUndefined(constructor) ? new ProcessImpl(info) : new constructor(info) + + return process as T + } + // 添加进程 public registerProcess(process: ProcessImpl) { this._processPool.set(process.id, process); diff --git a/src/core/window/ui/css/wf.scss b/src/core/window/ui/css/wf.scss index 602a32b..86200f9 100644 --- a/src/core/window/ui/css/wf.scss +++ b/src/core/window/ui/css/wf.scss @@ -1,3 +1,11 @@ +*, +*::before, +*::after { + box-sizing: border-box; /* 使用更直观的盒模型 */ + margin: 0; + padding: 0; +} + :host { position: absolute; top: 0;