Skip to content

插件相关

javascript
const core = require('cheese-js');
lua
local core = require('cheese-lua')

安装插件:install(apkPath:string): boolean

参数:

  • string (apkPath):插件路径

返回值:

  • 🟢boolean:true
  • 🔴boolean:false

用法示例:

javascript
const core = require('cheese-js'); //导入核心模块
const plugins = new core.plugins;
const path =  core.path;
if(plugins.install(path.ASSETS_DIRECTORY+"/app-debug.apk")){
    console.log("插件安装成功")
}else{
    console.log("插件安装失败")
}
lua
local core = require('cheese-lua')
local plugins = core.plugins.new()
local path = core.path
if plugins:install(path.ASSETS_DIRECTORY .. "/app-debug.apk") then
    print("插件安装成功")
else
    print("插件安装失败")
end

插件是否存在:public static hasPlugins(pkg: string): plugins

参数:

  • string (pkg):插件包名

返回值:

  • 🟢plugins:存在即返回对应插件的plugins对象
  • 🔴null

用法示例:

javascript
const core = require('cheese-js'); //导入核心模块
let plugins = core.plugins.hasPlugins("com.test")
if(plugins!=null){
    console.log("插件的context",plugins.createContext())
}else{
    console.log("插件尚未安装")
}
lua
local core = require('cheese-lua')
local plugins = core.plugins.hasPlugins("com.test")
if plugins ~= nil then
    print("插件的context", plugins:createContext())
else
    print("插件尚未安装")
end

创建插件上下文:createContext(): any

返回值:

  • 🟢any:插件上下文对象
  • 🔴null

用法示例:

javascript
const core = require('cheese-js'); //导入核心模块
const plugins = new core.plugins;
const path =  core.path;

plugins.install(path.ASSETS_DIRECTORY+"/test.apk")
console.log("插件的context",plugins.createContext())
lua
local core = require('cheese-lua')
local plugins = core.plugins.new()
local path = core.path
plugins:install(path.ASSETS_DIRECTORY .. "/test.apk")
print("插件的context", plugins:createContext())

卸载插件:uninstall(pkg:string): boolean

参数:

  • string (pkg):插件包名

返回值:

  • 🟢boolean:true
  • 🔴boolean:false

用法示例:

javascript
const core = require('cheese-js'); //导入核心模块
const plugins = new core.plugins;
const path =  core.path;
if(plugins.install(path.ASSETS_DIRECTORY+"/app-debug.apk")){
    console.log("插件安装成功")
   if(plugins.uninstall()) {
       console.log("插件卸载成功")
   }else{
       console.log("插件卸载失败")
   }
}else{
    console.log("插件安装失败")
}
lua
local core = require('cheese-lua')
local plugins = core.plugins.new()
local path = core.path
if plugins:install(path.ASSETS_DIRECTORY .. "/app-debug.apk") then
    print("插件安装成功")
    if plugins:uninstall() then
        print("插件卸载成功")
    else
        print("插件卸载失败")
    end
else
    print("插件安装失败")
end

Released under the GPL-3.0 License.