A lightweight framework base on Electron
简体中文 | English
npm i sugar-electron --save-dev
npm i sugar-electron-cli -g
sugar-electron-cli init
We expect Sugar-Electron to improve the stability of Electron applications and help the development team reduce development and maintenance costs.
Source code: https://github.com/SugarTurboS/Sugar-Electron
Docs: https://sugarturbos.github.io/Sugar-Electron/
If you have any questions, you can scan the QR code to join the WeChat group chat discussion.
We know that the Electron application has three basic modules.
- Main Process
- Render Process
- IPC Messge
Since we belong to a multi-window (multi-rendering process) application, we will write all the service modules to the main process module, which lays a hidden danger for the stability of the entire program.
In Electron, tge main process controls this life cycle of the entire program and also managing the render processes create by it. Once there is a problem with the code of the main process, the following situations will occur.
- An uncaught abnormal crash of the main process directly causes the application to exit.
- The main process is blocked, which directly causes all rendering processes to be blocked, and the UI is blocked and unresponsive.
Therefore, in Sugar-Electron, we introduced the concept of Service process. We hope to migrate the code originally written in the main process to the Service process (essentially the rendering process), so that the crash caused by these codes will not make the entire Program exit.
The process manager of the main process can restart the process and restore the state before the crash when the Service crashes, thereby improving the stability and usability of the entire program.
Electron belongs to the desktop development platform to provide desktop application development capability framework, so it is easy to get started.However, the framework itself lacks conventions. Therefore, when Electron is used for application development, there will be a variety of bizarre divisions in the system modules, and the code will appear in a variety of ways to write, which will significantly increase the cost of learning and reduce the efficiency of developers.Sugar-electron is developed in accordance with the agreement to reduce the cost of team collaboration and improve efficiency.
- Integrated communication module, support request response, publish and subscribe.
- Integrated inter-process state sharing module, support state synchronization change, state change monitoring.
- Integrated process management module, supporting centralized management of process modules.
- Integrated configuration management module, supporting development, testing, and production environment .configuration switching.
- Integrated plug-in module, support highly extensible plug-in mechanism.
- The framework is low intrusive, and the cost of project access and transformation is low
- Progressive development
一、Sugar-electron is designed around the rendering process as its core. The main process only acts as a daemon for process management (creation, deletion, error monitoring) and scheduling (process communication, status function bridge).
The main process does not deal with business logic, the benefits of such a design:
- Can prevent the main process from crashing with an uncaught exception, causing the application to exit.
- Avoid blocking the main process, causing all rendering processes to be blocked, resulting in UI blocking and unresponsiveness.
二、All business modules of sugar-electron are rendering processes. We know that there is no direct access between processes. In order to make calls between processes as convenient as direct calls between modules of the same thread, sugar-electron provides the following three modules:
- Process communication module
- Process state sharing module
- Process management module
三、In order to ensure that the core of the framework is sufficiently streamlined, stable, and efficient, the scalability of the framework is essential. For this reason, sugar-electron provides a custom plug-in mechanism to extend the framework's capabilities, which can also promote the reuse of business logic and even the formation of an ecosystem.
Sugar-electron is based on the micro-kernel architecture design:
Seven core modules in Sugar-electron:
- BaseWindow
- Service
- WindowCenter
- Ipc
- Store
- Config
- Plugins
PRs accepted.
MIT © 2020 Tomey/SugarTurboS