优化格式化json功能
This commit is contained in:
parent
4e885b3869
commit
44d0a1dade
@ -4,7 +4,7 @@
|
||||
--- DateTime: 2020/10/24 14:13
|
||||
---
|
||||
local console = require("hs.console")
|
||||
version = "v0.1.8"
|
||||
version = "v0.1.9"
|
||||
configPath= "~/.hammerspoon/data/config.json"
|
||||
initConfigPath= "~/.hammerspoon/data/initConfig.json"
|
||||
config = {}
|
||||
|
@ -5,8 +5,11 @@
|
||||
-----
|
||||
--
|
||||
--
|
||||
|
||||
function init()
|
||||
sheetView = nil
|
||||
end
|
||||
|
||||
function initWeb()
|
||||
local cscreen = hs.screen.mainScreen()
|
||||
local cres = cscreen:fullFrame()
|
||||
sheetView = hs.webview.newBrowser({
|
||||
@ -15,6 +18,7 @@ function init()
|
||||
w = cres.w*0.85,
|
||||
h = cres.h*1.0
|
||||
})
|
||||
sheetView:deleteOnClose(true)
|
||||
sheetView:windowTitle("JsonFormat")
|
||||
sheetView:windowStyle("utility")
|
||||
sheetView:titleVisibility("hidden")
|
||||
@ -23,35 +27,49 @@ function init()
|
||||
sheetView:allowTextEntry(true)
|
||||
sheetView:closeOnEscape(true)
|
||||
sheetView:bringToFront(false)
|
||||
sheetView:darkMode(true)
|
||||
sheetView:darkMode(false)
|
||||
sheetView:reload(false)
|
||||
sheetView:shadow(true)
|
||||
sheetView:alpha(1)
|
||||
sheetView:level(hs.drawing.windowLevels.mainMenu)
|
||||
sheetView:level(hs.drawing.windowLevels.mainMenu) --设置窗口置顶
|
||||
sheetView:url("https://i.sugood.xyz/pages/jsonweb.html")
|
||||
sheetView:windowCallback(function(action, webview)
|
||||
if action == "closing" and not pickedDuration then
|
||||
sheetView = nil
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
--- KSheet:hide()
|
||||
--- Method
|
||||
--- Hide the JsonFormat view.
|
||||
function hide(time)
|
||||
sheetView:hide(time)
|
||||
--sheetView:hide(time)
|
||||
sheetView:delete()
|
||||
|
||||
sheetView = nil
|
||||
end
|
||||
|
||||
--- KSheet:show()
|
||||
--- Method
|
||||
--- Show JsonFormat.
|
||||
function show(time)
|
||||
initWeb()
|
||||
bindCopyKey()
|
||||
local str = hs.pasteboard.getContents()
|
||||
-- local webcontent = generateHtml()
|
||||
-- sheetView:html(webcontent, "http://localhost")
|
||||
-- sheetView:url("https://i.sugood.xyz/pages/jsonweb.html")
|
||||
|
||||
--print("窗口焦点"..hs.window.focusedWindow())
|
||||
sheetView:show(time)
|
||||
hs.focus()
|
||||
hs.timer.delayed.new(0.7, function() bindPasteKey() end):start()
|
||||
--bindPasteKey()
|
||||
end
|
||||
|
||||
function toggle()
|
||||
if sheetView and sheetView:hswindow() and sheetView:hswindow():isVisible() then
|
||||
if sheetView ~= nil and sheetView then
|
||||
hide(1)
|
||||
else
|
||||
show(1)
|
||||
@ -64,7 +82,12 @@ init()
|
||||
function bindCopyKey()
|
||||
hs.eventtap.keyStroke({ "cmd" }, "C")
|
||||
end
|
||||
-- 添加片段(按下快捷键时做一个复制操作,并记录复制的内容到片段列表中)
|
||||
|
||||
function bindPasteKey()
|
||||
hs.eventtap.keyStroke({ "cmd" }, "V")
|
||||
end
|
||||
|
||||
-- json 格式化
|
||||
hs.hotkey.bind(hyperCmd, "G", function ()
|
||||
toggle()
|
||||
end)
|
||||
|
Loading…
Reference in New Issue
Block a user