应用程序开发公司
软件开发

针对您的项目需求及预算规划量身制定方案

个体/中小企业/集团/政府机构/行业组织 了解详情 了解详情

chemzqm:文件保存后自动刷新微信小程序

发布时间:2024-01-01 00:00 浏览次数:45

作者的话:


我辨认出这个方法存有副作用,就是别的应用领域也可能将存有登记注册这个全局快捷键,所以我研发了 https://github.com/chemzqm/wept


正文部分:


微信开发者工具积极支持创下和扩建的快捷键,所以我们可以传送一段 apple script 脚本去达至创下/扩建项目的效果,从而免职手工转换再采用快捷键的麻烦。比如:


tell application "wechatwebdevtools"


activate


delay 0.2


tell application "System Events"


key code {55, 15}


end tell


end tell


这段代码可以采用命令 osascript 继续执行,效果就是著眼微信开发者工具,然后传送 Command + R 刷新界面。


这里的问题就是我们还是须要每次创下都必须转换至微信开发者工具界面,这对于研发的简洁度还是存有影响的。


一个直观的解决办法就是修正开发者工具源码,使它积极支持全局快捷键,经过一番搜寻,找出了文件:


/Applications/wechatwebdevtools.app/Contents/Resources/app.nw/app/dist/common/menu/menu.js,


嵌入代码:


function registShortcut(key, onactive) {


var option = {


key : key,


active : onactive,


failed : function(msg) {


// :(, fail to register the |key| or couldn't parse the |key|.


console.log(msg);


}


};


// Create a shortcut with |option|.


var shortcut = new nw.Shortcut(option);


// Register global desktop shortcut, which can work without focus.


nw.App.registerGlobalHotKey(shortcut);


}


以及


registShortcut("Command+Shift+R", function () {


e.reload()


})


registShortcut("Command+Shift+B", function () {


e.reBuild()


})


至 init 函数下面就可以使开发者工具积极支持全局创下的热键了(Command+Shift+R 和 Command+Shift+B),


完备文件浏览


然后只须要使 vim 留存 wxss 和 wxml 文件后传送快捷键就可以了。采用一键加装命令:


curl https://raw.githubusercontent.com/chemzqm/vim-macos/master/autoload/macos.vim > ~/.vim/autoload/macos.vim


加装 vim-macos 插件, 然后在 ~/.vimrc 中布局:


autocmd BufWritePost *.wxml call macos#keycodes('command', 'shift', 'r')


autocmd BufWritePost *.wxss call macos#keycodes('command', 'shift', 'r')

TAG标签:
阅读推荐