Electron定制mac上的通知栏效果

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Electron定制mac上的通知栏效果相关的知识,希望对你有一定的参考价值。

参考技术A

在mac上, node-notifier 是通过调用封装好的 terminal-notifier 实现,虽然,通过提供的nodejs接口,我们可以传递通知消息的 title , message 等内容,但显示的图标和应用名称仍是 terminal-notifier 的。

我们需要重定制一个 terminal-notifier 的mac应用。

相关讨论: Issue #71 for more info

以上。

来自 Electron 的 M1 mac 上的 Emacs 崩溃

【中文标题】来自 Electron 的 M1 mac 上的 Emacs 崩溃【英文标题】:Crash Emacs on M1 mac from Electron 【发布时间】:2021-12-06 01:13:08 【问题描述】:

在“电子”上,当我尝试执行 Emacs 时 在新的 M1 mac 上使用 child_process.exec('Emacs'), 该过程已崩溃,并给出了下面所附的报告。 在旧的mac上,它可以工作。 代码如下:

exec(`/Applications/Emacs.app/Contents/MacOS/Emacs "$ExecPathEscape(dirPath)"' ...

我该如何解决?

“Emacs”是由“brew install cask emacs”安装的 和 'Electron' 由'npm install electron' 安装。

> node --version
v16.11.0
> emacs --version
GNU Emacs 27.2
Process:               Emacs-x86_64-10_14 [28673]
Path:                  /Applications/Emacs.app/Contents/MacOS/Emacs-x86_64-10_14
Identifier:            org.gnu.Emacs
Version:               Version 27.2 (9.0)
Code Type:             X86-64 (Translated)
Parent Process:        org_viewer_for_electron [28667]
Responsible:           org_viewer_for_electron [28667]
User ID:               501

Date/Time:             2021-10-16 14:52:14.719 +0900
OS Version:            macOS 11.6 (20G165)
Report Version:        12
Anonymous UUID:        85EA4D90-AA61-E019-08A5-82B0FB446187

Sleep/Wake UUID:       E05F8F97-4CFE-4F3E-A8EB-88E278C78BE3

Time Awake Since Boot: 22000 seconds
Time Since Wake:       210 seconds

System Integrity Protection: enabled

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_INSTRUCTION (SIGABRT)
Exception Codes:       0x0000000000000001, 0x0000000000000000
Exception Note:        EXC_CORPSE_NOTIFY

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   ???                             0x00007ffe946828f4 ???
1   libsystem_kernel.dylib          0x00007fff2042392e __pthread_kill + 10
2   libsystem_c.dylib               0x00007fff20336bd5 raise + 26
3   Emacs-x86_64-10_14              0x00000001023db6d9 terminate_due_to_signal + 153
4   Emacs-x86_64-10_14              0x00000001023dc01b emacs_abort + 15
5   Emacs-x86_64-10_14              0x00000001023a3880 ns_term_shutdown + 80
6   Emacs-x86_64-10_14              0x00000001022935d4 shut_down_emacs + 340
7   Emacs-x86_64-10_14              0x00000001023db6a6 terminate_due_to_signal + 102
8   Emacs-x86_64-10_14              0x00000001022b3e8e handle_fatal_signal + 14
9   Emacs-x86_64-10_14              0x00000001022b3f11 deliver_thread_signal + 129
10  Emacs-x86_64-10_14              0x00000001022b2969 deliver_fatal_thread_signal + 9
11  libsystem_platform.dylib        0x00007fff20497d7d _sigtramp + 29
12  ???                             000000000000000000 0 + 0
13  Emacs-x86_64-10_14              0x00000001023785c9 decode_time_components + 633
14  Emacs-x86_64-10_14              0x00000001023790df decode_lisp_time + 159
15  Emacs-x86_64-10_14              0x000000010237a240 Ftime_convert + 32
16  Emacs-x86_64-10_14              0x0000000102320331 funcall_subr + 257
17  Emacs-x86_64-10_14              0x000000010231f91b Ffuncall + 843
18  Emacs-x86_64-10_14              0x0000000102362c57 exec_byte_code + 1815
19  Emacs-x86_64-10_14              0x000000010231f8b9 Ffuncall + 745
20  Emacs-x86_64-10_14              0x0000000102362c57 exec_byte_code + 1815
21  Emacs-x86_64-10_14              0x000000010231f8b9 Ffuncall + 745
22  Emacs-x86_64-10_14              0x0000000102362c57 exec_byte_code + 1815
23  Emacs-x86_64-10_14              0x000000010231f8b9 Ffuncall + 745
24  Emacs-x86_64-10_14              0x0000000102362c57 exec_byte_code + 1815
25  Emacs-x86_64-10_14              0x000000010231f8b9 Ffuncall + 745
26  Emacs-x86_64-10_14              0x0000000102362c57 exec_byte_code + 1815
27  Emacs-x86_64-10_14              0x000000010231f8b9 Ffuncall + 745
28  Emacs-x86_64-10_14              0x0000000102362c57 exec_byte_code + 1815
29  Emacs-x86_64-10_14              0x000000010231f8b9 Ffuncall + 745
30  Emacs-x86_64-10_14              0x0000000102362c57 exec_byte_code + 1815
31  Emacs-x86_64-10_14              0x000000010231f8b9 Ffuncall + 745
32  Emacs-x86_64-10_14              0x000000010231ff8c call1 + 44
33  Emacs-x86_64-10_14              0x000000010232b4c8 mapcar1 + 88
34  Emacs-x86_64-10_14              0x000000010232b90b Fmapc + 75
35  Emacs-x86_64-10_14              0x0000000102320331 funcall_subr + 257
36  Emacs-x86_64-10_14              0x000000010231f91b Ffuncall + 843
37  Emacs-x86_64-10_14              0x0000000102362c57 exec_byte_code + 1815
38  Emacs-x86_64-10_14              0x000000010231f8b9 Ffuncall + 745
39  Emacs-x86_64-10_14              0x0000000102362c57 exec_byte_code + 1815
40  Emacs-x86_64-10_14              0x000000010231f164 apply_lambda + 356
41  Emacs-x86_64-10_14              0x000000010231b69f eval_sub + 783
42  Emacs-x86_64-10_14              0x000000010231ee9a Feval + 106
43  Emacs-x86_64-10_14              0x000000010231df77 internal_condition_case + 263
44  Emacs-x86_64-10_14              0x00000001022a772d top_level_1 + 45
45  Emacs-x86_64-10_14              0x000000010231d79b internal_catch + 267
46  Emacs-x86_64-10_14              0x00000001023dba96 command_loop.cold.1 + 54
47  Emacs-x86_64-10_14              0x0000000102296633 command_loop + 131
48  Emacs-x86_64-10_14              0x0000000102296563 recursive_edit_1 + 115
49  Emacs-x86_64-10_14              0x00000001022967bb Frecursive_edit + 347
50  Emacs-x86_64-10_14              0x000000010229534c main + 7436
51  libdyld.dylib                   0x00007fff2046df3d start + 1

Thread 1:: com.apple.rosetta.exceptionserver
0   runtime                         0x00007ffdfff96a28 0x7ffdfff92000 + 18984
1   runtime                         0x00007ffdfff9beec 0x7ffdfff92000 + 40684
2   runtime                         0x00007ffdfff9d2c0 0x7ffdfff92000 + 45760

Thread 2:
0   runtime                         0x00007ffdfffb47c8 0x7ffdfff92000 + 141256

Thread 3:
0   runtime                         0x00007ffdfffb47c8 0x7ffdfff92000 + 141256

Thread 4:
0   runtime                         0x00007ffdfffb47c8 0x7ffdfff92000 + 141256

Thread 5:
0   runtime                         0x00007ffdfffb47c8 0x7ffdfff92000 + 141256

Thread 6:
0   ???                             0x00007ffe946828f4 ???
1   libsystem_kernel.dylib          0x00007fff20425656 __select + 10
2   com.apple.Foundation            0x00007fff211fd437 __NSThread__start__ + 1068
3   libsystem_pthread.dylib         0x00007fff204528fc _pthread_start + 224
4   libsystem_pthread.dylib         0x00007fff2044e443 thread_start + 15

Thread 7:: com.apple.NSEventThread
0   ???                             0x00007ffe946828f4 ???
1   libsystem_kernel.dylib          0x00007fff2041d2ba mach_msg_trap + 10
2   com.apple.CoreFoundation        0x00007fff2054b215 __CFRunLoopServiceMachPort + 316
3   com.apple.CoreFoundation        0x00007fff205498cb __CFRunLoopRun + 1332
4   com.apple.CoreFoundation        0x00007fff20548cd0 CFRunLoopRunSpecific + 567
5   com.apple.AppKit                0x00007fff22e0223a _NSEventThread + 124
6   libsystem_pthread.dylib         0x00007fff204528fc _pthread_start + 224
7   libsystem_pthread.dylib         0x00007fff2044e443 thread_start + 15

Thread 0 crashed with X86 Thread State (64-bit):
 rax: 0x0000000000000000  rbx: 0x0000000202d57e00  rcx: 0x0000000000000000  rdx: 0x0000000000000000
 rdi: 0x0000000000000004  rsi: 0x0000000000000006  rbp: 0x0000000000000003  rsp: 0x00000000000001ad
  r8: 0x0000000000000006   r9: 0x0000000000000003  r10: 0x0000000202d57e00  r11: 0x00007fff20336bbb
 r12: 0x0000000000000103  r13: 0x0000000000000002  r14: 0x0000000000000006  r15: 0x0000000000000016
 rip: <unavailable>  rfl: 0x0000000000000283

【问题讨论】:

【参考方案1】:

我们自己解决了。 当我们直接符号链接 Emacs、bin、libexe 的 arm64 时, 它有效。

> pwd
/Applications/Emacs.app/Contents/MacOS
> rm bin
> ln -s bin-arm64-11_2/ bin
> rm libexec
> ln -s lib-arm64-11_2/ libexec
> mv Emacs Emacs-orig
> ln -s Emacs-arm64-11_2 Emacs

在 Homebrew 提供的原始 Emacs 脚本中, 架构检查由

> uname -m
arm64

并返回适当的答案, 但执行的版本是 x86_64。 我们不能提出修改后的 Emacs 解决方案,但它确实有效。

【讨论】:

我们现在已经了解到崩溃是由于“电子”架构造成的。当我们将“电子”从 x86_64 更改为通用版本时,“uname -m”会返回适当的答案。原来的 Emacs 运行良好。

以上是关于Electron定制mac上的通知栏效果的主要内容,如果未能解决你的问题,请参考以下文章

Android 10.0 原生SystemUI下拉通知栏UI背景设置为圆角背景的定制

electron——通知

electron——通知

在 Windows 平台上启用 Electron 应用通知的粘性行为

如何在 Mac 上为 Qt 设置徽章通知

电子应用程序通知仅显示在开发版本(非构建)