### Install Electron-Egg Project Dependencies Source: https://www.kaka996.com/pages/987b1c/pages/b16aa7 Commands to install Node.js (npm) dependencies for the root and frontend directories, and Go dependencies including the `air` hot-reloader. ```bash # 根目录安装electron依赖 npm i # 进入前端目录安装依赖 cd ./frontend npm i # 先全局安装热重载 air go install github.com/air-verse/air@v1.49.0 # 进入go目录安装依赖 cd ../go go mod tidy ``` -------------------------------- ### Switch to Python Demo Branch Source: https://www.kaka996.com/pages/987b1c/pages/479cf2 Command to switch to the `demo-python` branch, which contains the specific setup and examples for Python integration within the Electron-Egg project. This ensures you are working with the correct demo configuration. ```bash git checkout -b demo-python remotes/origin/demo ``` -------------------------------- ### Switch to Java Demo Branch Source: https://www.kaka996.com/pages/987b1c/pages/368cc3 Use this command to switch to the `demo-java` branch, which contains the specific setup and code for the Java integration demonstration. ```Shell git checkout -b demo-java remotes/origin/demo ``` -------------------------------- ### Start Go Service with Electron Application Startup Source: https://www.kaka996.com/pages/987b1c/pages/b16aa7 Illustrates how to integrate the Go service startup into the Electron application's preload module. This ensures the Go service runs automatically when the desktop software starts, by directly calling the `createGoServer` method. ```javascript // 文件 electron/preload/index.js /************************************************* ** preload为预加载模块,该文件将会在程序启动时加载 ** *************************************************/ const { crossService } = require('../service/cross'); function preload() { // 直接调用 crossService.createGoServer(); } /** * 预加载模块入口 */ module.exports = { preload } ``` -------------------------------- ### Download Electron-Egg Project with Git Source: https://www.kaka996.com/pages/987b1c/pages/b16aa7 Commands to clone the electron-egg repository from Gitee or GitHub. ```bash # gitee git clone https://gitee.com/dromara/electron-egg.git # github git clone https://github.com/dromara/electron-egg.git ``` -------------------------------- ### Set Up and Start Frontend Development Server Source: https://www.kaka996.com/pages/987b1c/pages/ae3b54 These commands guide you through the initial setup for the frontend development environment. It involves navigating to the frontend directory, installing necessary dependencies, and starting the development server. ```Shell # 进入【前端目录】 cd frontend # 安装依赖 npm install # 启动服务 npm run dev ``` -------------------------------- ### Install Project Dependencies Source: https://www.kaka996.com/pages/987b1c/pages/479cf2 Commands to install all necessary dependencies for the Electron-Egg project. This includes Node.js packages for the Electron main process and frontend, as well as Python packages specified in `requirements.txt`. ```bash # 根目录安装electron依赖 npm i # 进入前端目录安装依赖 cd ./frontend npm i # 安装python依赖 cd ./python pip install -r requirements.txt ``` -------------------------------- ### Set Up Frontend Development Environment Source: https://www.kaka996.com/pages/987b1c/pages/c9eed1 These commands guide developers through setting up the frontend part of an `electron-egg` project for development. It involves navigating to the frontend directory, installing dependencies, and starting the development server. ```Shell # 进入【前端目录】 cd frontend # 安装依赖 npm install # 启动服务 npm run dev ``` -------------------------------- ### Run Electron-Egg Java Demo Source: https://www.kaka996.com/pages/987b1c/pages/368cc3 Execute this command from the project root to start the Electron-Egg application, allowing you to view the integrated Java service demo. ```Shell npm run start ``` -------------------------------- ### Install Electron and Frontend Dependencies Source: https://www.kaka996.com/pages/987b1c/pages/368cc3 These commands install the necessary Node.js dependencies for the Electron application in the root directory and then for the frontend project within the `frontend` subdirectory. ```Shell # 根目录安装electron依赖 npm i # 进入前端目录安装依赖 cd ./frontend npm i ``` -------------------------------- ### Run Go Executable in Electron (API Mode) Source: https://www.kaka996.com/pages/987b1c/pages/b16aa7 Demonstrates how to start a Go executable from Electron using the `cross` module's API. It shows both default and custom configurations for running the Go server, including specifying the program name, path, arguments, and application exit behavior. ```javascript // 文件 electron/service/cross.js const { cross } = require('ee-core/cross'); async createGoServer() { // method 1: Use the default Settings //const entity = await cross.run(serviceName); // method 2: Use custom configuration const serviceName = "go"; const opt = { // 程序名称,一般填写可执行程序名 name: 'goapp', cmd: path.join(getExtraResourcesDir(), 'goapp'), directory: getExtraResourcesDir(), args: ['--port=7073'], // 程序退出时,是否退出electron应用 appExit: true, } const entity = await cross.run(serviceName, opt); logger.info('server name:', entity.name); return; } ``` -------------------------------- ### Download Electron-Egg via Git Source: https://www.kaka996.com/pages/987b1c/pages/d86dd9 Instructions to download the Electron-Egg framework source code from either Gitee or GitHub using Git clone commands. ```bash # gitee git clone https://gitee.com/dromara/electron-egg.git # github git clone https://github.com/dromara/electron-egg.git ``` -------------------------------- ### Install Electron-Egg Dependencies with npm Source: https://www.kaka996.com/pages/987b1c/pages/d86dd9 Steps to install project dependencies using npm. Includes a note on troubleshooting Electron installation issues by running npm install within the node_modules/electron directory. ```npm # 进入目录 ./electron-egg/ npm install # 如果还是提示 electron 没安装,进入 node_modules/electron 目录下,再npm install ``` -------------------------------- ### Prepare Development Environment for DLL Usage Source: https://www.kaka996.com/pages/987b1c/pages/e13483 This section details the setup process for calling DLLs, including installing `node-gyp` for compilation, `windows-build-tools` for C++ builds, and essential Node.js libraries like `ref-napi`, `ref-array-napi`, `ref-struct-napi`, and `ffi-napi`. It also provides commands to configure and build the `ref-napi` library. ```Shell # 编译工具 npm i -g node-gyp # C++构建工具 1. 管理员模式打开PowerShell 2. npm --vs2015 i -g --production windows-build-tools 或者 npm i -g --production windows-build-tools # 外部接口调用库 1. npm install ref-napi // 基本类型 2. npm install ref-array-napi // 数组类型 3. npm install ref-struct-napi // 结构体类型 4. npm install ffi-napi // 连接c代码和js代码 # 编译 ref-napi 库 1. cd ./node_modules/ref-napi 2. node-gyp configure // 配置 3. node-gyp build // 编译 ``` -------------------------------- ### Run Electron-Egg Application Source: https://www.kaka996.com/pages/987b1c/pages/479cf2 Command to start the Electron-Egg application. After running this command, you can navigate to the 'cross' menu and 'Python service' within the demo to see the integrated Python functionality. ```bash npm run start ``` -------------------------------- ### Build Python Executable Source: https://www.kaka996.com/pages/987b1c/pages/479cf2 Instructions to install `cx_Freeze`, a tool for creating standalone executables from Python scripts, and then run the npm script to build the Python program. A note is included regarding `conda` specific installation of `cx_Freeze`. ```bash # 安装 cx_Freeze,它可以生成可执行程序 pip install cx_Freeze # 构建python程序 npm run build-python ``` -------------------------------- ### Frontend Setup for HTML Mode Source: https://www.kaka996.com/pages/987b1c/pages/a75f3c Instructions for preparing an HTML-based frontend for an Electron application. This involves navigating into the frontend directory, creating a 'dist' folder, and then starting the Electron service from the root. ```bash cd ./frontend && mkdir dist # 2: 编写html文件 index.html # 3:【根目录】,启动electron服务 npm run dev ``` -------------------------------- ### Clone Electron-Egg Project Repository Source: https://www.kaka996.com/pages/987b1c/pages/368cc3 This snippet provides commands to clone the electron-egg project repository from either Gitee or GitHub, which is the first step to setting up the development environment. ```Shell # gitee git clone https://gitee.com/dromara/electron-egg.git ``` ```Shell # github git clone https://github.com/dromara/electron-egg.git ``` -------------------------------- ### Clone Electron-Egg Project Repository Source: https://www.kaka996.com/pages/987b1c/pages/479cf2 Commands to clone the Electron-Egg project repository from either Gitee or GitHub. Choose one of the provided options to get the project source code. ```bash # gitee git clone https://gitee.com/dromara/electron-egg.git # github git clone https://github.com/dromara/electron-egg.git ``` -------------------------------- ### Framework LTS Versions: Node.js v12, Electron v12 Source: https://www.kaka996.com/pages/987b1c/pages/d86dd9 Recommended long-term supported versions for Node.js, Electron, and better-sqlite3 for developers unfamiliar with their dependencies. ```text node.js: v12.22.0 electron: v12.2.3 better-sqlite3: v7.6.0 ``` -------------------------------- ### EE-Bin Production Start Command Configuration Source: https://www.kaka996.com/pages/987b1c/pages/fe18e5 Configures the command to launch the Electron application in production mode. It specifies the execution directory, the `electron` command, and arguments to set the environment to `prod`. ```JavaScript { directory: './', cmd: 'electron', args: ['.', '--env=prod'] } ``` -------------------------------- ### Run Electron-Egg in Pre-Release Mode Source: https://www.kaka996.com/pages/987b1c/pages/95a09b This command starts the Electron-Egg application in a production-like environment, allowing for testing before final packaging. It's the 'zero step' to ensure functionality is normal in a pre-release state. ```Shell npm run start ``` -------------------------------- ### Start Python Service on Electron Application Startup (Preload) Source: https://www.kaka996.com/pages/987b1c/pages/abb660 Shows how to automatically start the Python executable when the Electron application launches by calling the `createPythonServer` method directly from the `preload` module, ensuring the Python backend is ready upon app startup. ```javascript // 文件 electron/preload/index.js /************************************************* ** preload为预加载模块,该文件将会在程序启动时加载 ** *************************************************/ const { crossService } = require('../service/cross'); function preload() { // 直接调用 crossService.createPythonServer(); } /** * 预加载模块入口 */ module.exports = { preload } ``` -------------------------------- ### Clone Electron-Egg Repository Source: https://www.kaka996.com/pages/987b1c/pages/e64ff6 Instructions to download the Electron-Egg source code from either Gitee or GitHub using standard Git clone commands. This is the first step to get the project files locally. ```Shell # gitee git clone https://gitee.com/dromara/electron-egg.git # github git clone https://github.com/dromara/electron-egg.git ``` -------------------------------- ### Framework LTS Versions: Node.js v14, Electron v13 Source: https://www.kaka996.com/pages/987b1c/pages/d86dd9 Recommended long-term supported versions for Node.js, Electron, and better-sqlite3 for developers unfamiliar with their dependencies. ```text node.js: v14.21.1 electron: v13.6.9 better-sqlite3: v7.6.0 ``` -------------------------------- ### Install Development Tools for DLL Integration Source: https://www.kaka996.com/pages/987b1c/pages/c67dff This section details the command-line steps to prepare your development environment for integrating DLLs. It includes global installations for `node-gyp` (compilation tool) and `windows-build-tools` (C++ build tools), followed by local installations of `ref-napi`, `ref-array-napi`, `ref-struct-napi`, and `ffi-napi` for external interface calls. Finally, it outlines the process to configure and build the `ref-napi` library. ```Shell # 编译工具 npm i -g node-gyp # C++构建工具 1. 管理员模式打开PowerShell 2. npm --vs2015 i -g --production windows-build-tools 或者 npm i -g --production windows-build-tools # 外部接口调用库 1. npm install ref-napi // 基本类型 2. npm install ref-array-napi // 数组类型 3. npm install ref-struct-napi // 结构体类型 4. npm install ffi-napi // 连接c代码和js代码 # 编译 ref-napi 库 1. cd ./node_modules/ref-napi 2. node-gyp configure // 配置 3. node-gyp build // 编译 ``` -------------------------------- ### Framework LTS Versions: Node.js v20, Electron v31 Source: https://www.kaka996.com/pages/987b1c/pages/d86dd9 Recommended long-term supported versions for Node.js, Electron, and better-sqlite3 for developers unfamiliar with their dependencies. ```text node.js: v20.16.0 electron: v^31.7.6 better-sqlite3: v11.7.0 ``` -------------------------------- ### API: app.run Source: https://www.kaka996.com/pages/987b1c/pages/cdf5f8 Starts the ElectronEgg application, initiating all necessary processes. ```APIDOC app.run(): void Parameters: None. Returns: void. ``` -------------------------------- ### ee-bin start Command Usage Source: https://www.kaka996.com/pages/987b1c/pages/e1816f Illustrates the use of the 'ee-bin start' command for pre-release testing, setting the environment variable to 'prod' to verify program functionality before building the executable. ```Bash ee-bin start ``` -------------------------------- ### Install Electron-Egg Dependencies with pnpm (Hoisted) Source: https://www.kaka996.com/pages/987b1c/pages/d86dd9 Instructions to resolve 'phantom dependencies' by adding 'node-linker=hoisted' to the .npmrc file and then installing dependencies using pnpm. ```pnpm # 解决幽灵依赖,在 .npmrc 文件中添加如下内容: node-linker=hoisted # 进入目录 ./electron-egg/ pnpm install ``` -------------------------------- ### Configure npm Mirror for Faster Downloads Source: https://www.kaka996.com/pages/987b1c/pages/d86dd9 Configuration for the .npmrc file to set up domestic mirror sources for npm, node, electron, and electron-builder binaries to accelerate downloads. ```npmrc registry=https://registry.npmmirror.com/ disturl=https://registry.npmmirror.com/-/binary/node electron_mirror=https://npmmirror.com/mirrors/electron/ electron-builder-binaries_mirror=https://registry.npmmirror.com/-/binary/electron-builder-binaries/ ``` -------------------------------- ### Framework LTS Versions: Node.js v16, Electron v21 Source: https://www.kaka996.com/pages/987b1c/pages/d86dd9 Recommended long-term supported versions for Node.js, Electron, and better-sqlite3 for developers unfamiliar with their dependencies. ```text node.js: v16.20.0 electron: v21.4.4 better-sqlite3: v8.6.0 ``` -------------------------------- ### ee-bin dev Command API Reference Source: https://www.kaka996.com/pages/987b1c/pages/e1816f API documentation for the 'ee-bin dev' command, detailing its 'serve' parameter which controls the startup mode (frontend, electron, go) or starts all services if empty. ```APIDOC dev * serve - 'frontend' | 'electron' | go Startup mode: `frontend` for frontend; `electron` for main process; `go` for Go service. If empty, all start. See bin configuration for more details. ``` -------------------------------- ### ee-bin dev Command Usage Source: https://www.kaka996.com/pages/987b1c/pages/e1816f Demonstrates various ways to use the 'ee-bin dev' command to start the application in different modes (frontend, electron, go, or all), based on the 'serve' parameter. ```Bash ee-bin dev ee-bin dev --serve=frontend ee-bin dev --serve=electron ee-bin dev --serve=go ``` -------------------------------- ### Install mkcert Root Certificate Authority Source: https://www.kaka996.com/pages/987b1c/pages/afbd71 Installs the mkcert root certificate authority on your system. This command needs to be executed in a command prompt or terminal where mkcert is accessible. ```Shell mkcert -install ``` -------------------------------- ### Configure Electron-Egg Plugins Source: https://www.kaka996.com/pages/987b1c/pages/c08bd9 This configuration snippet, located in `./electron/config/config.default.js`, shows how to enable plugins. Plugins are defined as keys within the `config.addons` object, with an `enable: true` property to activate them. This example enables both the built-in `window` plugin and the custom `example` plugin. ```javascript /** * 插件功能 * window 官方内置插件 * example demo插件 */ config.addons = { window: { enable: true, }, // 插件名为key,enable 配置启用 example: { enable: true, } }; ``` -------------------------------- ### Install Electron-Egg Icon Generation Dependencies Source: https://www.kaka996.com/pages/987b1c/pages/801f4c Instructions for installing the `ee-bin` and `icon-gen` npm packages, which are prerequisites for using the automated icon generation command in Electron-Egg projects. Includes a note about potential installation failures. ```Shell # 安装 ee-bin npm install ee-bin # 安装依赖 npm install icon-gen -D ``` -------------------------------- ### Electron-Egg: Install Icon Generation Dependencies Source: https://www.kaka996.com/pages/987b1c/pages/1fc032 This snippet provides commands to install `ee-bin` and `icon-gen` dependencies required for the framework's built-in icon generation tool. `ee-bin` is the command-line interface, and `icon-gen` is the underlying library. ```shell # 安装 ee-bin npm install ee-bin # 安装依赖 npm install icon-gen -D ``` -------------------------------- ### Clone Electron-Egg Project Repository Source: https://www.kaka996.com/pages/987b1c/pages/c76e73 Instructions to download the Electron-Egg project source code from either Gitee or GitHub, providing two common repository options to get started with the project. ```Bash # gitee git clone https://gitee.com/dromara/electron-egg.git # github git clone https://github.com/dromara/electron-egg.git ``` -------------------------------- ### Recommended Software Versions for Windows 7 Compatibility Source: https://www.kaka996.com/pages/987b1c/pages/d86dd9 Lists specific versions of Electron, Node.js, electron-builder, and better-sqlite3 required for Electron-Egg applications to run on Windows 7, as Microsoft has ceased support for Win7. ```text electron <= v21.4.4 node.js <= v16.20.2 electron-builder <= v23.6.0 (可选)@types/node <= v16.18.12 类型提示 (可选)better-sqlite3 <= v8.6.0 ``` -------------------------------- ### Run Electron-Egg Application Source: https://www.kaka996.com/pages/987b1c/pages/c9eed1 This command starts the `electron-egg` application after configuring the remote URL. It allows users to view the effect of the remote mode setup. ```Shell npm run start ``` -------------------------------- ### Execute Go Backend Development Scripts Source: https://www.kaka996.com/pages/987b1c/pages/b467cc This snippet provides the command-line instructions to run the previously defined 'npm' scripts for starting the Go backend in development mode with hot reloading. ```bash npm run dev-go or npm run dev-go-w ``` -------------------------------- ### Electron-Egg Desktop and Installation Icon File Paths Source: https://www.kaka996.com/pages/987b1c/pages/801f4c Lists the required file paths and naming conventions for desktop and installation icons across different sizes and operating systems (Windows, macOS) within an Electron-Egg project's build directory. Emphasizes that names and dimensions must match. ```Shell # 名称和尺寸必须一致 ./build/icons/16x16.png ./build/icons/32x32.png ./build/icons/64x64.png ./build/icons/128x128.png ./build/icons/256x256.png ./build/icons/512x512.png ./build/icons/icon.icns (macOS) ./build/icons/icon.ico ./build/icons/icon.png ``` -------------------------------- ### Example `sqliteOptions` Object Initialization Source: https://www.kaka996.com/pages/987b1c/pages/49e723 An example JavaScript object demonstrating the basic structure for `sqliteOptions`, including `timeout` and `verbose` properties for configuring a `better-sqlite3` database connection. ```JavaScript const sqliteOptions = { timeout: 6000, verbose: console.log // 打印sql语法 } ``` -------------------------------- ### Initialize electron-egg Tray Plugin in Preload Module Source: https://www.kaka996.com/pages/987b1c/pages/c2dd07 This example shows how to initialize the tray functionality by calling `Addon.get('tray').create()` within the preload module. This approach ensures the tray is created when the application starts, as it's a core startup feature. ```JavaScript /** * 预加载模块入口 */ const Addon = require('ee-core/addon'); module.exports = async () => { Addon.get('tray').create(); } ``` -------------------------------- ### Start Electron-Egg Frontend and Electron Development Servers Source: https://www.kaka996.com/pages/987b1c/pages/a2b76f These commands demonstrate how to concurrently launch the frontend and Electron main process development servers. It requires opening two separate terminal windows to run each command, facilitating parallel development and debugging. ```bash # 打开两个终端 npm run dev-frontend npm run dev-electron ``` -------------------------------- ### Starting Electron-egg with Vue/React Frontend Source: https://www.kaka996.com/pages/987b1c/pages/3d5da0 These instructions detail how to launch the Electron-egg application when using a Vue or React frontend. The process involves first navigating into the frontend directory to start the respective development server (e.g., "npm run serve"), and then executing "npm run dev" from the project's root directory to start the Electron service. ```bash # 1:【进入前端目录】,启动vue cd ./frontend npm run serve # 2:【根目录】,启动electron服务 npm run dev ``` -------------------------------- ### Configure and Connect to SQLite Database Source: https://www.kaka996.com/pages/987b1c/pages/9c1613 This example shows how to configure `sqliteOptions` with a `sqlite` driver and default parameters (like timeout and verbose logging) and then establish a connection to a database named 'sqlite-demo.db' using `Storage.connection`. ```JavaScript // sqlite数据库 let sqliteOptions = { driver: 'sqlite', default: { timeout: 6000, verbose: console.log // 打印sql语法 } } const sdb = Storage.connection('sqlite-demo.db', sqliteOptions); ``` -------------------------------- ### Switch to Python Demo Branch Source: https://www.kaka996.com/pages/987b1c/pages/c76e73 Command to switch to the 'demo' branch, specifically the 'demo-python' branch, which contains the pre-configured Python integration example for Electron-Egg. ```Bash git checkout -b demo-python remotes/origin/demo ``` -------------------------------- ### Create Python Service in Electron-Egg using API Mode Source: https://www.kaka996.com/pages/987b1c/pages/abb660 Illustrates how to programmatically create and manage a Python service within the Electron main process using the `cross` module's API. It shows both default and custom configuration options for starting the Python executable, including specifying its path and arguments. ```javascript // 文件 electron/service/cross.js /** * create python service * In the default configuration, services can be started with applications. * Developers can turn off the configuration and create it manually. */ async createPythonServer() { // method 1: Use the default Settings //const entity = await cross.run(serviceName); // method 2: Use custom configuration const serviceName = "python"; const opt = { name: 'pyapp', cmd: path.join(getExtraResourcesDir(), 'py', 'pyapp'), directory: path.join(getExtraResourcesDir(), 'py'), args: ['--port=7074'], windowsExtname: true, appExit: true, } const entity = await cross.run(serviceName, opt); logger.info('server name:', entity.name); logger.info('server config:', entity.config); logger.info('server url:', entity.getUrl()); return; } ``` -------------------------------- ### Configure New Build Command in bin.js Source: https://www.kaka996.com/pages/987b1c/pages/2757b2 Example configuration snippet for `./cmd/bin.js` to define a new build command for Windows 32-bit, specifying arguments for the builder. ```JavaScript # 1. 修改 ./cmd/bin.js 文件 build: { win32: { args: ['--config=./cmd/builder.json', '-w=nsis', '--ia32'], }, } ``` -------------------------------- ### Start Application in Pre-release Mode Source: https://www.kaka996.com/pages/987b1c/pages/2757b2 Command to run the application in pre-release mode, allowing for testing functionality with the production environment variables. ```Shell npm run start ``` -------------------------------- ### Comprehensive example of ee-core API usage Source: https://www.kaka996.com/pages/987b1c/pages/089f32 A detailed example (`test.js`) showcasing the use of various `ee-core` modules such as `Log` for logging, `Ps` for process/system information, `HttpClient` for making HTTP requests, `Storage` for data persistence, and `Utils` for utility functions. This snippet demonstrates common operations like logging messages, retrieving system directories, performing API calls, and managing local storage with a simple database. ```javascript const Log = require('ee-core/log'); const Ps = require('ee-core/ps'); const HttpClient = require('ee-core/httpclient'); const Storage = require('ee-core/storage'); const Utils = require('ee-core/utils'); const Test = { async hello() { Log.info('[log] hello ee-core'); const hc = new HttpClient(); const url = "https://api.wrdan.com/ip"; const options = { method: 'GET', data: { url: 'https://www.baidu.com', }, dataType: 'json', timeout: 15000, }; const result = await hc.request(url, options); console.log('hc.request:', result); console.log('Ps.isMain:', Ps.isMain()); console.log('Ps.getHomeDir:', Ps.getHomeDir()); console.log('Ps.getExecDir:', Ps.getExecDir()); console.log('Utils.machineIdSync:', Utils.machineIdSync()); this.test(); }, test() { const demoDB = Storage.connection('demo'); const key = 'test_data'; if (!demoDB.db.has(key).value()) { demoDB.db.set(key, []).write(); } const data = demoDB.db .get(key) .push({name: 'gsx', age:21}) .write(); return data; } } module.exports=Test; ``` -------------------------------- ### Initialize and Use Electron-Egg Addons Source: https://www.kaka996.com/pages/987b1c/pages/12884f This snippet demonstrates how to initialize and use both built-in and custom addons within the Electron-Egg framework. It shows examples for creating a new window using the 'window' addon and initializing a 'tray' addon. ```JavaScript const Addon = require('ee-core/addon'); // Built-in window plugin const win = Addon.get('window').create('window-name', {title: 'demo'}); // Demo tray plugin Addon.get('tray').create(); ``` -------------------------------- ### Start Electron-Egg Application in Pre-release Mode Source: https://www.kaka996.com/pages/987b1c/pages/5c466b Command to launch the Electron-Egg application in a pre-release (production but unpacked) environment. This mode is used for testing the application's functionality before final packaging. ```Shell npm run start ``` -------------------------------- ### GetPort Usage Examples in JavaScript Source: https://www.kaka996.com/pages/987b1c/pages/001df6 Examples illustrating how to use the `GetPort` function. The first example shows how to randomly acquire an available port. The second example demonstrates attempting to acquire a specific port, falling back to a random port if the specified one is already in use. ```JavaScript // Randomly acquire a port const port = await GetPort(); // Acquire a specified port; if occupied, acquire a random one. const port = await GetPort({port: 3001}); ``` -------------------------------- ### JavaScript Example for Calling DLL Functions with ffi-napi Source: https://www.kaka996.com/pages/987b1c/pages/c67dff This JavaScript code demonstrates how to use `ffi-napi` to load a DLL and call its exported functions. It illustrates mapping C function signatures (return types and parameter lists) to JavaScript, handling basic integer arithmetic, passing pointers for in-place modification, and working with C-style arrays. The example showcases `ref-napi` for type mapping and `ref-array-napi` for array handling, including memory allocation for pointers and arrays. ```JavaScript const ffi = require('ffi-napi'); var ref = require('ref-napi'); var ArrayType = require('ref-array-napi'); /** * exec dll file */ async execDll () { // 资源路径 const dllFile = 'myDllDemo.dll'; const dllPath = path.join(Ps.getExtraResourcesDir(), "dll", dllFile); // 映射到C语言 int数组类型 var IntArray = ArrayType(ref.types.int); // 加载 DLL文件,无需写扩展名,将DLL中的函数映射成JS方法 const MyDellDemo = new ffi.Library(dllPath, { // 方法名必须与C函数名一致 add: [ 'int', // 对应 C函数返回类型 ['int', 'int'] // C函数参数列表 ], // 使用 ffi中内置类型的简写类型 addPtr: ['void', ['int', 'int', 'int*']], // IntArray 是上面通过 ArrayType 构建出来的类型 initArray: ['void', [IntArray, 'int']] }); // 调用add 方法 const res = MyDellDemo.add(1, 2); console.log(`add method result of 1 + 2 is: ` + res); // 调用addPtr 方法 // 使用Buffer类在C代码和JS代码之间实现了内存共享,让Buffer成为了C语言当中的指针。 // C函数使用指针操作函数外部的内存,所以首先需要 分配一个int类型的内存空间 第一个参数为 C语言数据类型,第二个参数为 默认值 var intBuf = ref.alloc(ref.types.int, 100); console.log('addPtr 调用前数据>>', ref.deref(intBuf)); //获取指向的内容 MyDellDemo.addPtr(2, 2, intBuf); // 调用函数,传递指针 console.log('addPtr 调用后数据>>', ref.deref(intBuf)); // 调用initArray 方法 // IntArray 是前面使用ref-napi 和 ref-array-napi 库创建的数据类型,数组的长度为 8 // 这里一定要分配内存空间,否则 函数内的指针无法操作内存 let myArray = new IntArray(8); MyDellDemo.initArray(myArray, 8); console.log('初始化数组执行结果:'); for (var i = 0; i < myArray.length; i++) { console.log(myArray[i]); } return true; } ``` -------------------------------- ### Switch to Demo Branch in Git Source: https://www.kaka996.com/pages/987b1c/pages/132909 This command checks out and switches to the `demo` branch from the `origin/demo` remote, which contains functional examples for the electron-egg framework. ```shell git checkout -b demo remotes/origin/demo ``` -------------------------------- ### Electron-Egg: Generate Icons with ee-bin Command Source: https://www.kaka996.com/pages/987b1c/pages/1fc032 This snippet shows how to use the `ee-bin icon` command to automatically generate various icon sizes from a source image and copy them to the specified output directory. It also provides a commented example of using input and output path parameters. ```shell # 命令 ee-bin icon // ee-bin icon -i /public/images/logo.png -o /build/icons/ ``` -------------------------------- ### Generate SSL Certificate for Local Domains and IPs Source: https://www.kaka996.com/pages/987b1c/pages/afbd71 Generates an SSL certificate and private key for specified hostnames and IP addresses. Replace `localhost`, `127.0.0.1`, `::1`, `example.com`, and `*.example.com` with your desired domains and IPs. ```Shell mkcert localhost 127.0.0.1 ::1 example.com *.example.com ``` -------------------------------- ### Programmatically Create Python Service in Electron with Cross Module Source: https://www.kaka996.com/pages/987b1c/pages/a2b76f This JavaScript code snippet, intended for `electron/service/cross.js`, illustrates how to programmatically start a Python service from the Electron main process using the `Cross.run` API. It provides two methods: using default settings or a custom configuration that specifies the Python executable path, working directory, arguments, and application exit behavior, offering fine-grained control over the Python service lifecycle. ```javascript // 文件 electron/service/cross.js /** * create python service * In the default configuration, services can be started with applications. * Developers can turn off the configuration and create it manually. */ async createPythonServer() { // method 1: Use the default Settings //const entity = await Cross.run(serviceName); // method 2: Use custom configuration const serviceName = "python"; const opt = { name: 'pyapp', cmd: path.join(Ps.getExtraResourcesDir(), 'py', 'pyapp'), directory: path.join(Ps.getExtraResourcesDir(), 'py'), args: ['--port=7074'], windowsExtname: true, appExit: true }; const entity = await Cross.run(serviceName, opt); Log.info('server name:', entity.name); Log.info('server config:', entity.config); Log.info('server url:', entity.getUrl()); return; } ``` -------------------------------- ### Initialize ElectronEgg Application Source: https://www.kaka996.com/pages/987b1c/pages/cdf5f8 Demonstrates how to import and initialize the ElectronEgg application instance. ```javascript const { ElectronEgg } = require('ee-core'); const app = new ElectronEgg(); ``` -------------------------------- ### Install Electron-Egg Dependencies with npm Source: https://www.kaka996.com/pages/987b1c/pages/e64ff6 Commands to install project dependencies using npm. It explicitly recommends npm over yarn or cnpm and provides a troubleshooting step for common Electron installation issues, guiding users to re-run npm install within the Electron module directory if needed. ```Shell # 进入目录 ./electron-egg/ npm install # 如果还是提示 electron 没安装,进入 node_modules/electron 目录下,再npm install ``` -------------------------------- ### Install ee-core library using npm or pnpm Source: https://www.kaka996.com/pages/987b1c/pages/089f32 Instructions to install the `ee-core` library, which provides core `electron-egg` APIs, using either npm or pnpm package managers. This library allows you to access `electron-egg`'s functionalities without using the full framework. ```bash npm install ee-core ``` ```bash pnpm install ee-core ``` -------------------------------- ### ee-bin build Command Usage Source: https://www.kaka996.com/pages/987b1c/pages/e1816f Shows examples of using the 'ee-bin build' command to build frontend, Go, or custom commands, utilizing the 'cmds' parameter as defined in the 'bin' configuration. ```Bash ee-bin build --cmds=frontend ee-bin build --cmds=go_build_w ee-bin build --cmds=go_build_m ee-bin build --cmds=go_build_l ``` -------------------------------- ### Start Electron-Egg Application in Development Source: https://www.kaka996.com/pages/987b1c/pages/c9eed1 This command starts the `electron-egg` application in development mode after the frontend and configuration steps are completed. It allows for live development and testing. ```Shell npm run dev ``` -------------------------------- ### Example PowerShell Executable Path Source: https://www.kaka996.com/pages/987b1c/pages/0b76fb Provides an example path to the PowerShell executable on Windows, illustrating a typical third-party program location that might be placed in "extraResources". ```Shell C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe ``` -------------------------------- ### Install SQLite Build Tools for Electron-Egg Source: https://www.kaka996.com/pages/987b1c/pages/879ef7 Instructions for setting up the necessary build tools for SQLite in electron-egg projects. This involves installing `electron-rebuild` and running a script to rebuild SQLite for the specific operating system. Note for older versions (`ee < 2.1.6`), a specific script entry is required in `package.json`. ```bash # 安装构建工具(新版本自带,旧版本ee < 2.1.6需安装) npm i electron-rebuild -D # (必须)重新构建适合当前操作系统的sqlite npm run re-sqlite ``` ```json "scripts": { "re-sqlite": "electron-rebuild -f -w better-sqlite3" } ``` -------------------------------- ### Upgrade ee-core to ee-bin Module Source: https://www.kaka996.com/pages/987b1c/pages/e1816f Instructions on how to migrate from 'ee-core' to 'ee-bin' after 'ee-core v2.4.0', including installing 'ee-bin' and modifying the 'package.json' scripts. ```Bash npm i ee-bin -D ``` ```JSON "scripts": { "rd": "ee-bin rd", "encrypt": "ee-bin encrypt", "clean": "ee-bin clean", "icon": "ee-bin icon" } ``` -------------------------------- ### Electron-Egg `appInfo` Object Parameters Source: https://www.kaka996.com/pages/987b1c/pages/201d62 Details the properties available within the `appInfo` object, which provides essential application-related information such as name, base directory, environment, version, and packaging status. ```APIDOC name: 应用名称 baseDir: 框架中electron目录路径,如果使用加密功能,打包后路径为 ./public/electron env: 环境变量,local-本地,prod-生产环境 home: APP根目录路径 root: APP在操作系统中的数据目录,根据环境变量而变化 appUserDataDir: APP在操作系统中的数据目录,与环境变量无关 userHome: 操作系统用户的home目录 appVersion: APP版本号 isPackaged: APP是否已经打包 execDir: APP安装后,可执行程序(exe、dmg、dep)的根目录 ``` -------------------------------- ### Define an Electron-Egg Plugin Class Source: https://www.kaka996.com/pages/987b1c/pages/c08bd9 This JavaScript code defines an `ExampleAddon` class, which serves as a plugin. The constructor automatically receives the `app` object for framework integration. It includes a `hello` method demonstrating basic plugin functionality and shows how the class is exported. ```javascript /** * example插件 * @class */ class ExampleAddon { # 自动注入 app 对象 constructor(app) { this.app = app; } /** * hello * * @function * @since 1.0.0 */ hello () { return 'hello'; } } ExampleAddon.toString = () => '[class ExampleAddon]'; module.exports = ExampleAddon; ``` -------------------------------- ### EE-Bin Build/Resource Path Mappings Source: https://www.kaka996.com/pages/987b1c/pages/fe18e5 Defines various source-to-destination path mappings for project resources, including configuration files, package.json, images, and Python distribution outputs, used for copying or building resources into the Go application's public directory or the build output. ```JavaScript { config: { dest: './go/public/config' }, go_package: { src: './package.json', dest: './go/public/package.json' }, go_images: { src: './public/images', dest: './go/public/images' }, python_dist: { src: './python/dist', dest: './build/extraResources/py' } } ``` -------------------------------- ### Electron-Egg Desktop and Installation Icon Image Specifications Source: https://www.kaka996.com/pages/987b1c/pages/801f4c Provides detailed image specifications, including resolution, width, height, and bit depth, for key desktop and installation icon files such as `256x256.png`, `512x512.png`, `icon.ico`, and `icon.icns` (for macOS) located in the `electron-egg\build\icons` directory. ```Shell # 文件路径 electron-egg\build\icons # 说明 # 图1:256x256.png # 分辨率:256 x 256 # 宽度:256像素 # 高度:256像素 # 位深度:32 # 图2:512x512.png # 分辨率:512 x 512 # 宽度:512像素 # 高度:512像素 # 位深度:32 # 图3:icon.ico # 分辨率:256 x 256 # 宽度:256像素 # 高度:256像素 # 位深度:32 # macOS # 图4:icon.icns # 分辨率:512 x 512 # 宽度:512像素 # 高度:512像素 # 位深度:32 ``` -------------------------------- ### Importing Socket Module Components in Electron-Egg Source: https://www.kaka996.com/pages/987b1c/pages/1593c8 Demonstrates how to import various components from the `ee-core/socket` module, including Koa, IoServer, IoClient, and functions to get server instances, for setting up socket communication. ```JavaScript const { Koa, IoServer, IoClient, loadSocket, getSocketServer, getHttpServer, getIpcServer } = require('ee-core/socket'); ``` -------------------------------- ### Execute NPM Script to Build Go Program for Windows Source: https://www.kaka996.com/pages/987b1c/pages/5c466b An example command demonstrating how to run the `build-go-w` NPM script. This command triggers the configured build process for the Windows platform, including resource movement and Go executable generation. ```Shell npm run build-go-w ``` -------------------------------- ### Recommended Development Environment for Windows 7 Source: https://www.kaka996.com/pages/987b1c/pages/e64ff6 Specifies the compatible versions of Electron, Node.js, and Electron Builder required for developing on Windows 7. This is crucial as Microsoft has ceased official support for this operating system, necessitating specific older versions for compatibility. ```Text electron <= 22 node.js <= 16 electron-builder <= 23.6.0 ``` -------------------------------- ### Define Example Service in Electron-Egg Source: https://www.kaka996.com/pages/987b1c/pages/465a58 This snippet demonstrates how to define a service class, `ExampleService`, in Electron-Egg. It extends `ee-core.Service` and includes an asynchronous `test` method that accepts arguments and returns an object containing a status and the received parameters. ```javascript const Service = require('ee-core').Service; /** * 示例服务 * @class */ class ExampleService extends Service { constructor(ctx) { super(ctx); } /** * test */ async test (args) { let obj = { status:'ok', params: args } return obj; } } module.exports = ExampleService; ``` -------------------------------- ### Electron-Egg Basic Configuration File Structure Source: https://www.kaka996.com/pages/987b1c/pages/201d62 Describes the location and purpose of the core configuration files in the Electron-Egg framework, including default, local, and production-specific settings, along with encryption and hot-reloading configurations. ```APIDOC # 位置 ./electron/config/ # 说明 config.default.js // 默认配置文件,开发环境和生产环境都会加载 config.local.js // 开发环境配置文件,追加和覆盖default配置文件 config.prod.js // 生产环境配置文件,追加和覆盖default配置文件 encrypt.js // 代码加密的配置 nodemon.json // 开发环境,代码(监控)热加载 ``` -------------------------------- ### Implementing an Example Service in Electron-Egg Source: https://www.kaka996.com/pages/987b1c/pages/de1cbf This JavaScript code defines an `ExampleService` class within the `electron-egg` framework. It demonstrates how to create a service, access other services using `Services.get()`, and send messages back to the frontend using `event.reply()` or `event.sender.send()`. The `test` method showcases basic functionality and inter-process communication. ```JavaScript const { Service } = require('ee-core'); const Services = require('ee-core/services'); /** * 示例服务 * @class */ class ExampleService extends Service { constructor(ctx) { super(ctx); } /** * test */ async test (args, event) { let obj = { status:'ok', params: args } // 调用其它service Services.get('framework').test('egg'); // 主动向前端发请求 // channel 前端ipc.on(),监听的路由 const channel = "controller.example.something" // controller 传入 event // IpcMainInvokeEvent event.reply(channel, {age:21}) // IpcMainEvent event.sender.send(`${channel}`, {age:21}) return obj; } } ExampleService.toString = () => '[class ExampleService]'; module.exports = ExampleService; ``` -------------------------------- ### Using Business Logger Methods Source: https://www.kaka996.com/pages/987b1c/pages/9ea8ce Shows examples of calling different logging methods (info, error, debug, warn) on the `logger` instance, which is used for application-specific business logs. ```JavaScript logger.info() logger.error() logger.debug() logger.warn() ``` -------------------------------- ### Initialize Electron-Egg Window Addon Source: https://www.kaka996.com/pages/987b1c/pages/3b0795 Demonstrates how to import the ee-core/addon module and retrieve the "window" addon instance, which is essential for interacting with window management functionalities. ```javascript const Addon = require('ee-core/addon'); const win = Addon.get('window'); ``` -------------------------------- ### Configure Electron-Egg Development Modes Source: https://www.kaka996.com/pages/987b1c/pages/201d62 Illustrates how to configure different development modes (Vue, React, HTML) within Electron-Egg, allowing customization of protocol, hostname, port, and index page settings for each framework. ```JavaScript config.developmentMode = { default: 'vue', mode: { vue: { protocol: 'http://', // 自定义协议头 hostname: 'localhost', port: 8080 }, react: { hostname: 'localhost', port: 3000 }, html: { hostname: 'localhost', indexPage: 'index.html' // 首页 } } }; ``` -------------------------------- ### Build Python Executable with cx_Freeze Source: https://www.kaka996.com/pages/987b1c/pages/c76e73 Instructions to install `cx_Freeze`, a utility for generating standalone Python executables, and then run the npm script to build the Python program, preparing it for seamless integration into the Electron application. ```Bash # 安装 cx_Freeze,它可以生成可执行程序 pip install cx_Freeze # 构建python程序 npm run build-python ``` -------------------------------- ### ee-bin move Command Usage Source: https://www.kaka996.com/pages/987b1c/pages/e1816f Demonstrates how to use the 'ee-bin move' command to transfer frontend, Go, and configuration static resources to a specified directory for production environments, with customizable parameters. ```Bash ee-bin move --flag=frontend_dist ee-bin move --flag=go_static,go_config,go_package,go_images ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.