Skip to content

Commit

Permalink
不用每次都删除窗口,提高性能
Browse files Browse the repository at this point in the history
  • Loading branch information
sugood committed Sep 28, 2022
1 parent 44d0a1d commit f818329
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion modules/commons.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
--- DateTime: 2020/10/24 14:13
---
local console = require("hs.console")
version = "v0.1.9"
version = "v0.2.0"
configPath= "~/.hammerspoon/data/config.json"
initConfigPath= "~/.hammerspoon/data/initConfig.json"
config = {}
Expand Down
22 changes: 13 additions & 9 deletions modules/jsonFormat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
--
--
function init()
sheetView = nil
initWeb()
end

function initWeb()
Expand All @@ -18,7 +18,7 @@ function initWeb()
w = cres.w*0.85,
h = cres.h*1.0
})
sheetView:deleteOnClose(true)
sheetView:deleteOnClose(false)
sheetView:windowTitle("JsonFormat")
sheetView:windowStyle("utility")
sheetView:titleVisibility("hidden")
Expand All @@ -35,7 +35,7 @@ function initWeb()
sheetView:url("https://i.sugood.xyz/pages/jsonweb.html")
sheetView:windowCallback(function(action, webview)
if action == "closing" and not pickedDuration then
sheetView = nil
-- sheetView = nil
end
end)
end
Expand All @@ -44,17 +44,16 @@ end
--- Method
--- Hide the JsonFormat view.
function hide(time)
--sheetView:hide(time)
sheetView:delete()
sheetView:hide(time)
-- sheetView:delete()

sheetView = nil
-- sheetView = nil
end

--- KSheet:show()
--- Method
--- Show JsonFormat.
function show(time)
initWeb()
bindCopyKey()
local str = hs.pasteboard.getContents()
-- local webcontent = generateHtml()
Expand All @@ -64,12 +63,13 @@ function show(time)
--print("窗口焦点"..hs.window.focusedWindow())
sheetView:show(time)
hs.focus()
bindAllSelectKey()
hs.timer.delayed.new(0.7, function() bindPasteKey() end):start()
--bindPasteKey()
end

function toggle()
if sheetView ~= nil and sheetView then
function toggle()
if sheetView and sheetView:hswindow() and sheetView:hswindow():isVisible() then
hide(1)
else
show(1)
Expand All @@ -87,6 +87,10 @@ function bindPasteKey()
hs.eventtap.keyStroke({ "cmd" }, "V")
end

function bindAllSelectKey()
hs.eventtap.keyStroke({ "cmd" }, "A")
end

-- json 格式化
hs.hotkey.bind(hyperCmd, "G", function ()
toggle()
Expand Down

0 comments on commit f818329

Please sign in to comment.