ソースを参照

Initial commit

Christoph Stelz 1 年間 前
コミット
34d03387e7
2 ファイル変更118 行追加0 行削除
  1. 6 0
      firefoxreader.koplugin/_meta.lua
  2. 112 0
      firefoxreader.koplugin/main.lua

+ 6 - 0
firefoxreader.koplugin/_meta.lua

@@ -0,0 +1,6 @@
+local _ = require("gettext")
+return {
+    name = "firefoxreader",
+    fullname = _("FirefoxReader"),
+    description = _([[Display web pages from firefox in near-realtime.]]),
+}

+ 112 - 0
firefoxreader.koplugin/main.lua

@@ -0,0 +1,112 @@
+--[[--
+This is a debug plugin to test Plugin functionality.
+
+@module koplugin.HelloWorld
+--]]--
+
+-- This is a debug plugin, remove the following if block to enable it
+
+local Dispatcher = require("dispatcher")  -- luacheck:ignore
+local InfoMessage = require("ui/widget/infomessage")
+local UIManager = require("ui/uimanager")
+local WidgetContainer = require("ui/widget/container/widgetcontainer")
+local socket = require("socket")
+local BackgroundTaskPlugin = require("ui/plugin/background_task_plugin")
+local PluginShare = require("pluginshare")
+local _ = require("gettext")
+
+local Hello = WidgetContainer:new{
+    name = "firefoxreader",
+    is_doc_only = false,
+}
+
+function Hello:onDispatcherRegisterActions()
+    Dispatcher:registerAction("helloworld_action", {category="none", event="HelloWorld", title=_("Hello World"), general=true,})
+end
+
+function Hello:checkForConnection()
+    print("FFR: Background job is run!", self)
+    if self.socket == nil then
+        print("FFR: no socket")
+        --self:bindSocket()
+    end
+    print("FFR: Socket is now", self.socket)
+
+    local client = self.socket:accept()
+
+    if client == nil then
+        print("No client")
+        return
+    end
+
+    local data = client:receive('*a')
+    local f = io.open(self.tmppath, "w")
+    f:write(data)
+    f:close()
+    local ReaderUI = require("apps/reader/readerui")
+    ReaderUI:showReader("/tmp/test.html")
+    print("FFR: Received data: " .. data)
+
+    client:close()
+end
+
+function Hello:bindSocket()
+    print("FFR: Initializing plugin")
+    self.socket = socket.bind("192.168.0.112", "17144")
+    self.socket:settimeout(0.02) -- 20ms
+    print("FFR: Socket was bound")
+end
+
+function Hello:_schedule()
+    print("Scheduling")
+    self:checkForConnection()
+    UIManager:scheduleIn(4, self.task)
+end
+
+function Hello:init()
+    print("Initializing")
+    self.tmppath = "/tmp/test.html"
+    self.task = function()
+        self:_schedule()
+    end
+    --table.insert(PluginShare.backgroundJobs, {
+    --    when = 2,
+    --    repeated = true,
+    --    executable = function()
+    --        print("hello")
+    --    end,
+    --    callback = function()
+    --        print("Job finished!")
+    --    end,
+    --})
+    local Event = require("ui/event")
+    --UIManager:broadcastEvent(Event:new("BackgroundJobsUpdated"))
+    --print("scheduled")
+    self:onDispatcherRegisterActions()
+    self.ui.menu:registerToMainMenu(self)
+    self:bindSocket()
+    self:_schedule()
+end
+
+function Hello:addToMainMenu(menu_items)
+    menu_items.hello_world = {
+        text = _("Hello World"),
+        -- in which menu this should be appended
+        sorting_hint = "more_tools",
+        -- a callback when tapping
+        callback = function()
+            UIManager:show(InfoMessage:new{
+                text = _("Hello, plugin world"),
+            })
+        end,
+    }
+end
+
+function Hello:onHelloWorld()
+    local popup = InfoMessage:new{
+        text = _("Hello World"),
+    }
+    UIManager:show(popup)
+end
+
+return Hello