Files
qt-creator/share/qtcreator/lua-plugins/tellajoke/tellajoke.lua
Eike Ziller f5dde31558 Move the shipped Lua plugins to the resources directory
On macOS, files in Contents/PlugIns/ need to be codesigned individually.
Since Lua plugins are not really binaries, per Apple's documentation
that is to be avoided (and we currently only sign executables there).

Just move Lua plugins generally to the resources directory, like we do
for other scripts like the debugger Python scripts, and load them from
there.

Change-Id: Idabd6b7c0c7c6e842b1752488cb7073f00e7be49
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
2024-06-20 07:40:46 +00:00

57 lines
1.6 KiB
Lua

--- Copyright (C) 2024 The Qt Company Ltd.
--- SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
local function fetchJoke()
print("Fetching ...")
local a = require("async")
local fetch = require("Fetch").fetch
local utils = require("Utils")
local mm = require("MessageManager")
local r = a.wait(fetch({ url = "https://official-joke-api.appspot.com/random_joke", convertToTable = true }))
if (type(r) == "table") then
mm.writeDisrupting(r.setup)
a.wait(utils.waitms(1000))
mm.writeSilently(".")
a.wait(utils.waitms(1000))
mm.writeSilently(".")
a.wait(utils.waitms(1000))
mm.writeSilently(".")
a.wait(utils.waitms(1000))
mm.writeDisrupting(r.punchline)
else
print("echo Error fetching: " .. r)
end
end
local function fetchJokeSafe()
local ok, err = pcall(fetchJoke)
if not ok then
print("echo Error fetching: " .. err)
end
end
local function setup()
local a = require("async")
Action = require("Action")
Action.create("Simple.joke", {
text = "Tell a joke",
onTrigger = function() a.sync(fetchJokeSafe)() end,
defaultKeySequences = { "Meta+Ctrl+Shift+J", "Ctrl+Shift+Alt+J" },
})
end
return {
Name = "Tell A Joke",
Version = "1.0.0",
CompatVersion = "1.0.0",
Vendor = "The Qt Company",
Category = "Fun",
Description = "This plugin adds an action that tells a joke.",
Dependencies = {
{ Name = "Lua", Version = "14.0.0" },
},
setup = setup,
} --[[@as QtcPlugin]]