@@ -38,14 +38,14 @@ function openTutorial() {
3838*/
3939function setTray ( ) {
4040 // Tray menu is only available in window mode
41- if ( NL_MODE != "window" ) {
41+ if ( typeof NL_MODE === "undefined" || NL_MODE != "window" ) {
4242 console . log ( "INFO: Tray menu is only available in the window mode." ) ;
4343 return ;
4444 }
4545
4646 // Define tray menu items
4747 let tray = {
48- icon : "/resources/icons/trayIcon.png " ,
48+ icon : "/resources/assets/icon.jpg " ,
4949 menuItems : [
5050 { id : "VERSION" , text : "Get version" } ,
5151 { id : "SEP" , text : "-" } ,
@@ -54,7 +54,11 @@ function setTray() {
5454 } ;
5555
5656 // Set the tray menu
57- Neutralino . os . setTray ( tray ) ;
57+ try {
58+ Neutralino . os . setTray ( tray ) ;
59+ } catch ( e ) {
60+ console . warn ( "Failed to set system tray:" , e ) ;
61+ }
5862}
5963
6064/*
@@ -85,39 +89,40 @@ function onWindowClose() {
8589 Neutralino . app . exit ( ) ;
8690}
8791
88- // Initialize Neutralino
89- Neutralino . init ( ) ;
92+ // Initialize Neutralino if in native environment
93+ if ( typeof Neutralino !== 'undefined' ) {
94+ Neutralino . init ( ) ;
9095
91- // Register event listeners
92- Neutralino . events . on ( "trayMenuItemClicked" , onTrayMenuItemClicked ) ;
93- Neutralino . events . on ( "windowClose" , onWindowClose ) ;
96+ // Register event listeners
97+ Neutralino . events . on ( "trayMenuItemClicked" , onTrayMenuItemClicked ) ;
98+ Neutralino . events . on ( "windowClose" , onWindowClose ) ;
9499
95- // Conditional initialization: Set up system tray if not running on macOS
96- if ( NL_OS != "Darwin" ) {
97- // TODO: Fix https://github.com/neutralinojs/neutralinojs/issues/615
98- setTray ( ) ;
100+ // Conditional initialization: Set up system tray if not running on macOS
101+ if ( typeof NL_OS !== 'undefined' && NL_OS != "Darwin" ) {
102+ // TODO: Fix https://github.com/neutralinojs/neutralinojs/issues/615
103+ setTray ( ) ;
104+ }
99105}
100106
101107// Open file passed as command-line argument (e.g. when double-clicking a .md file)
102108( async function loadInitialFile ( ) {
109+ if ( typeof Neutralino === 'undefined' || typeof NL_ARGS === 'undefined' ) return ;
103110 const args = Array . isArray ( NL_ARGS ) ? NL_ARGS : ( ( ) => { try { return JSON . parse ( NL_ARGS ) ; } catch ( e ) { return [ ] ; } } ) ( ) ;
104111 const filePath = args . find ( a => typeof a === 'string' && / \. ( m d | m a r k d o w n ) $ / i. test ( a ) ) ;
105112 if ( ! filePath ) return ;
106113
107114 try {
108115 const content = await Neutralino . filesystem . readFile ( filePath ) ;
116+ const fileName = filePath . split ( / [ / \\ ] / ) . pop ( ) . replace ( / \. ( m d | m a r k d o w n ) $ / i, '' ) ;
117+
118+ window . NL_INITIAL_FILE_CONTENT = {
119+ name : fileName ,
120+ content : content
121+ } ;
109122
110- function applyContent ( ) {
111- const editor = document . getElementById ( 'markdown-editor' ) ;
112- if ( ! editor ) return ;
113- editor . value = content ;
114- editor . dispatchEvent ( new Event ( 'input' ) ) ;
115- }
116-
117- if ( document . readyState === 'loading' ) {
118- document . addEventListener ( 'DOMContentLoaded' , applyContent ) ;
119- } else {
120- setTimeout ( applyContent , 0 ) ;
123+ // Callback hook in case script.js loaded first
124+ if ( window . NL_IMPORT_EXTERNAL_FILE ) {
125+ window . NL_IMPORT_EXTERNAL_FILE ( content , fileName ) ;
121126 }
122127 } catch ( e ) {
123128 console . warn ( 'Could not open initial file:' , e ) ;
0 commit comments