core icon indicating copy to clipboard operation
core copied to clipboard

[FEATURE] ElectronEnv 改造

Open yantze opened this issue 3 years ago • 3 comments

如果你的需求与问题相关,请在下面描述一下(Is your feature request related to a problem? Please describe.)

Electron 桌面端版本充斥着大量的 ElectronEnv,有几个明显的问题:

  1. 不知道什么时候有数据
  2. 不是到哪些数据是已经更新完成了
  3. 来自各个地方都能修改数据,导致这个变量难以维护
  4. 不要暴露全局变量到框架外部

描述你预期的功能表现(Describe the solution you'd like)

把 ElectronEnv 中多个变量拆分成多个服务,最后的一部分可以单独设置为应用整体的 ClientEnvInfoService 这类可以管理的服务,最后是分解 ElectronEnv 全局变量。

描述你考虑过的替代方案(Describe alternatives you've considered)

补充信息(Additional context)

yantze avatar Feb 03 '23 11:02 yantze

4. 不要暴露全局变量到框架外部

温馨提醒:opensumi/devtools目前依赖这个全局变量 :)

tyn1998 avatar Feb 16 '23 16:02 tyn1998

https://github.com/opensumi/core/blob/3226e4d9248f9aadc9b9dae6f34573a15171f92e/packages/core-browser/src/utils/electron.ts#L5

这里的declare也隐式依赖了在browser-preload中用Object.assign(global, electronEnv)暴露的electronEnv.ElectronIpcRenderer

https://github.com/opensumi/core/blob/3226e4d9248f9aadc9b9dae6f34573a15171f92e/packages/core-electron-main/browser-preload/index.js#L79-L107

tyn1998 avatar Mar 21 '23 09:03 tyn1998

改造的目标是框架的 browser 层不感知 electronEnv, 它感知的是一个叫做 IClientEnvInfoService 的东西,

interface IClientEnvInfoService {
  provideMetadata(): Metadata;
  createNetConnection(xxx): xxx;
  ...
}

然后用户需要显式的创建好这个 IClientEnvInfoService 的一个具体实现,才能启动整个 Browser 层的 ClientApp

bytemain avatar Jun 28 '23 09:06 bytemain