@@ -52,6 +52,11 @@ const globalShortcut = window.require('electron').remote.globalShortcut;
5252
5353const noIMG = require ( './assets/img/NO-IMAGE.jpg' ) ;
5454
55+ const { Menu, MenuItem } = window . require ( 'electron' ) . remote
56+ //const menu = new Menu();
57+ const menu = Menu . getApplicationMenu ( ) ;
58+ console . log ( 'menu:' , menu ) ;
59+
5560class ViewA extends React . Component {
5661 constructor ( props ) {
5762 super ( props ) ;
@@ -62,7 +67,7 @@ class ViewA extends React.Component {
6267 name : '' ,
6368 active : '' ,
6469 id : 1 ,
65- workSpaces : { } ,
70+ workSpaces : [ ] ,
6671 images : { } ,
6772 res : [ 0 , 0 ]
6873 }
@@ -72,21 +77,15 @@ class ViewA extends React.Component {
7277 let workspacesStore = store . get ( 'workspaces' ) ;
7378 let imagesStore = store . get ( 'images' ) ;
7479 if ( typeof ( workspacesStore ) !== 'undefined' ) {
75- for ( let w in workspacesStore ) {
76- workspacesStore [ w ] = 0 ;
77- }
80+ workspacesStore . map ( w => {
81+ w . id = 0 ;
82+ } ) ;
7883 this . setState ( { workSpaces : workspacesStore } ) ;
7984 }
8085 if ( typeof ( imagesStore ) !== 'undefined' ) {
8186 this . setState ( { images : imagesStore } )
8287 }
83- var i = 1 ;
84- for ( let w in workspacesStore ) {
85- globalShortcut . register ( 'CommandOrControl+' + i , ( ) => {
86- this . openWorkSpace ( w )
87- } )
88- i ++ ;
89- }
88+
9089 }
9190
9291 componentDidMount = ( ) => {
@@ -97,21 +96,54 @@ class ViewA extends React.Component {
9796 console . log ( arg [ 0 ] ) ;
9897 console . log ( arg ) ;
9998 } ) ;
100-
10199
102100 }
103101
104102 componentWillUnmount = ( ) => {
105103 ipc . removeAllListeners ( ) ;
106104 globalShortcut . unregisterAll ( ) ;
107- alert ( 'unmount' )
108105 }
109106
110107
111108 workspacesShortcut = ( quantity ) => {
112109
113110 }
114111
112+ /* WORKSPACES */
113+
114+ getIndexByName = ( name ) => {
115+
116+ if ( typeof name !== 'undefined' ) {
117+ var output = this . state . workSpaces . filter (
118+ ( workSpaces ) => {
119+ return workSpaces . name === name ;
120+ }
121+ ) ;
122+ return output . length > 0 ? this . state . workSpaces . indexOf ( output [ 0 ] ) : - 1 ;
123+ } else {
124+ return - 1 ;
125+ }
126+ }
127+ getWorkspaceByName = ( name ) => {
128+ if ( typeof name !== 'undefined' ) {
129+ var output = this . state . workSpaces . filter (
130+ ( workSpaces ) => {
131+ return workSpaces . name === name ;
132+ }
133+ ) ;
134+ return output . length > 0 ? output [ 0 ] : - 1 ;
135+ } else {
136+ return - 1 ;
137+ }
138+ }
139+
140+ getWorkspaceByIndex = ( index ) => {
141+ var workspace = this . state . workSpaces [ index ] ;
142+ return typeof workspace === 'undefined' ? - 1 : this . state . workSpaces [ index ] ;
143+ }
144+
145+ /* WORKSPACES */
146+
115147 /* Get 1st JSON object */
116148 first = ( state ) => {
117149 var i = 0 ;
@@ -138,11 +170,12 @@ class ViewA extends React.Component {
138170
139171 openWorkSpace = ( workSpace ) => {
140172 var test = BrowserWindow . getAllWindows ( ) [ 0 ] ;
141- let view = BrowserView . fromId ( this . state . workSpaces [ workSpace ] ) ;
173+ var workspace = this . getWorkspaceByName ( workSpace ) ;
174+ let view = BrowserView . fromId ( workspace . id ) ;
142175 if ( view ) {
143176 test . setBrowserView ( view ) ;
144177 view . setBounds ( { x : 73 , y : 0 , width : test . getSize ( ) [ 0 ] - 73 , height : test . getSize ( ) [ 1 ] - 26 } ) ;
145- view . webContents . openDevTools ( ) ;
178+ isDev ? view . webContents . openDevTools ( ) : console . log ( 'Production mode' ) ;
146179 this . setActive ( workSpace ) ;
147180 } else {
148181 let view = new BrowserView ( {
@@ -166,7 +199,8 @@ class ViewA extends React.Component {
166199 view . setAutoResize ( { width :true , height : true } ) ;
167200
168201 var woorkspaces = this . state . workSpaces ;
169- woorkspaces [ workSpace ] = view . id ;
202+ var woorkspacesIndex = this . getIndexByName ( workspace . name ) ;
203+ woorkspaces [ woorkspacesIndex ] . id = view . id ;
170204 this . setState ( { workSpaces :woorkspaces } ) ;
171205
172206 store . set ( 'workspaces' , woorkspaces ) ;
@@ -200,24 +234,29 @@ class ViewA extends React.Component {
200234 var workspaces = this . state . workSpaces ;
201235
202236 // Check workspace already exists
203- if ( typeof workspaces [ name ] !== 'undefined' ) {
237+ if ( this . getIndexByName ( name ) !== - 1 ) {
204238 alert ( 'The name of this workspace already exists.' )
205239 } else {
206240
207241 this . setImage ( this . state . name ) ;
208-
209- workspaces [ this . state . name ] = 0 ;
242+ workspaces . push ( { name : this . state . name , id : 0 } )
210243 this . setState ( { workspaces : workspaces } ) ;
211244
212245 store . set ( 'workspaces' , workspaces ) ;
213-
246+
214247 let window = BrowserWindow . getAllWindows ( ) [ 0 ] ;
215248 window . setBrowserView ( null ) ;
216249 this . handleClose ( 'create' ) ;
217250 this . openWorkSpace ( this . state . name ) ;
251+
218252 }
219253 }
220254 }
255+
256+ modifyMenuWorkspaces = ( ) => {
257+ var workspaceItems = menu . items [ 5 ] . submenu . items ;
258+ }
259+
221260 /* ADD WORKSPACE */
222261
223262 /* DIALOG */
@@ -234,7 +273,8 @@ class ViewA extends React.Component {
234273 if ( type === 'close' ) {
235274
236275 if ( this . state . active !== '' ) {
237- var view = BrowserView . fromId ( this . state . workSpaces [ this . state . active ] ) ;
276+ var workspace = this . getWorkspaceByName ( this . state . active ) ;
277+ var view = BrowserView . fromId ( workspace . id ) ;
238278 let window = BrowserWindow . getAllWindows ( ) [ 0 ] ;
239279 window . setBrowserView ( view ) ;
240280 }
@@ -256,30 +296,27 @@ class ViewA extends React.Component {
256296
257297 _renderWorkspaces = ( ) => {
258298 let children = [ ] ;
259- console . log ( 'plataforma: ' , remote . process . platform ) ;
260299 var text = remote . process . platform === 'darwin' ? 'cmd' : 'ctrl' ;
261300 var i = 1 ;
262- globalShortcut . unregisterAll ( ) ;
263- for ( let workspace in this . state . workSpaces ) {
301+
302+ this . state . workSpaces . map ( workspace => {
264303 children . push (
265- < ListItem className = "bttn" key = { workspace } >
304+ < ListItem className = "bttn" key = { workspace . name } >
266305 { /*<span style={{borderLeft: this.activeColor(workspace) === 1 ? '1px dotted white' : 'none'}}></span>*/ }
267- < div style = { { backgroundImage : 'red' , borderRadius : 8 , borderLeft : this . activeColor ( workspace ) === 1 ? '3px solid #FF9735' : 'none' , textAlign :'center' , width : this . activeColor ( workspace ) === 1 ? '69px' : '72px' } } >
268- < a onClick = { ( ) => { this . openWorkSpace ( workspace ) } } href = "#/" style = { { marginLeft : this . activeColor ( workspace ) === 1 ? '-8px!important' : 'none' } } >
269- < Tooltip title = { workspace } enterDelay = { 700 } leaveDelay = { 200 } placement = "bottom" >
270- < img style = { { opacity :this . activeColor ( workspace ) , backgroundColor :'#FFFFFF' } } alt = { workspace } className = "workspace-img" src = { this . getImageBase64 ( workspace ) } />
306+ < div style = { { backgroundImage : 'red' , borderRadius : 8 , borderLeft : this . activeColor ( workspace . name ) === 1 ? '3px solid #FF9735' : 'none' , textAlign :'center' , width : this . activeColor ( workspace . name ) === 1 ? '69px' : '72px' } } >
307+ < a onClick = { ( ) => { this . openWorkSpace ( workspace . name ) } } href = "#/" style = { { marginLeft : this . activeColor ( workspace . name ) === 1 ? '-8px!important' : 'none' } } >
308+ < Tooltip title = { workspace . name } enterDelay = { 700 } leaveDelay = { 200 } placement = "bottom" >
309+ < img style = { { opacity :this . activeColor ( workspace . name ) , backgroundColor :'#FFFFFF' } } alt = { workspace . name } className = "workspace-img" src = { this . getImageBase64 ( workspace . name ) } />
271310 { /*this.getImageBase64(workspace)*/ }
272311 </ Tooltip >
273312 </ a >
274313 </ div >
275314 < ListItemText className = "secondary" secondary = { `${ text } +${ i } ` } style = { { color : 'red' , textAlign : 'center' } } />
276315 </ ListItem >
277316 ) ;
278- globalShortcut . register ( 'CommandOrControl+' + i , ( ) => {
279- this . openWorkSpace ( workspace )
280- } )
281317 i ++ ;
282- } ;
318+
319+ } ) ;
283320 return children ;
284321 }
285322
0 commit comments