@@ -100,6 +100,7 @@ App.addInitializer(function (options) {
100100
101101 var width = parseInt ( localStorage . width ? localStorage . width : Settings . defaultWidth ) ;
102102 var height = parseInt ( localStorage . height ? localStorage . height : Settings . defaultHeight ) ;
103+ var isMaximized = Boolean ( parseInt ( localStorage . isMaximized ) ) ;
103104 var x = parseInt ( localStorage . posX ? localStorage . posX : - 1 ) ;
104105 var y = parseInt ( localStorage . posY ? localStorage . posY : - 1 ) ;
105106
@@ -128,8 +129,13 @@ App.addInitializer(function (options) {
128129 }
129130
130131 win . zoomLevel = zoom ;
131- win . resizeTo ( width , height ) ;
132- win . moveTo ( x , y ) ;
132+
133+ if ( isMaximized ) {
134+ win . maximize ( ) ;
135+ } else {
136+ win . resizeTo ( width , height ) ;
137+ win . moveTo ( x , y ) ;
138+ }
133139} ) ;
134140
135141var initTemplates = function ( ) {
@@ -152,7 +158,9 @@ var initApp = function () {
152158 var mainWindow = new App . View . MainWindow ( ) ;
153159
154160 // -m argument to open minimized to tray
155- if ( nw . App . fullArgv . indexOf ( '-m' ) === - 1 ) {
161+ var isStartMinimized = nw . App . fullArgv . indexOf ( '-m' ) !== - 1 ;
162+
163+ if ( ! isStartMinimized ) {
156164 win . show ( ) ;
157165 }
158166
@@ -213,35 +221,6 @@ var delCache = function () {
213221 win . close ( true ) ;
214222} ;
215223
216- win . on ( 'resize' , function ( width , height ) {
217- localStorage . width = Math . round ( width ) ;
218- localStorage . height = Math . round ( height ) ;
219- } ) ;
220-
221- win . on ( 'move' , function ( x , y ) {
222- localStorage . posX = Math . round ( x ) ;
223- localStorage . posY = Math . round ( y ) ;
224- } ) ;
225-
226- win . on ( 'enter-fullscreen' , function ( ) {
227- App . vent . trigger ( 'window:focus' ) ;
228- } ) ;
229-
230- // Wipe the tmpFolder when closing the app (this frees up disk space)
231- win . on ( 'close' , function ( ) {
232- if ( App . settings . deleteTmpOnClose ) {
233- deleteFolder ( App . settings . tmpLocation ) ;
234- }
235- if ( fs . existsSync ( path . join ( data_path , 'logs.txt' ) ) ) {
236- fs . unlinkSync ( path . join ( data_path , 'logs.txt' ) ) ;
237- }
238- try {
239- delCache ( ) ;
240- } catch ( e ) {
241- win . close ( true ) ;
242- }
243- } ) ;
244-
245224String . prototype . capitalize = function ( ) {
246225 return this . charAt ( 0 ) . toUpperCase ( ) + this . slice ( 1 ) ;
247226} ;
@@ -656,6 +635,60 @@ if (nw.App.fullArgv.indexOf('-f') !== -1) {
656635 win . enterFullscreen ( ) ;
657636}
658637
638+ // nwjs window events
639+ win . on ( 'focus' , function ( ) { //hack to make it somehow work
640+ win . setAlwaysOnTop ( true ) ;
641+ win . setAlwaysOnTop ( Settings . alwaysOnTop ) ;
642+ } ) ;
643+
644+ win . on ( 'resize' , function ( width , height ) {
645+ localStorage . width = Math . round ( width ) ;
646+ localStorage . height = Math . round ( height ) ;
647+ } ) ;
648+
649+ win . on ( 'move' , function ( x , y ) {
650+ localStorage . posX = Math . round ( x ) ;
651+ localStorage . posY = Math . round ( y ) ;
652+ } ) ;
653+
654+ win . on ( 'enter-fullscreen' , function ( ) {
655+ win . focus ( ) ;
656+ } ) ;
657+
658+ win . on ( 'minimize' , function ( ) {
659+ if ( Settings . minimizeToTray ) {
660+ minimizeToTray ( ) ;
661+ }
662+ } ) ;
663+
664+ win . on ( 'maximize' , function ( ) {
665+ localStorage . isMaximized = 1 ;
666+ $ ( '.os-max' ) . addClass ( 'os-is-max' ) ;
667+ } ) ;
668+
669+ win . on ( 'restore' , function ( ) {
670+ if ( Boolean ( parseInt ( localStorage . isMaximized ) ) ) {
671+ localStorage . isMaximized = 0 ;
672+ }
673+
674+ $ ( '.os-max' ) . removeClass ( 'os-is-max' ) ;
675+ } ) ;
676+
677+ // Wipe the tmpFolder when closing the app (this frees up disk space)
678+ win . on ( 'close' , function ( ) {
679+ if ( App . settings . deleteTmpOnClose ) {
680+ deleteFolder ( App . settings . tmpLocation ) ;
681+ }
682+ if ( fs . existsSync ( path . join ( data_path , 'logs.txt' ) ) ) {
683+ fs . unlinkSync ( path . join ( data_path , 'logs.txt' ) ) ;
684+ }
685+ try {
686+ delCache ( ) ;
687+ } catch ( e ) {
688+ win . close ( true ) ;
689+ }
690+ } ) ;
691+
659692nw . App . on ( 'open' , function ( cmd ) {
660693 var file ;
661694 if ( os . platform ( ) === 'win32' ) {
@@ -682,19 +715,6 @@ nw.App.on('open', function (cmd) {
682715 }
683716} ) ;
684717
685- win . on ( 'minimize' , function ( ) {
686- if ( Settings . minimizeToTray ) {
687- minimizeToTray ( ) ;
688- }
689- } ) ;
690-
691- // When win.focus() doesn't do it's job right, play dirty.
692- App . vent . on ( 'window:focus' , function ( ) {
693- win . setAlwaysOnTop ( true ) ;
694- win . focus ( ) ;
695- win . setAlwaysOnTop ( Settings . alwaysOnTop ) ;
696- } ) ;
697-
698718// On uncaught exceptions, log to console.
699719process . on ( 'uncaughtException' , function ( err ) {
700720 try {
0 commit comments