不用每次都删除窗口,提高性能
This commit is contained in:
parent
44d0a1dade
commit
f818329d17
@ -4,7 +4,7 @@
|
|||||||
--- DateTime: 2020/10/24 14:13
|
--- DateTime: 2020/10/24 14:13
|
||||||
---
|
---
|
||||||
local console = require("hs.console")
|
local console = require("hs.console")
|
||||||
version = "v0.1.9"
|
version = "v0.2.0"
|
||||||
configPath= "~/.hammerspoon/data/config.json"
|
configPath= "~/.hammerspoon/data/config.json"
|
||||||
initConfigPath= "~/.hammerspoon/data/initConfig.json"
|
initConfigPath= "~/.hammerspoon/data/initConfig.json"
|
||||||
config = {}
|
config = {}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
--
|
--
|
||||||
--
|
--
|
||||||
function init()
|
function init()
|
||||||
sheetView = nil
|
initWeb()
|
||||||
end
|
end
|
||||||
|
|
||||||
function initWeb()
|
function initWeb()
|
||||||
@ -18,7 +18,7 @@ function initWeb()
|
|||||||
w = cres.w*0.85,
|
w = cres.w*0.85,
|
||||||
h = cres.h*1.0
|
h = cres.h*1.0
|
||||||
})
|
})
|
||||||
sheetView:deleteOnClose(true)
|
sheetView:deleteOnClose(false)
|
||||||
sheetView:windowTitle("JsonFormat")
|
sheetView:windowTitle("JsonFormat")
|
||||||
sheetView:windowStyle("utility")
|
sheetView:windowStyle("utility")
|
||||||
sheetView:titleVisibility("hidden")
|
sheetView:titleVisibility("hidden")
|
||||||
@ -35,7 +35,7 @@ function initWeb()
|
|||||||
sheetView:url("https://i.sugood.xyz/pages/jsonweb.html")
|
sheetView:url("https://i.sugood.xyz/pages/jsonweb.html")
|
||||||
sheetView:windowCallback(function(action, webview)
|
sheetView:windowCallback(function(action, webview)
|
||||||
if action == "closing" and not pickedDuration then
|
if action == "closing" and not pickedDuration then
|
||||||
sheetView = nil
|
-- sheetView = nil
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
@ -44,17 +44,16 @@ end
|
|||||||
--- Method
|
--- Method
|
||||||
--- Hide the JsonFormat view.
|
--- Hide the JsonFormat view.
|
||||||
function hide(time)
|
function hide(time)
|
||||||
--sheetView:hide(time)
|
sheetView:hide(time)
|
||||||
sheetView:delete()
|
-- sheetView:delete()
|
||||||
|
|
||||||
sheetView = nil
|
-- sheetView = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
--- KSheet:show()
|
--- KSheet:show()
|
||||||
--- Method
|
--- Method
|
||||||
--- Show JsonFormat.
|
--- Show JsonFormat.
|
||||||
function show(time)
|
function show(time)
|
||||||
initWeb()
|
|
||||||
bindCopyKey()
|
bindCopyKey()
|
||||||
local str = hs.pasteboard.getContents()
|
local str = hs.pasteboard.getContents()
|
||||||
-- local webcontent = generateHtml()
|
-- local webcontent = generateHtml()
|
||||||
@ -64,12 +63,13 @@ function show(time)
|
|||||||
--print("窗口焦点"..hs.window.focusedWindow())
|
--print("窗口焦点"..hs.window.focusedWindow())
|
||||||
sheetView:show(time)
|
sheetView:show(time)
|
||||||
hs.focus()
|
hs.focus()
|
||||||
|
bindAllSelectKey()
|
||||||
hs.timer.delayed.new(0.7, function() bindPasteKey() end):start()
|
hs.timer.delayed.new(0.7, function() bindPasteKey() end):start()
|
||||||
--bindPasteKey()
|
--bindPasteKey()
|
||||||
end
|
end
|
||||||
|
|
||||||
function toggle()
|
function toggle()
|
||||||
if sheetView ~= nil and sheetView then
|
if sheetView and sheetView:hswindow() and sheetView:hswindow():isVisible() then
|
||||||
hide(1)
|
hide(1)
|
||||||
else
|
else
|
||||||
show(1)
|
show(1)
|
||||||
@ -87,6 +87,10 @@ function bindPasteKey()
|
|||||||
hs.eventtap.keyStroke({ "cmd" }, "V")
|
hs.eventtap.keyStroke({ "cmd" }, "V")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function bindAllSelectKey()
|
||||||
|
hs.eventtap.keyStroke({ "cmd" }, "A")
|
||||||
|
end
|
||||||
|
|
||||||
-- json 格式化
|
-- json 格式化
|
||||||
hs.hotkey.bind(hyperCmd, "G", function ()
|
hs.hotkey.bind(hyperCmd, "G", function ()
|
||||||
toggle()
|
toggle()
|
||||||
|
Loading…
Reference in New Issue
Block a user