@@ -10,55 +10,68 @@ let win
10
10
11
11
function createWindow ( ) {
12
12
13
- // TODO - Use the altair protocol to replace the file protocol
14
- protocol . registerBufferProtocol ( 'altair' , ( request , callback ) => {
15
- const url = request . url . substr ( 7 ) ;
16
- fs . readFile ( path . normalize ( `${ url } ` ) , 'utf8' , function ( err , data ) {
17
- if ( err ) {
18
- return console . log ( 'Error loading file to buffer.' , err ) ;
19
- }
20
-
21
- // Load the data from the file into a buffer and pass it to the callback
22
- // Using the mime package to get the mime type for the file, based on the file name
23
- callback ( { mimeType : mime . lookup ( url ) , data : new Buffer ( data ) } ) ;
24
- // console.log(data);
25
- } ) ;
26
- // callback({path: path.normalize(`${__dirname}/${url}`) })
27
- } , ( error ) => {
28
- if ( error ) console . error ( 'Failed to register protocol' )
29
- } ) ;
13
+ /**
14
+ * Using a custom buffer protocol, instead of a file protocol because of restrictions with the file protocol.
15
+ */
16
+ protocol . registerBufferProtocol ( 'altair' , ( request , callback ) => {
17
+ let url = request . url . substr ( 7 ) ;
18
+
19
+ // In windows, the url comes as altair://c/Users/Jackie/Documents/projects/altair/dist/index.html
20
+ // We also need to strip out the //c from the path
21
+ // TODO - Find a better way of handling this
22
+ if ( process . platform === 'win32' ) {
23
+ url = request . url . substr ( 10 ) ;
24
+ }
30
25
31
- // Create the browser window.
32
- win = new BrowserWindow ( {
33
- width : 1280 ,
34
- height : 800 ,
35
- titleBarStyle : 'hidden-inset'
36
- } ) ;
26
+ // Maybe this could work?
27
+ // console.log('::>>', path.join(__dirname, '../dist', path.basename(request.url)));
37
28
38
- // Populate the application menu
39
- createMenu ( ) ;
40
-
41
- // and load the index.html of the app.
42
- win . loadURL ( url . format ( {
43
- pathname : path . join ( __dirname , '../dist/index.html' ) ,
44
- protocol : 'altair:' ,
45
- slashes : true
46
- } ) ) ;
47
- // win.loadURL('altair://' + __dirname + '/../dist/index.html')
48
-
49
- // Open the DevTools.
50
- // win.webContents.openDevTools()
51
-
52
- // Prevent the app from navigating away from the app
53
- win . webContents . on ( 'will-navigate' , ( e , url ) => e . preventDefault ( ) ) ;
54
-
55
- // Emitted when the window is closed.
56
- win . on ( 'closed' , ( ) => {
57
- // Dereference the window object, usually you would store windows
58
- // in an array if your app supports multi windows, this is the time
59
- // when you should delete the corresponding element.
60
- win = null ;
61
- } )
29
+ fs . readFile ( path . normalize ( `${ url } ` ) , 'utf8' , function ( err , data ) {
30
+ if ( err ) {
31
+ return console . log ( 'Error loading file to buffer.' , err ) ;
32
+ }
33
+
34
+ // Load the data from the file into a buffer and pass it to the callback
35
+ // Using the mime package to get the mime type for the file, based on the file name
36
+ callback ( { mimeType : mime . lookup ( url ) , data : new Buffer ( data ) } ) ;
37
+ // console.log(data);
38
+ } ) ;
39
+ // callback({path: path.normalize(`${__dirname}/${url}`) })
40
+ } , ( error ) => {
41
+ if ( error ) console . error ( 'Failed to register protocol' )
42
+ } ) ;
43
+
44
+ // Create the browser window.
45
+ win = new BrowserWindow ( {
46
+ width : 1280 ,
47
+ height : 800 ,
48
+ // titleBarStyle: 'hidden-inset'
49
+ } ) ;
50
+
51
+ // Populate the application menu
52
+ createMenu ( ) ;
53
+
54
+ // and load the index.html of the app.
55
+ win . loadURL ( url . format ( {
56
+ pathname : path . join ( __dirname , '../dist/index.html' ) ,
57
+ protocol : 'altair:' ,
58
+ slashes : true
59
+ } ) ) ;
60
+ // win.loadURL('altair://' + __dirname + '/../dist/index.html')
61
+
62
+ // Open the DevTools.
63
+ // win.webContents.openDevTools()
64
+
65
+ // Prevent the app from navigating away from the app
66
+ win . webContents . on ( 'will-navigate' , ( e , url ) => e . preventDefault ( ) ) ;
67
+
68
+ // Emitted when the window is closed.
69
+ win . on ( 'closed' , ( ) => {
70
+ // Dereference the window object, usually you would store windows
71
+ // in an array if your app supports multi windows, this is the time
72
+ // when you should delete the corresponding element.
73
+ win = null ;
74
+ } )
62
75
}
63
76
64
77
function createMenu ( ) {
@@ -136,24 +149,24 @@ protocol.registerStandardSchemes(['altair']);
136
149
// This method will be called when Electron has finished
137
150
// initialization and is ready to create browser windows.
138
151
// Some APIs can only be used after this event occurs.
139
- app . on ( 'ready' , createWindow )
152
+ app . on ( 'ready' , createWindow ) ;
140
153
141
154
// Quit when all windows are closed.
142
155
app . on ( 'window-all-closed' , ( ) => {
143
- // On macOS it is common for applications and their menu bar
144
- // to stay active until the user quits explicitly with Cmd + Q
145
- if ( process . platform !== 'darwin' ) {
146
- app . quit ( )
147
- }
156
+ // On macOS it is common for applications and their menu bar
157
+ // to stay active until the user quits explicitly with Cmd + Q
158
+ if ( process . platform !== 'darwin' ) {
159
+ app . quit ( )
160
+ }
148
161
} ) ;
149
162
150
163
app . on ( 'activate' , ( ) => {
151
- // On macOS it's common to re-create a window in the app when the
152
- // dock icon is clicked and there are no other windows open.
153
- if ( win === null ) {
154
- createWindow ( )
155
- }
156
- } )
164
+ // On macOS it's common to re-create a window in the app when the
165
+ // dock icon is clicked and there are no other windows open.
166
+ if ( win === null ) {
167
+ createWindow ( )
168
+ }
169
+ } ) ;
157
170
158
171
// In this file you can include the rest of your app's specific main process
159
172
// code. You can also put them in separate files and require them here.
0 commit comments