@@ -13,6 +13,15 @@ declare global {
13
13
setBackgroundColor ?: ( color : string ) => void ;
14
14
} ;
15
15
} ;
16
+ macPermissions ?: {
17
+ overlayMode : {
18
+ checkSupport : ( ) => Promise < { supported : boolean ; platform ?: string ; reason ?: string ; error ?: string } > ;
19
+ setAlwaysOnTop : ( flag : boolean , level ?: string ) => Promise < { success : boolean ; alwaysOnTop ?: boolean ; error ?: string } > ;
20
+ setOpacity : ( opacity : number ) => Promise < { success : boolean ; opacity ?: number ; error ?: string } > ;
21
+ getOpacity : ( ) => Promise < { success : boolean ; opacity ?: number ; error ?: string } > ;
22
+ setBackgroundColor : ( color : string ) => Promise < { success : boolean ; color ?: string ; error ?: string } > ;
23
+ } ;
24
+ } ;
16
25
}
17
26
}
18
27
@@ -22,7 +31,21 @@ export function useOverlayMode() {
22
31
let previousTheme : string | null = null ;
23
32
24
33
// Check if overlay mode is supported
25
- const checkSupport = ( ) => {
34
+ const checkSupport = async ( ) => {
35
+ // First try IPC method
36
+ if ( window . macPermissions ?. overlayMode ) {
37
+ try {
38
+ const result = await window . macPermissions . overlayMode . checkSupport ( ) ;
39
+ if ( result . supported ) {
40
+ isSupported . value = true ;
41
+ return true ;
42
+ }
43
+ } catch ( error ) {
44
+ console . error ( 'Error checking overlay mode support via IPC:' , error ) ;
45
+ }
46
+ }
47
+
48
+ // Fallback to window.remote for backward compatibility
26
49
try {
27
50
if ( window . remote && typeof window . remote . getCurrentWindow === 'function' ) {
28
51
const currentWindow = window . remote . getCurrentWindow ( ) ;
@@ -49,46 +72,53 @@ export function useOverlayMode() {
49
72
} ;
50
73
51
74
// Toggle overlay mode
52
- const toggleOverlayMode = ( ) => {
75
+ const toggleOverlayMode = async ( ) => {
53
76
if ( ! isSupported . value ) {
54
77
return false ;
55
78
}
56
79
57
80
const newState = ! isOverlayMode . value ;
58
81
59
82
try {
60
- const currentWindow = window . remote ! . getCurrentWindow ( ) ;
61
-
62
83
if ( newState ) {
63
84
// Enable overlay mode
64
- currentWindow . setAlwaysOnTop ( true , 'floating' ) ;
65
-
66
- // Set transparent background for overlay mode
67
- if ( typeof currentWindow . setBackgroundColor === 'function' ) {
68
- currentWindow . setBackgroundColor ( '#00000000' ) ;
69
- }
70
-
71
- // Set window opacity for overlay mode visibility
72
- if ( typeof currentWindow . setOpacity === 'function' ) {
73
- currentWindow . setOpacity ( 0.8 ) ; // 80% opacity for more transparency
85
+ if ( window . macPermissions ?. overlayMode ) {
86
+ // Use IPC methods
87
+ await window . macPermissions . overlayMode . setAlwaysOnTop ( true , 'floating' ) ;
88
+ await window . macPermissions . overlayMode . setBackgroundColor ( '#00000000' ) ;
89
+ await window . macPermissions . overlayMode . setOpacity ( 0.8 ) ;
90
+ } else if ( window . remote ) {
91
+ // Fallback to window.remote
92
+ const currentWindow = window . remote . getCurrentWindow ( ) ;
93
+ currentWindow . setAlwaysOnTop ( true , 'floating' ) ;
94
+ if ( typeof currentWindow . setBackgroundColor === 'function' ) {
95
+ currentWindow . setBackgroundColor ( '#00000000' ) ;
96
+ }
97
+ if ( typeof currentWindow . setOpacity === 'function' ) {
98
+ currentWindow . setOpacity ( 0.8 ) ;
99
+ }
74
100
}
75
101
76
102
// Save current theme and force dark mode
77
103
previousTheme = localStorage . getItem ( 'appearance' ) ;
78
104
updateTheme ( 'dark' ) ;
79
105
} else {
80
106
// Disable overlay mode
81
- currentWindow . setAlwaysOnTop ( false ) ;
82
-
83
- // Restore opaque background
84
- if ( typeof currentWindow . setBackgroundColor === 'function' ) {
85
- // Set opaque background to match the app
86
- currentWindow . setBackgroundColor ( '#f5f7fa' ) ;
87
- }
88
-
89
- // Restore full window opacity
90
- if ( typeof currentWindow . setOpacity === 'function' ) {
91
- currentWindow . setOpacity ( 1 ) ; // Full opacity for normal mode
107
+ if ( window . macPermissions ?. overlayMode ) {
108
+ // Use IPC methods
109
+ await window . macPermissions . overlayMode . setAlwaysOnTop ( false ) ;
110
+ await window . macPermissions . overlayMode . setBackgroundColor ( '#f5f7fa' ) ;
111
+ await window . macPermissions . overlayMode . setOpacity ( 1 ) ;
112
+ } else if ( window . remote ) {
113
+ // Fallback to window.remote
114
+ const currentWindow = window . remote . getCurrentWindow ( ) ;
115
+ currentWindow . setAlwaysOnTop ( false ) ;
116
+ if ( typeof currentWindow . setBackgroundColor === 'function' ) {
117
+ currentWindow . setBackgroundColor ( '#f5f7fa' ) ;
118
+ }
119
+ if ( typeof currentWindow . setOpacity === 'function' ) {
120
+ currentWindow . setOpacity ( 1 ) ;
121
+ }
92
122
}
93
123
94
124
// Restore previous theme
@@ -110,7 +140,8 @@ export function useOverlayMode() {
110
140
) ;
111
141
112
142
return true ;
113
- } catch {
143
+ } catch ( error ) {
144
+ console . error ( 'Error toggling overlay mode:' , error ) ;
114
145
return false ;
115
146
}
116
147
} ;
@@ -136,17 +167,21 @@ export function useOverlayMode() {
136
167
137
168
// Initialize
138
169
onMounted ( ( ) => {
139
- setTimeout ( ( ) => {
140
- if ( checkSupport ( ) ) {
170
+ setTimeout ( async ( ) => {
171
+ if ( await checkSupport ( ) ) {
141
172
const savedPreference = loadPreference ( ) ;
142
173
if ( savedPreference ) {
143
- enableOverlayMode ( ) ;
174
+ await enableOverlayMode ( ) ;
144
175
} else {
145
176
// Ensure normal mode has opaque background on startup
146
177
try {
147
- const currentWindow = window . remote ! . getCurrentWindow ( ) ;
148
- if ( typeof currentWindow . setBackgroundColor === 'function' ) {
149
- currentWindow . setBackgroundColor ( '#f5f7fa' ) ;
178
+ if ( window . macPermissions ?. overlayMode ) {
179
+ await window . macPermissions . overlayMode . setBackgroundColor ( '#f5f7fa' ) ;
180
+ } else if ( window . remote ) {
181
+ const currentWindow = window . remote . getCurrentWindow ( ) ;
182
+ if ( typeof currentWindow . setBackgroundColor === 'function' ) {
183
+ currentWindow . setBackgroundColor ( '#f5f7fa' ) ;
184
+ }
150
185
}
151
186
} catch { }
152
187
}
0 commit comments