-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from kwonoj/feat-asmfallback
feat(loadmodule): fall back to asm.js if wasm load fails
- Loading branch information
Showing
18 changed files
with
2,273 additions
and
958 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"files.exclude": { | ||
"**/.git": true, | ||
"**/.svn": true, | ||
"**/.hg": true, | ||
"**/CVS": true, | ||
"**/.DS_Store": true, | ||
"node_modules": true, | ||
"dist": true | ||
} | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { enableLogger, loadModule } from '../../src/index'; | ||
|
||
enableLogger(console.log.bind(console)); | ||
|
||
//Initialize cld, then attach into global | ||
const init = async () => { | ||
try { | ||
const cldFactory = await loadModule(); | ||
(window as any).cld = cldFactory.create(10, 1000); | ||
} catch (e) { | ||
//tslint:disable-next-line | ||
console.log(`failed to load cld library`, e); | ||
} | ||
}; | ||
|
||
init(); | ||
|
||
//demo purpose only: hook loaded page's input event then run cld each time input emits value | ||
const postDOMSetup = () => { | ||
if (!window || !window.location || !window.document || !window.document.body) { | ||
setTimeout(postDOMSetup, 250); | ||
return; | ||
} | ||
|
||
document.body.addEventListener('input', (evt: Event) => { | ||
if (!!evt.target && !!(evt.target as any).value) { | ||
const v = (evt.target as any).value; | ||
//we created cld with 10 char as min length of input. Skipping shorter text | ||
if (v.length < 10) { | ||
return; | ||
} | ||
const start = performance.now(); | ||
const result = (window as any).cld.findLanguage(v); | ||
const time = performance.now() - start; | ||
//tslint:disable-next-line | ||
console.log(`findLanguage: ${v} took ${time}ms, length ${v.length}`, result); | ||
} | ||
}); | ||
}; | ||
|
||
setTimeout(postDOMSetup, 250); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<html> | ||
|
||
<body> | ||
<div id="container"> | ||
<p>Language detector in BrowserView: Type any languages in textArea and check devTools console output.</p> | ||
</div> | ||
</body> | ||
</html> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<html> | ||
|
||
<body> | ||
<div id="container"> | ||
<p>Language detector in BrowserWindow: Type any languages in textArea</p> | ||
<textarea id="ta" width="400"></textarea> | ||
<p id="out"></p> | ||
</div> | ||
|
||
<script> | ||
require('./browserWindow.js'); | ||
</script> | ||
</body> | ||
|
||
</html> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { enableLogger, loadModule } from '../../src/index'; | ||
|
||
enableLogger(console.log.bind(console)); | ||
|
||
const init = async () => { | ||
try { | ||
const cldFactory = await loadModule(); | ||
const cld = cldFactory.create(10, 1000); | ||
|
||
//demo purpose only: hook input event then run cld each time input emits value | ||
(window as any).ta.addEventListener('input', (evt: Event) => { | ||
if (!!evt.target && !!(evt.target as any).value) { | ||
const v = (evt.target as any).value; | ||
//we created cld with 10 char as min length of input. Skipping shorter text | ||
if (v.length < 10) { | ||
return; | ||
} | ||
const start = performance.now(); | ||
const result = cld.findLanguage(v); | ||
const time = performance.now() - start; | ||
|
||
(window as any).out.innerText = `findLanguage: ${v} \n took ${time}ms, length ${v.length} \n ${JSON.stringify( | ||
result | ||
)}`; | ||
} | ||
}); | ||
} catch (e) { | ||
//tslint:disable-next-line | ||
console.log(`failed to load cld library`, e); | ||
} | ||
}; | ||
|
||
init(); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { app, BrowserView, BrowserWindow } from 'electron'; | ||
|
||
let mainWindow: Electron.BrowserWindow | null = null; | ||
|
||
app.on('window-all-closed', () => { | ||
app.quit(); | ||
}); | ||
|
||
app.on('ready', () => { | ||
mainWindow = new BrowserWindow({ | ||
width: 1024, | ||
height: 768 | ||
}); | ||
|
||
mainWindow.loadURL(`file://${__dirname}/${process.env.ENTRY}.html`); | ||
|
||
if (process.env.ENTRY === 'browserView') { | ||
const view = new BrowserView({ | ||
webPreferences: { | ||
nodeIntegration: false, | ||
preload: require.resolve('./browserView-preload') | ||
} | ||
}); | ||
mainWindow.setBrowserView(view); | ||
view.setBounds({ x: 0, y: 80, width: 1024, height: 768 }); | ||
view.setAutoResize({ width: true, height: true }); | ||
view.webContents.loadURL('http://html.com/tags/textarea/#Code_Example'); | ||
setTimeout(() => { | ||
view.webContents.openDevTools(); | ||
}, 2000); | ||
} | ||
}); |
Oops, something went wrong.