From f818329d179fba648072a14c96d4b2d672ca28f8 Mon Sep 17 00:00:00 2001 From: sugood <15820258199@163.com> Date: Wed, 28 Sep 2022 11:59:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8D=E7=94=A8=E6=AF=8F=E6=AC=A1=E9=83=BD?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E7=AA=97=E5=8F=A3=EF=BC=8C=E6=8F=90=E9=AB=98?= =?UTF-8?q?=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/commons.lua | 2 +- modules/jsonFormat.lua | 22 +++++++++++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/modules/commons.lua b/modules/commons.lua index 99bb824..dd20e13 100644 --- a/modules/commons.lua +++ b/modules/commons.lua @@ -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 = {} diff --git a/modules/jsonFormat.lua b/modules/jsonFormat.lua index 7cbfc2b..d8ff742 100644 --- a/modules/jsonFormat.lua +++ b/modules/jsonFormat.lua @@ -6,7 +6,7 @@ -- -- function init() - sheetView = nil + initWeb() end function initWeb() @@ -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") @@ -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 @@ -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() @@ -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) @@ -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()