scriptcat icon indicating copy to clipboard operation
scriptcat copied to clipboard

[重构]一些代码重构记录

Open CodFrm opened this issue 3 years ago • 4 comments

之前eslint配置错误,现在修复后代码大片大片的红。。。。。这种eslint的错误就看一个处理一个吧,太多了😭。

然后一些设计的地方也比较乱,期望进行整理,记录如下

消息中心重构

此处将sendResponse删除,将返回值作为send内容,undefined不进行发送,另外对其他发消息的代码进行整理:apps/Manager::listenerMessage 主要是规范好 Promise的返回值 <any> 表示将发送数据 <void> 表示将由方法自己发送数据

export type MessageCallback = (body: any, sendResponse: (response?: any) => void, sender?: chrome.runtime.MessageSender) => Promise<any> | any;

    // 监听msg操作的只能有一个
    public static listenerMessage(topic: string, callback: MessageCallback) {
        const val = new Map();
        topicMap.set(topic, val);
        val.set(callback, (msg: any, port: chrome.runtime.Port) => {
            callback(msg, (resp) => { port.postMessage(resp) }, port.sender);
        });
    }

后台grant通信

一些油猴的API通信方式优化一下,主要是postMessage,让返回值/resolve也支持返回

export type Api = (grant: Grant, postMessage: IPostMessage, script?: Script) => Promise<any> | any;

资源释放

支持资源释放freed

// 资源释放,后台脚本只有脚本id,当窗口是关闭而不是刷新时windowClose为true
// TODO: 实现脚本id
export type FreedCallback = (id: number, tabId?: number, windowClose?: boolean) => void;

GM_registerMenuCommand优化

将释放的逻辑放到freed中,获取和点击的逻辑放到listener中,删除 ScriptManager::listenScriptMath 中的相关逻辑

CodFrm avatar Jan 03 '22 14:01 CodFrm

  • [x] 新建脚本页面URL识别
  • [x] 暴力猴导出的zip包无法正常导入
  • [x] 静默更新
  • [x] 无meta.js的更新(看看tm怎么做的)
  • [x] 订阅文档优化
  • [x] 密码找回
  • [x] 登录框框优化

1.批量操作的更新无效 2.手动新建的脚本,无法更新,必须安装脚本才能识别updateurl 3.popup.html 版本显示问题 4.忽略一次弹框,下一次弹框会卡住很久 5.订阅好像也有点问题。。。

不能修改和保存订阅

CodFrm avatar Jan 11 '22 10:01 CodFrm

CodFrm avatar Feb 03 '22 12:02 CodFrm

脚本不兼容

https://greasyfork.org/scripts/411837

CodFrm avatar Feb 26 '22 04:02 CodFrm

AX@8_4QW4)_R$AL0E{(R2UE

群友反馈记录

CodFrm avatar Mar 09 '22 08:03 CodFrm