* 系统通知 * * > 通知参数: 同时支持 QuanX 和 Loon 两种格式, EnvJs根据运行环境自动转换, Surge 环境不支持多媒体通知 * * 示例: * $.msg(title, subt, desc, 'twitter://') * $.msg(title, subt, desc, { 'open-url': 'twitter://', 'media-url': 'https://github.githubassets.com/images/modules/open_graph/github-mark.png' }) * $.ms
(title = name, subt = '', desc = '', opts)
| 987 | * |
| 988 | */ |
| 989 | msg(title = name, subt = '', desc = '', opts) { |
| 990 | const toEnvOpts = (rawopts) => { |
| 991 | if (!rawopts) return rawopts |
| 992 | if (typeof rawopts === 'string') { |
| 993 | if (this.isLoon()) return rawopts |
| 994 | else if (this.isQuanX()) return { |
| 995 | 'open-url': rawopts |
| 996 | } |
| 997 | else if (this.isSurge()) return { |
| 998 | url: rawopts |
| 999 | } |
| 1000 | else return undefined |
| 1001 | } else if (typeof rawopts === 'object') { |
| 1002 | if (this.isLoon()) { |
| 1003 | let openUrl = rawopts.openUrl || rawopts.url || rawopts['open-url'] |
| 1004 | let mediaUrl = rawopts.mediaUrl || rawopts['media-url'] |
| 1005 | return { |
| 1006 | openUrl, |
| 1007 | mediaUrl |
| 1008 | } |
| 1009 | } else if (this.isQuanX()) { |
| 1010 | let openUrl = rawopts['open-url'] || rawopts.url || rawopts.openUrl |
| 1011 | let mediaUrl = rawopts['media-url'] || rawopts.mediaUrl |
| 1012 | return { |
| 1013 | 'open-url': openUrl, |
| 1014 | 'media-url': mediaUrl |
| 1015 | } |
| 1016 | } else if (this.isSurge()) { |
| 1017 | let openUrl = rawopts.url || rawopts.openUrl || rawopts['open-url'] |
| 1018 | return { |
| 1019 | url: openUrl |
| 1020 | } |
| 1021 | } |
| 1022 | } else { |
| 1023 | return undefined |
| 1024 | } |
| 1025 | } |
| 1026 | if (!this.isMute) { |
| 1027 | if (this.isSurge() || this.isLoon()) { |
| 1028 | $notification.post(title, subt, desc, toEnvOpts(opts)) |
| 1029 | } else if (this.isQuanX()) { |
| 1030 | $notify(title, subt, desc, toEnvOpts(opts)) |
| 1031 | } |
| 1032 | } |
| 1033 | if (!this.isMuteLog) { |
| 1034 | let logs = ['', '==============📣系统通知📣=============='] |
| 1035 | logs.push(title) |
| 1036 | subt ? logs.push(subt) : '' |
| 1037 | desc ? logs.push(desc) : '' |
| 1038 | console.log(logs.join('\n')) |
| 1039 | this.logs = this.logs.concat(logs) |
| 1040 | } |
| 1041 | } |
| 1042 | |
| 1043 | log(...logs) { |
| 1044 | if (logs.length > 0) { |