Bläddra i källkod

Fixes #1: Add electron sample

Alex Dima 9 år sedan
förälder
incheckning
4dad8338f9
3 ändrade filer med 81 tillägg och 0 borttagningar
  1. 5 0
      sample-electron/README.md
  2. 48 0
      sample-electron/index.html
  3. 28 0
      sample-electron/main.js

+ 5 - 0
sample-electron/README.md

@@ -0,0 +1,5 @@
+To run this sample, you need to [download Electron](https://github.com/electron/electron/releases)
+
+```
+$/sample-electron> electron main.js
+```

+ 48 - 0
sample-electron/index.html

@@ -0,0 +1,48 @@
+<!DOCTYPE html>
+<html>
+	<head>
+		<meta charset="UTF-8">
+		<title>Hello World!</title>
+	</head>
+	<body>
+		<h1>Hello World!</h1>
+		<div id="container" style="width:500px;height:300px;border:1px solid #ccc"></div>
+	</body>
+
+	<script>
+		// require node modules before loader.js comes in
+		var path = require('path');
+	</script>
+
+	<script src="../node_modules/monaco-editor/min/vs/loader.js"></script>
+	<script>
+		function uriFromPath(_path) {
+			var pathName = path.resolve(_path).replace(/\\/g, '/');
+			if (pathName.length > 0 && pathName.charAt(0) !== '/') {
+				pathName = '/' + pathName;
+			}
+			return encodeURI('file://' + pathName);
+		}
+
+		require.config({
+			baseUrl: uriFromPath(path.join(__dirname, '../node_modules/monaco-editor/min'))
+		});
+
+		// workaround monaco-css not understanding the environment
+		self.module = undefined;
+
+		// workaround monaco-typescript not understanding the environment
+		self.process.browser = true;
+
+		require(['vs/editor/editor.main'], function() {
+			var editor = monaco.editor.create(document.getElementById('container'), {
+				value: [
+					'function x() {',
+					'\tconsole.log("Hello world!");',
+					'}'
+				].join('\n'),
+				language: 'javascript'
+			});
+		});
+	</script>
+</html>

+ 28 - 0
sample-electron/main.js

@@ -0,0 +1,28 @@
+const electron = require('electron')
+const app = electron.app
+const BrowserWindow = electron.BrowserWindow
+
+let mainWindow;
+
+function createWindow () {
+	mainWindow = new BrowserWindow({width: 800, height: 600})
+	mainWindow.loadURL(`file://${__dirname}/index.html`)
+	mainWindow.webContents.openDevTools()
+	mainWindow.on('closed', function () {
+		mainWindow = null
+	})
+}
+
+app.on('ready', createWindow)
+
+app.on('window-all-closed', function () {
+	if (process.platform !== 'darwin') {
+		app.quit()
+	}
+})
+
+app.on('activate', function () {
+	if (mainWindow === null) {
+		createWindow()
+	}
+})