1. 参考网址:https://forum.openmediavault....
  2. 创建应用GUI
    创建应用目录:/var/www/openmediavault/js/omv/module/admin/service/example
    创建菜单节点: Node.js

    ```

    // require("js/omv/WorkspaceManager.js")
    OMV.WorkspaceManager.registerNode({
    id: 'example',
    path: '/service',
    text: _('Example'),
    icon16: 'images/example.png',
    iconSvg: 'images/example.svg'
    });
    ```

    设置菜单节点图标
    var/www/openmediavault/images 内创建对应Node.js内的2张图片

    创建设置面板: Settings.js

    ```

    // require("js/omv/WorkspaceManager.js")
    // require("js/omv/workspace/form/Panel.js")
    Ext.define('OMV.module.admin.service.example.Settings', {
    extend: 'OMV.workspace.form.Panel',

    rpcService: 'Example',
    rpcGetMethod: 'getSettings',
    rpcSetMethod: 'setSettings',

    getFormItems: function() {
    return [{
    xtype: 'fieldset',
    title: _('General'),
    fieldDefaults: {
    labelSeparator: ''
    },
    items: [{
    xtype: 'checkbox',
    name: 'enable',
    fieldLabel: _('Enable'),
    checked: false
    },
    {
    xtype: 'numberfield',
    name: 'max_value',
    fieldLabel: _('Max value'),
    minValue: 0,
    maxValue: 100,
    allowDecimals: false,
    allowBlank: true
    }]
    }];
    }
    });

    OMV.WorkspaceManager.registerPanel({
    id: 'settings',
    path: '/service/example',
    text: _('Settings'),
    position: 10,
    className: 'OMV.module.admin.service.example.Settings'
    });
    ```

    刷新js缓存:

    ```

    source /usr/share/openmediavault/scripts/helper-functions && omv_purge_internal_cache
    ```

  3. 创建shell脚本
    生成配置信息的脚本postinst 命令执行:/bin/sh postinst configure

    ```

    #!/bin/sh

    set -e

    . /etc/default/openmediavault
    . /usr/share/openmediavault/scripts/helper-functions

    case "$1" in
    configure)
    SERVICE_XPATH_NAME="example"
    SERVICE_XPATH="/config/services/${SERVICE_XPATH_NAME}"

    # 添加默认配置
    if ! omv_config_exists "${SERVICE_XPATH}"; then
    omv_config_add_element "/config/services" "${SERVICE_XPATH_NAME}"
    omv_config_add_element "${SERVICE_XPATH}" "enable" "0"
    omv_config_add_element "${SERVICE_XPATH}" "max_value" "0"
    fi

    # 以下2条命令用于安装包安装 直接执行可注释掉
    dpkg-trigger update-fixperms
    dpkg-trigger update-locale
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

    *)
    echo "postinst called with unknown argument" >&2
    exit 1
    ;;
    esac

    #DEBHELPER#

    exit 0
    ```

    创建删除配置信息的shell脚本 postrm 执行命令:/bin/sh postrm purge

    ```

    #!/bin/sh

    set -e

    . /etc/default/openmediavault
    . /usr/share/openmediavault/scripts/helper-functions

    SERVICE_XPATH_NAME="example"
    SERVICE_XPATH="/config/services/${SERVICE_XPATH_NAME}"

    case "$1" in
    purge)
    if omv_config_exists ${SERVICE_XPATH}; then
    omv_config_delete ${SERVICE_XPATH}
    fi
    ;;

    remove)
    ;;

    upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
    ;;

    *)
    echo "postrm called with unknown argument \\`$1'" >&2
    exit 1
    ;;
    esac

    #DEBHELPER#

    exit 0
    ```

  4. 创建rpc
    在目录/usr/share/openmediavault/engined/rpc创建example.inc

    ```

    <?php
    class OMVRpcServiceExample extends \OMV\Rpc\ServiceAbstract {

    public function getName() {
    return "EXAMPLE";
    }

    public function initialize() {
    $this->registerMethod("getSettings");
    $this->registerMethod("setSettings");
    }

    public function getSettings($params, $context) {
    // Validate the RPC caller context.
    $this->validateMethodContext($context, [
    "role" => OMV_ROLE_ADMINISTRATOR
    ]);
    // Get the configuration object.
    $db = \\OMV\\Config\\Database::getInstance();
    $object = $db->get("conf.service.example");
    // Remove useless properties from the object.
    return $object->getAssoc();
    }

    public function setSettings($params, $context) {
    // Validate the RPC caller context.
    $this->validateMethodContext($context, [
    "role" => OMV_ROLE_ADMINISTRATOR
    ]);
    // Validate the parameters of the RPC service method.
    $this->validateMethodParams($params, "rpc.example.setsettings");
    // Get the existing configuration object.
    $db = \\OMV\\Config\\Database::getInstance();
    $object = $db->get("conf.service.example");
    $object->setAssoc($params);
    $db->set($object);
    // Return the configuration object.
    return $object->getAssoc();
    }
    }
    ```

    创建对应的配置文件
    在usr\share\openmediavault\datamodels创建conf.service.example.json

    ```

    {
    "type": "config",
    "id": "conf.service.example",
    "title": "EXAMPLE",
    "queryinfo": {
    "xpath": "//services/example",
    "iterable": false
    },
    "properties": {
    "enable": {
    "type": "boolean",
    "default": false
    },
    "max_value": {
    "type": "integer",
    "minimum": 1,
    "maximum": 100,
    "default": 0
    }
    }
    }
    ```

    在usr\share\openmediavault\datamodels创建rpc.example.json

    ```

    [{
    "type": "rpc",
    "id": "rpc.example.setsettings",
    "params": {
    "type": "object",
    "properties": {
    "enable": {
    "type": "boolean",
    "required": true
    },
    "max_value": {
    "type": "integer",
    "minimum": 1,
    "maximum": 100,
    "required": true
    }
    }
    }
    }]
    ```

    运行命令重启omv服务:service openmediavault-engined restart

  5. 创建shell脚本获取配置信息
    创建执行脚本 example 执行命令:omv-mkconf example

    ```

    #!/bin/sh

    set -e

    . /etc/default/openmediavault
    . /usr/share/openmediavault/scripts/helper-functions

    OMV_EXAMPLE_XPATH="/config/services/example"
    OMV_EXAMPLE_CONF="/tmp/example.conf"

    cat <<EOF > ${OMV_EXAMPLE_CONF}
    enable = $(omv_config_get "${OMV_EXAMPLE_XPATH}/enable")
    max_value = $(omv_config_get "${OMV_EXAMPLE_XPATH}/max_value")
    EOF

    exit 0
    ```

    为了监听触发执行脚本,将脚本放在/usr/share/openmediavault/mkconf目录下
    脚本权限改为 chmod 755 example

  6. 配置保存事件监听

    /usr/share/openmediavault/engined/module创建监听的example.inc

    ```

    <?php
    class OMVModuleExample extends \OMV\Engine\Module\ServiceAbstract
    implements \OMV\Engine\Notify\IListener {
    public function getName() {
    return "EXAMPLE";
    }

    public function applyConfig() {
    // 触发对应执行脚本
    $cmd = new \\OMV\\System\\Process("omv-mkconf", "example");
    $cmd->setRedirect2to1();
    $cmd->execute();
    }

    function bindListeners(\\OMV\\Engine\\Notify\\Dispatcher $dispatcher) {
    $dispatcher->addListener(OMV_NOTIFY_MODIFY,
    "org.openmediavault.conf.service.example", // 和rpc内的配置文件一致conf.service.example
    [ $this, "setDirty" ]);
    }
    }
    ```

    运行命令重启omv服务:service openmediavault-engined restart

  7. 创建deb包 https://blog.csdn.net/gatieme...

原文地址:https://segmentfault.com/a/1190000016716780

openmediavault 4.1.3 插件开发的更多相关文章

  1. JavaScript学习笔记(四)——jQuery插件开发与发布

    jQuery插件就是以jQuery库为基础衍生出来的库,jQuery插件的好处是封装功能,提高了代码的复用性,加快了开发速度,现在网络上开源的jQuery插件非常多,随着版本的不停迭代越来越稳定好用, ...

  2. jira的插件开发流程实践

    怎么开头呢,由于自己比较懒,博客一直不怎么弄,以后克己一点,多传点自己遇到的问题和经历上来,供自己以后记忆,也供需要的小伙伴少走点弯路吧 最近公司项目需要竞标一个运维项目,甲方给予了既定的几种比较常用 ...

  3. Vue插件开发入门

    相对组件来说,Vue 的插件开发受到的关注要少一点.但是插件的功能是十分强大的,能够完成许多 Vue 框架本身不具备的功能. 大家一般习惯直接调用现成的插件,比如官方推荐的 vue-router.vu ...

  4. 【原创】记一次Project插件开发

    一.开发背景 最近在使用微软的Office Project 2010 进行项目管理,看到排的满满的计划任务,一个个地被执行完毕,还是很有成就感的.其实,不光是在工作中可以使用Project进行项目进度 ...

  5. JavaScript学习总结(四)——jQuery插件开发与发布

    jQuery插件就是以jQuery库为基础衍生出来的库,jQuery插件的好处是封装功能,提高了代码的复用性,加快了开发速度,现在网络上开源的jQuery插件非常多,随着版本的不停迭代越来越稳定好用, ...

  6. [Tool] Open Live Writer插件开发

    一 前言 Windows Live Writer(简称 WLW)开源之后变成 Open Live Writer(简称 OLW),原先 WLW 的插件在 OLW 下都不能用了,原因很简单,WLW 插件开 ...

  7. VS插件开发 - 登录身份验证

    [附加] 很多朋友问那个VS背景怎么弄的,我刚刚已经抽时间把制作步骤发出来了: 请参见<VS插件开发 - 个性化VS IDE编辑器,瞬间 高 大 上>. 最近一直在忙着一些事情,一直没有发 ...

  8. jQuery插件开发精品教程,让你的jQuery提升一个台阶

    要说jQuery 最成功的地方,我认为是它的可扩展性吸引了众多开发者为其开发插件,从而建立起了一个生态系统.这好比大公司们争相做平台一样,得平台者得天下.苹果,微软,谷歌等巨头,都有各自的平台及生态圈 ...

  9. 开源遥感平台opticks插件开发指南

    Opticks是一款开源的遥感数据处理平台,与其同类开源软件OSSIM一样,支持种类丰富的数据文件格式,但其最大特点为设计精巧的插件开发模式,在设计技巧上,系统提供了良好的封装特性,即使插件开发者对框 ...

随机推荐

  1. Codeforces731E Funny Game

    dp[i][0]表示从i出发,轮到先手走的最优值. dp[i][1]表示从i出发,轮到后手走的最优值. dp[i][0]=max(dp[j][1]+sum[j]) dp[i][1]=min(dp[j] ...

  2. Ubuntu解决中文乱码

    gsettings set org.gnome.gedit.preferences.encodings candidate-encodings "['GB18030', 'UTF-8', ' ...

  3. java实训 :异常(try-catch执行顺序与自定义异常)

    关键字: try:执行可能产生异常的代码 catch:捕获异常 finally:无论是否发生异常代码总能执行 throws:声明方法可能要抛出的各种异常 throw:手动抛出自定义异常 用 try-c ...

  4. php 中的引用(&)与foreach结合后的一个注意点

    关于php中引用的概念及foreach循环的的应用就不多说了,php文档已经说的很明白了.直接上一段代码: <?php $arr = array(1,2, 3); foreach($arr as ...

  5. 【转】有了Auto Layout,为什么你还是害怕写UITabelView的自适应布局?

      Apple 算是最重视应用开发体验的公司了.从Xib到StoryBoard,从Auto Layout到Size Class,每一次的更新,都会给iOS应用的开发带来不小的便利.但是,对于绝对多数i ...

  6. 跟我一起玩Win32开发(9):绘图(B)

    我们今天继续涂鸦,实践证明,涂鸦是人生一大乐趣. 首先,我们写一个程序骨架子,以便做实验. #include <Windows.h> LRESULT CALLBACK MainWinPro ...

  7. [CQOI2014]通配符匹配

    Description 几乎所有操作系统的命令行界面(CLI)中都支持文件名的通配符匹配以方便用户.最常见的通配符有两个,一个是星号(""'),可以匹配0个及以上的任意字符:另一个 ...

  8. Jamie and Interesting Graph CodeForces - 916C

    http://codeforces.com/problemset/problem/916/C 好尬的题啊... #include<cstdio> #include<algorithm ...

  9. Python+selenium定位不到元素的问题及解决方案

    在操作过程中主要遇到两种阻塞的问题,总结如下: 1.页面中有iframe,定位元素时,需要用switch_to.frame()转换到元素所在的frame上再去定位 2.遇到一种新情况,有些按钮在htm ...

  10. solr 包地址

    http://archive.apache.org/dist/lucene/solr/6.3.0/