Skip to content

CeHub api 参考

API参考

全局API,后续还会完善,取决于我游戏开发是否需要。

version

插件版本目前处在0.0.1版本中。

cehub.process

下面会对个详细参数进行描述。

详细参考

cehub.log

日志打印详情,该插件使用的是electron-log,会在你小程序目录/log文件目录下生成日志文件。

API详情

cehub.store

本地配置文件存储,该插件是直接使用了electron-store,会在你小程序目录/config/config.json生成配置详情文件。

cehub.ElectronStore

如果上面的cehub.store没法满足你,你可以使用这个方法cehub.ElectronStore

案例

js
import cehub from 'cehub'
import { ElectronStore } from 'cehub'

const extensions = new ElectronStore({
  name: 'extensions', // 文件名
  cwd: path.join(cehub.process.APP_USER_DATA, 'extensions') // 存储位置
})

cehub.contextBridge

该方法是继承electron,主要用于渲染程序调用。详情参考

使用案例

js
import { contextBridge } from 'cehub'

contextBridge.exposeInMainWorld("$app", {
  $desktop:{
      doThing: () =>{
        console.log('Hello World')
      }
  }
})

cehub.ipcRenderer

该方法是基础了electron,主要用于主程序跟渲染程序通讯。详情参考

使用案例

js
import { ipcRenderer } from 'cehub'

// Renderer process
ipcRenderer.invoke('some-name', someArgument).then((result) => {
  // ...
})

cehub.appRootPath

该插件使用app-root-path,具体详情API可以参考官网。详情参考

js
   function resolve(pathToModule: string): string
   function require(pathToModule: string): ReturnType<NodeRequire>
   function toString(): string
   function setPath(explicitlySetPath: string): void
   const path: string

cehub.Database

该插件使用的是better-sqlite3数据库,可用于小程序在渲染程序中调用数据库。详情参考

js
import {Database} from 'cehub'

const dbPath = path.join(cehub.process.CE_APP_DIR, 'config', 'data.db')
const db = new Database(dbPath);

cehub.AdmZip

该插件使用adm-zip压缩或解压文件。详情参考

cehub.fs

该插件是扩展了原生node.fs,使用的插件是fs-extra详情参考

cehub.lodash

该插件用于也行数据处理,使用插件lodash详情参考