Created
January 8, 2020 06:31
-
-
Save bendemboski/d0cb93e9c7d6ad198fe38db77038495a to your computer and use it in GitHub Desktop.
Electron Fiddle Gist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="cust://assets/test.js"></script> | |
</head> | |
<body> | |
<h1>Hello World!</h1> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const {app, protocol, BrowserWindow} = require('electron') | |
// canned content | |
const testJs = ` | |
function testSourceMapUrls() { | |
var arr2 = [6, 4, -2, 8, 7]; | |
sortAndDisplay2(arr2); | |
} | |
function sortAndDisplay2(arr) { | |
arr.sort(); | |
console.log(arr); | |
} | |
//# sourceMappingURL=test.js.map | |
`; | |
const testJsMap = `{"version":3,"file":"test.js","sourceRoot":"","sources":["test.ts"],"names":[],"mappings":"AAAA;IAEI,IAAI,IAAI,GAAa,CAAC,CAAC,EAAC,CAAC,EAAC,CAAC,CAAC,EAAC,CAAC,EAAC,CAAC,CAAC,CAAC;IAClC,eAAe,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC;AAED,yBAA0B,GAAa;IAEnC,GAAG,CAAC,IAAI,EAAE,CAAC;IACX,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AACrB,CAAC"}`; | |
const testTs = ` | |
function testSourceMapUrls() | |
{ | |
let arr2: number[] = [6,4,-2,8,7]; | |
sortAndDisplay2(arr2); | |
} | |
function sortAndDisplay2 (arr: number[]) | |
{ | |
arr.sort(); | |
console.log(arr); | |
}`; | |
// register custom scheme | |
protocol.registerSchemesAsPrivileged([ | |
{ scheme: 'cust', privileges: { standard: true, secure: true } } | |
]); | |
// cheesy string handler to demonstrate map file loading (or failure to) | |
function handler({ url }, callback) { | |
if (url == 'cust://assets/test.js') { | |
callback({ | |
mimeType: 'application/javascript', | |
data: testJs | |
}); | |
} else if (url == 'cust://assets/test.js.map') { | |
console.log('source map requested!'); | |
callback({ | |
mimeType: 'application/json', | |
data: testJsMap | |
}); | |
} else if (url == 'cust://assets/test.ts') { | |
callback({ | |
mimeType: 'text/plain', | |
data: testTs | |
}); | |
} | |
} | |
// register protocol on custom scheme | |
app.on('ready', () => { | |
protocol.registerStringProtocol('cust', handler, error => { | |
if (error) { | |
console.error('Failed to register protocol'); | |
} | |
}); | |
}); | |
let mainWindow | |
function createWindow () { | |
mainWindow = new BrowserWindow({ | |
width: 800, | |
height: 600, | |
webPreferences: { | |
nodeIntegration: true | |
} | |
}) | |
mainWindow.loadFile('index.html') | |
} | |
app.on('ready', createWindow) | |
app.on('window-all-closed', function () { | |
if (process.platform !== 'darwin') { | |
app.quit() | |
} | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Empty |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment