File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -70,6 +70,11 @@ class HeaderToolbar extends Toolbar {
7070 ntype : 'component' ,
7171 cls : [ 'header-spacer' ] ,
7272 flex : 1
73+ } , {
74+ handler : 'onEnableWindowManagementClick' ,
75+ iconCls : 'fa fa-window-restore' ,
76+ reference : 'window-management-button' ,
77+ text : 'Enable Window Management'
7378 } , {
7479 handler : 'onDetachGridButtonClick' ,
7580 iconCls : 'fas fa-table' ,
Original file line number Diff line number Diff line change @@ -193,6 +193,24 @@ class ViewportController extends Controller {
193193 await this . createBrowserWindow ( 'pie-chart' )
194194 }
195195
196+ /**
197+ * @param {Object } data
198+ */
199+ async onEnableWindowManagementClick ( data ) {
200+ let me = this ,
201+ response = await Neo . main . addon . DragDrop . requestWindowManagementPermission ( ) ,
202+ button = me . getReference ( 'window-management-button' ) ;
203+
204+ if ( response . success ) {
205+ button . text = 'W-M enabled' ;
206+ button . iconCls = 'fa fa-check-square' ;
207+ button . disabled = true ;
208+ } else {
209+ button . text = 'W-M disabled' ;
210+ button . iconCls = 'fa fa-exclamation-triangle' ;
211+ }
212+ }
213+
196214 /**
197215 * @param {Object } data
198216 */
Original file line number Diff line number Diff line change @@ -110,6 +110,7 @@ class DragDrop extends Base {
110110 */
111111 remote : {
112112 app : [
113+ 'requestWindowManagementPermission' ,
113114 'setConfigs' ,
114115 'setDragProxyElement'
115116 ]
@@ -411,6 +412,25 @@ class DragDrop extends Base {
411412 return false
412413 }
413414
415+ /**
416+ * @returns {Promise<Object> }
417+ */
418+ async requestWindowManagementPermission ( ) {
419+ if ( ! window . isSecureContext || ! ( 'getScreenDetails' in window ) ) {
420+ return { success : false , error : 'The Window Management API requires a secure context (HTTPS or localhost) and is not supported by this browser.' } ;
421+ }
422+
423+ try {
424+ await window . getScreenDetails ( ) ;
425+ return { success : true } ;
426+ } catch ( err ) {
427+ if ( err . name === 'PermissionDeniedError' ) {
428+ return { success : false , error : 'Permission to manage windows was denied.' } ;
429+ }
430+ return { success : false , error : `An unknown error occurred: ${ err . message } ` } ;
431+ }
432+ }
433+
414434 /**
415435 * @param {Object } data
416436 * @param {Number } data.clientX
You can’t perform that action at this time.
0 commit comments