From a75843b3a2e986b996fd14376db6b05167365363 Mon Sep 17 00:00:00 2001 From: sugood <15820258199@163.com> Date: Sat, 24 Oct 2020 23:17:20 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=88=E6=9C=ACv0.1.1=20----1=E3=80=81?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=98=BE=E7=A4=BA=E8=BE=93=E5=85=A5=E6=B3=95?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E7=9A=84=E5=8A=9F=E8=83=BD=EF=BC=9B2?= =?UTF-8?q?=E3=80=81=E6=96=B0=E5=A2=9E=E6=97=B6=E9=97=B4=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=9B3=E3=80=81=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E7=BF=BB=E8=AF=91=E5=8A=9F=E8=83=BD=EF=BC=9B4=E3=80=81?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=92=96=E5=95=A1=E5=9B=A0=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=EF=BC=9B5=E3=80=81=E6=96=B0=E5=A2=9E=E5=B1=8F=E5=B9=95?= =?UTF-8?q?=E5=8F=96=E8=89=B2=E5=8A=9F=E8=83=BD=EF=BC=9B6=E3=80=81?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=8F=9C=E5=8D=95=E6=A0=8F=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/.hammerspoon.iml | 9 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + .idea/workspace.xml | 878 +++++++++++++++++++++++++ Spoons/Caffeine.spoon/caffeine-off.pdf | 234 +++++++ Spoons/Caffeine.spoon/caffeine-on.pdf | 238 +++++++ Spoons/Caffeine.spoon/docs.json | 143 ++++ Spoons/Caffeine.spoon/init.lua | 119 ++++ data/config.json | 12 + data/dictHistory.json | 3 + data/history.json | 12 + icon/caffeine-off.pdf | 234 +++++++ icon/caffeine-on.pdf | 238 +++++++ icon/input_abc.pdf | Bin 0 -> 133060 bytes icon/input_cn.pdf | Bin 0 -> 126907 bytes icon/input_en.pdf | Bin 0 -> 128928 bytes icon/input_u.pdf | Bin 0 -> 64396 bytes init.lua | 12 +- modules/caffeine.lua | 16 + modules/commons.lua | 226 +++++++ modules/dict.lua | 205 ++++++ modules/hotkey.lua | 3 +- modules/inputstat.lua | 128 ++++ modules/jsonFormat.lua | 208 ++++++ modules/snippet.lua | 13 +- modules/timesync.lua | 59 ++ timesync/timesync.sh | 15 + 27 files changed, 3006 insertions(+), 13 deletions(-) create mode 100644 .idea/.hammerspoon.iml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 100644 Spoons/Caffeine.spoon/caffeine-off.pdf create mode 100644 Spoons/Caffeine.spoon/caffeine-on.pdf create mode 100644 Spoons/Caffeine.spoon/docs.json create mode 100644 Spoons/Caffeine.spoon/init.lua create mode 100644 data/config.json create mode 100644 data/dictHistory.json create mode 100644 icon/caffeine-off.pdf create mode 100644 icon/caffeine-on.pdf create mode 100644 icon/input_abc.pdf create mode 100644 icon/input_cn.pdf create mode 100644 icon/input_en.pdf create mode 100644 icon/input_u.pdf create mode 100644 modules/caffeine.lua create mode 100644 modules/commons.lua create mode 100644 modules/dict.lua create mode 100644 modules/inputstat.lua create mode 100644 modules/jsonFormat.lua create mode 100644 modules/timesync.lua create mode 100755 timesync/timesync.sh diff --git a/.idea/.hammerspoon.iml b/.idea/.hammerspoon.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/.hammerspoon.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..e632461 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..dae6639 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,878 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + SubStringGetByteCount + historyPath + translation + hs.json + setState + isEm + webview + console.clearConsole() + menubar + config + menubar.new(true) + searchResult + keywords + hs.hotkey.bind + hs.hotkey + displayIdle + syntaxHighlight + hs.alert.show + 切换 + isSyncTime + hs.dialog + else if + elseif + colorDialog + appid + mChooser + baiduAppSecret + baiduAppid + hs.dialog.blockAlert + ydAppKey + + + self.menubar + macMenubar + + + + + + + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+                
+            
+        
+        
+        
+ +
+ + + + + ]] + + return html +end + + +--- 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() + sheetView = hs.webview.newBrowser({ + 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 + }) + sheetView:windowTitle("CheatSheets") + sheetView:windowStyle("utility") + sheetView:titleVisibility("hidden") + sheetView:allowGestures(true) + sheetView:allowNewWindows(false) + sheetView:allowTextEntry(true) + sheetView:closeOnEscape(true) + sheetView:bringToFront(false) + sheetView:darkMode(true) + sheetView:reload(false) + sheetView:level(hs.drawing.windowLevels.mainMenu) +end + +--- KSheet:show() +--- Method +--- Show current application's keybindings in a view. +function show(time) + local webcontent = generateHtml() + sheetView:html(webcontent, "http://localhost") + sheetView:show(time) +end + +function toggle() + if sheetView and sheetView:hswindow() and sheetView:hswindow():isVisible() then + hide(2) + else + show(2) + end +end + +init() + +-- 添加片段(按下快捷键时做一个复制操作,并记录复制的内容到片段列表中) +hs.hotkey.bind(hyperCmd, "G", function () + toggle() +end) diff --git a/modules/snippet.lua b/modules/snippet.lua index 2fd703e..59def20 100644 --- a/modules/snippet.lua +++ b/modules/snippet.lua @@ -1,7 +1,5 @@ local chooser = require("hs.chooser") -local console = require("hs.console") -console.clearConsole() local historyPath= "~/.hammerspoon/data/history.json" local maxLength = 1000 local history = {} @@ -24,10 +22,7 @@ function duplicate(table,keys) end return false end --- 字符串判空 -function isEmpty(str) - return str == nil or str == '' -end + -- 查询text是否存在并返回索引index -- 等于0为没有查询到,大于0为查询到 function searchByText(table,text) @@ -120,7 +115,7 @@ end local rightClickCallbackFn = function(index) if index and index > 0 then local selectResult = mChooser:selectedRowContents(index) - if selectResult == nil or isEmpty(selectResult.text) then + if selectResult == nil or stringIsEmpty(selectResult.text) then return end index = searchByText(history,selectResult.text) @@ -160,7 +155,7 @@ local rightClickCallbackFn = function(index) end end -- 选取片段内容(按下快捷键时显示片段列表,点击选中的快捷键将自动粘贴) -hs.hotkey.bind({ "ctrl", "cmd" }, "V", function () +hs.hotkey.bind(hyperCmd, "V", function () mChooser = chooser.new(completionFn) :choices(history) :rightClickCallback(rightClickCallbackFn) @@ -168,7 +163,7 @@ hs.hotkey.bind({ "ctrl", "cmd" }, "V", function () :show() end) -- 添加片段(按下快捷键时做一个复制操作,并记录复制的内容到片段列表中) -hs.hotkey.bind({"ctrl", "cmd"}, "A", function () +hs.hotkey.bind(hyperCmd, "X", function () bindCopyKey() if hs.dialog.blockAlert("添加片段:‘|’为分隔符,建议按如下格式","内容|keyword|示例|说明","确定","取消","informational") == "确定" then addToHistory() diff --git a/modules/timesync.lua b/modules/timesync.lua new file mode 100644 index 0000000..d0a7054 --- /dev/null +++ b/modules/timesync.lua @@ -0,0 +1,59 @@ +--- +--- 时间同步,开启后在系统或屏幕唤醒后自动同步一次时间 +--- Created by sugood(https://github.com/sugood). +--- DateTime: 2020/10/23 11:12 +--- + +function execTimeSync() + local shell_command = 'expect ~/.hammerspoon/timesync/timesync.sh '.. config[1].rootPassword + result = table.pack(hs.execute(shell_command,true)) + print(result[1]) +end +function caffeinateCallback(eventType) + if (eventType == hs.caffeinate.watcher.screensDidSleep) then + print("screensDidSleep") + elseif (eventType == hs.caffeinate.watcher.screensDidWake) then + execTimeSync() + hs.reload() + print("screensDidWake") + elseif (eventType == hs.caffeinate.watcher.systemDidWake) then + execTimeSync() + hs.reload() + print("systemDidWake") + elseif (eventType == hs.caffeinate.watcher.screensDidLock) then + print("screensDidLock") + elseif (eventType == hs.caffeinate.watcher.screensDidUnlock) then + print("screensDidUnlock") + end +end + +function initData() + if config ~=nil and config[1].isSyncTime == 'on' then + caffeinateWatcher = hs.caffeinate.watcher.new(caffeinateCallback) + caffeinateWatcher:start() + + -- 添加片段(按下快捷键时做一个复制操作,并记录复制的内容到片段列表中) + hs.hotkey.bind(hyperCmd, "T", function () + if hs.json.read(configPath) ~= nil then + config = hs.json.read(configPath) + end + if(stringIsEmpty(config[1].rootPassword)) then + local result,subText = hs.dialog.textPrompt("输入开机密码", "时间同步操作需要开机密码", '', "确定", "取消", true) + if result == "确定" then + if(stringIsEmpty(subText) == false) then + config[1].rootPassword = subText + hs.json.write(config,configPath, true, true) + execTimeSync() + hs.alert.show('同步时间') + end + end + else + execTimeSync() + hs.alert.show('同步时间') + end + end) + end +end +-- 初始化,读取本地数据 +initData() + diff --git a/timesync/timesync.sh b/timesync/timesync.sh new file mode 100755 index 0000000..210efaf --- /dev/null +++ b/timesync/timesync.sh @@ -0,0 +1,15 @@ +#timesyne.sh +#expect的安装路径 +#/usr/local/bin/expect这个路径安装完expect之后 which expect可以查看 +#!/usr/local/bin/expect + +set timeout 10 +set passwd [lindex $argv 0] + +spawn sudo sntp -sS ntp.aliyun.com +#根据输出传递数据,在这里是等待密码提示显示 +expect "*assword*" +send "$passwd\n" +#interact +expect eof +exit