0

我创建了这样的 PDK 插件:

#include <iostream>
#include <fstream>

#include "PDL.h"
#include "SDL.h"

#define forever for(;;)

using namespace std;

PDL_bool changeUserAgent(PDL_JSParameters * params)
{
    ofstream s("/media/internal/myfile.txt");
    s << "Some content";
    s.close();
    return PDL_TRUE;
}

int main(int argc, char** argv) 
{
    int err = SDL_Init(SDL_INIT_VIDEO);
    if ( err )
    {
        cerr << "Could not init SDL: " << SDL_GetError();
        return 1;
    }

    PDL_Init(0);

    PDL_RegisterJSHandler("changeUserAgent", changeUserAgent);
    PDL_JSRegistrationComplete();
    PDL_CallJS("ready", NULL, 0); //for enyo

    atexit(SDL_Quit);
    atexit(PDL_Quit);

    SDL_Event Event;
    bool paused = false, gotEvent;

    forever
    {
        if (paused) 
        {
            SDL_WaitEvent(&Event);
            gotEvent = true;
        }
        else 
        {
            gotEvent = SDL_PollEvent(&Event);
        }

        while (gotEvent)
        {
            switch (Event.type)
            {
                case SDL_ACTIVEEVENT:
                    if (Event.active.state == SDL_APPACTIVE) {
                        paused = !Event.active.gain;
                    }
                    break;

                case SDL_QUIT:
                    // We exit anytime we get a request to quit the app
                    // all shutdown code is registered via atexit() so this is clean.
                    exit(0);
                    break;

                default:
                    break;
            }
        }

        gotEvent = SDL_PollEvent(&Event);
    }

    return 0;
}

在 Enyo 我打电话

enyo.kind(
{
    name: "UserAgentTool",
    kind: enyo.VFlexBox,
    components: 
    [
        // UI components
        {
            kind: enyo.Hybrid,
            name: "plugin",
            executable: "UserAgentTool-plugin"
        }
    ],
    uaclick: function(inSender)
    { 
        this.$.plugin.callPluginMethodDeferred(null, "changeUserAgent")
        enyo.windows.addBannerMessage("User agent changed to " + inSender.getUserAgent(), '{}') 
    }
});

UI 按钮是一种新类型

enyo.kind(
{
    name: "DeviceButton",
    kind: "Button",
    // some other properties
    onclick: "uaclick",
})

当我单击 DeviceButton 时,横幅会成功升起。这表明执行了uaclick“槽”。但是没有创建文件“/media/internal/myfile.txt”。我究竟做错了什么?

谢谢,马辛

编辑:我应该如何使用回调?我真的是 Enyo 新手 :( 这和“onclick”一样吗?

我的 Enyo 应用程序的 appinfo.json 是:

{
"id": "com.palm.marmistrz.useragenttool",
"version": "1.0.0",
"vendor": "Marcin Mielniczuk",
"type": "web",
"main": "index.html",
"title": "User Agent Tool",
"icon": "icon.png",
"uiRevision":2
}

我没有插件的 appinfo.json。它只是一个可执行文件。目录上的 ls -l 是:

rw-r--r-- 1 marcin marcin  215 Nov  2 13:09 appinfo.json
drwx------ 3 marcin marcin 4096 Nov  7 15:10 build
-rw-r--r-- 1 marcin marcin  100 Oct 31 18:57 depends.js
-rw-r--r-- 1 marcin marcin   21 Oct 13 14:45 framework_config.json
drwxr-xr-x 2 marcin marcin 4096 Oct 13 14:44 images
-rw-r--r-- 1 marcin marcin  295 Oct 13 14:44 index.html
drwx------ 2 marcin marcin 4096 Nov  7 15:08 plugin
drwxr-xr-x 2 marcin marcin 4096 Nov  7 15:06 source
-rw-r--r-- 1 marcin marcin 8884 Nov  6 17:41 UserAgentTool-plugin

build 是构建插件的目录 images 为空 plugin 是插件源 source 是 Enyo 源

我做错了吗?

谢谢!

4

0 回答 0