diff --git a/modules/commons.lua b/modules/commons.lua index 410f71f..49a0531 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.4" +version = "v0.1.8" configPath= "~/.hammerspoon/data/config.json" initConfigPath= "~/.hammerspoon/data/initConfig.json" config = {} @@ -284,7 +284,7 @@ hs.hotkey.bind(hyperCmd, "P", function () openColorDialog() end) ---设置颜色拾取快键键 -hs.hotkey.bind(hyperCmd, "C", function () +--设置咖啡因开关 +hs.hotkey.bind(hyperCmd, "S", function () switchCaffeine() end) \ No newline at end of file diff --git a/modules/jsonFormat.lua b/modules/jsonFormat.lua index b432948..0375097 100644 --- a/modules/jsonFormat.lua +++ b/modules/jsonFormat.lua @@ -6,13 +6,6 @@ -- -- ---- KSheet:hide() ---- Method ---- Hide the cheatsheet view. -function hide(time) - sheetView:hide(time) -end - function init() local cscreen = hs.screen.mainScreen() local cres = cscreen:fullFrame() @@ -20,9 +13,9 @@ function init() x = cres.x+cres.w*0.15/2, y = cres.y+cres.h*0.25/2, w = cres.w*0.85, - h = cres.h*0.75 + h = cres.h*1.0 }) - sheetView:windowTitle("CheatSheets") + sheetView:windowTitle("JsonFormat") sheetView:windowStyle("utility") sheetView:titleVisibility("hidden") sheetView:allowGestures(true) @@ -35,17 +28,25 @@ function init() sheetView:shadow(true) sheetView:alpha(1) sheetView:level(hs.drawing.windowLevels.mainMenu) + sheetView:url("https://i.sugood.xyz/pages/jsonweb.html") +end + +--- KSheet:hide() +--- Method +--- Hide the JsonFormat view. +function hide(time) + sheetView:hide(time) end --- KSheet:show() --- Method ---- Show current application's keybindings in a view. +--- Show JsonFormat. function show(time) bindCopyKey() local str = hs.pasteboard.getContents() -- local webcontent = generateHtml() -- sheetView:html(webcontent, "http://localhost") - sheetView:url("https://i.sugood.xyz/pages/jsonweb.html") + -- sheetView:url("https://i.sugood.xyz/pages/jsonweb.html") sheetView:show(time) end diff --git a/modules/systemInfo.lua b/modules/systemInfo.lua index a277b3b..97cc303 100644 --- a/modules/systemInfo.lua +++ b/modules/systemInfo.lua @@ -156,21 +156,31 @@ end function getVmStats() local vmStats = hs.host.vmStat() - --1024^2 - local megDiv = 1048576 - local megMulti = vmStats.pageSize / megDiv + -- --1024^2 + -- local megDiv = 1048576 + -- local megMulti = vmStats.pageSize / megDiv - local totalMegs = vmStats.memSize / megDiv --总内存 - local megsCached = vmStats.fileBackedPages * megMulti --缓存内存 - local freeMegs = vmStats.pagesFree * megMulti --空闲内存 + -- local totalMegs = vmStats.memSize / megDiv --总内存 + -- local megsCached = vmStats.fileBackedPages * megMulti --缓存内存 + -- local freeMegs = vmStats.pagesFree * megMulti --空闲内存 - --第一种方法使用 APP内存+联动内存+被压缩内存 = 已使用内存 - -- local megsUsed = vmStats.pagesWiredDown * megMulti -- 联动内存 - -- megsUsed = megsUsed + vmStats.pagesUsedByVMCompressor * megMulti -- 被压缩内存 - -- megsUsed = megsUsed + (vmStats.pagesActive +vmStats.pagesSpeculative)* megMulti -- APP内存 + -- --第一种方法使用 APP内存+联动内存+被压缩内存 = 已使用内存 + -- --local megsUsed = vmStats.pagesWiredDown * megMulti -- 联动内存 + -- --megsUsed = megsUsed + vmStats.pagesUsedByVMCompressor * megMulti -- 被压缩内存 + -- --megsUsed = megsUsed + (vmStats.pagesActive +vmStats.pagesSpeculative)* megMulti -- APP内存 - --第二种方法使用 总内存-缓存内存-空闲内存 = 已使用内存 - local megsUsed = totalMegs - megsCached - freeMegs + -- --第二种方法使用 总内存-缓存内存-空闲内存 = 已使用内存 + -- local megsUsed = totalMegs - megsCached - freeMegs + + --第三种方法,由于部分设备pageSize获取不正确,所以只能通过已使用页数+缓存页数+空闲页数计算总页数 + local megsUsed = vmStats.pagesWiredDown -- 联动内存 + megsUsed = megsUsed + vmStats.pagesUsedByVMCompressor -- 被压缩内存 + megsUsed = megsUsed + vmStats.pagesActive +vmStats.pagesSpeculative -- APP内存 + + local megsCached = vmStats.fileBackedPages --缓存内存 + local freeMegs = vmStats.pagesFree --空闲内存 + + local totalMegs = megsUsed + megsCached + freeMegs local usedMem = megsUsed/totalMegs * 100 return formatPercent(usedMem) diff --git a/modules/windows.lua b/modules/windows.lua index 60aa519..7cba70c 100644 --- a/modules/windows.lua +++ b/modules/windows.lua @@ -131,7 +131,9 @@ function focusScreen(screen) window.orderedWindows(), fnutils.partial(isInScreen, screen)) local windowToFocus = #windows > 0 and windows[1] or window.desktop() - windowToFocus:focus() + if(windowToFocus ~=nil ) then + windowToFocus:focus() + end -- move cursor to center of screen local pt = geometry.rectMidPoint(screen:fullFrame())