* 系统通知 * * > 通知参数: 同时支持 QuanX 和 Loon 两种格式, EnvJs根据运行环境自动转换 * * 示例: * $.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' }) * $.msg(title, subt, des
(title = this.name, subt = '', desc = '', opts = {})
| 388 | * |
| 389 | */ |
| 390 | msg(title = this.name, subt = '', desc = '', opts = {}) { |
| 391 | const toEnvOpts = (rawopts) => { |
| 392 | const { $open, $copy, $media, $mediaMime } = rawopts |
| 393 | switch (typeof rawopts) { |
| 394 | case undefined: |
| 395 | return rawopts |
| 396 | case 'string': |
| 397 | switch (this.platform()) { |
| 398 | case 'Surge': |
| 399 | case 'Stash': |
| 400 | case 'Egern': |
| 401 | default: |
| 402 | return { url: rawopts } |
| 403 | case 'Loon': |
| 404 | case 'Shadowrocket': |
| 405 | return rawopts |
| 406 | case 'Quantumult X': |
| 407 | return { 'open-url': rawopts } |
| 408 | } |
| 409 | case 'object': |
| 410 | switch (this.platform()) { |
| 411 | case 'Surge': |
| 412 | case 'Stash': |
| 413 | case 'Egern': |
| 414 | case 'Shadowrocket': |
| 415 | default: { |
| 416 | const options = {} |
| 417 | |
| 418 | // 打开URL |
| 419 | let openUrl = |
| 420 | rawopts.openUrl || rawopts.url || rawopts['open-url'] || $open |
| 421 | if (openUrl) |
| 422 | Object.assign(options, { action: 'open-url', url: openUrl }) |
| 423 | |
| 424 | // 粘贴板 |
| 425 | let copy = |
| 426 | rawopts['update-pasteboard'] || |
| 427 | rawopts.updatePasteboard || |
| 428 | $copy |
| 429 | if (copy) { |
| 430 | Object.assign(options, { action: 'clipboard', text: copy }) |
| 431 | } |
| 432 | |
| 433 | // 图片通知 |
| 434 | let mediaUrl = rawopts.mediaUrl || rawopts['media-url'] || $media |
| 435 | if (mediaUrl) { |
| 436 | let media = undefined |
| 437 | let mime = undefined |
| 438 | // http 开头的网络地址 |
| 439 | if (mediaUrl.startsWith('http')) { |
| 440 | //不做任何操作 |
| 441 | } |
| 442 | // 带标识的 Base64 字符串 |
| 443 | // data:image/png;base64,iVBORw0KGgo... |
| 444 | else if (mediaUrl.startsWith('data:')) { |
| 445 | const [data] = mediaUrl.split(';') |
| 446 | const [, base64str] = mediaUrl.split(',') |
| 447 | media = base64str |