瀏覽代碼

Add Electron support

Matt Raible 7 年之前
父節點
當前提交
3026fd95e4
共有 3 個文件被更改,包括 151 次插入60 次删除
  1. 25
    0
      ionic-beer/electron.copy.js
  2. 60
    0
      ionic-beer/main.js
  3. 66
    60
      ionic-beer/package.json

+ 25
- 0
ionic-beer/electron.copy.js 查看文件

@@ -0,0 +1,25 @@
1
+// this is a custom dictionary to make it easy to extend/override
2
+// provide a name for an entry, it can be anything such as 'copyAssets' or 'copyFonts'
3
+// then provide an object with a `src` array of globs and a `dest` string
4
+module.exports = {
5
+  copyAssets: {
6
+    src: ['{{SRC}}/assets/**/*'],
7
+    dest: '{{WWW}}/assets'
8
+  },
9
+  copyIndexContent: {
10
+    src: ['{{SRC}}/index.html', '{{SRC}}/manifest.json', '{{SRC}}/service-worker.js'],
11
+    dest: '{{WWW}}'
12
+  },
13
+  copyFonts: {
14
+    src: ['{{ROOT}}/node_modules/ionicons/dist/fonts/**/*', '{{ROOT}}/node_modules/ionic-angular/fonts/**/*'],
15
+    dest: '{{WWW}}/assets/fonts'
16
+  },
17
+  copyPolyfills: {
18
+    src: ['{{ROOT}}/node_modules/ionic-angular/polyfills/polyfills.ng.js'],
19
+    dest: '{{BUILD}}'
20
+  },
21
+  copySwToolbox: {
22
+    src: ['{{ROOT}}/node_modules/sw-toolbox/sw-toolbox.js'],
23
+    dest: '{{BUILD}}'
24
+  }
25
+};

+ 60
- 0
ionic-beer/main.js 查看文件

@@ -0,0 +1,60 @@
1
+const electron = require('electron');
2
+// Module to control application life.
3
+const app = electron.app;
4
+// Module to create native browser window.
5
+const BrowserWindow = electron.BrowserWindow;
6
+
7
+const path = require('path');
8
+const url = require('url');
9
+
10
+// Keep a global reference of the window object, if you don't, the window will
11
+// be closed automatically when the JavaScript object is garbage collected.
12
+let mainWindow;
13
+
14
+function createWindow () {
15
+  // Create the browser window.
16
+  mainWindow = new BrowserWindow({width: 800, height: 600});
17
+
18
+  // and load the index.html of the app.
19
+  mainWindow.loadURL(url.format({
20
+    pathname: path.join(__dirname, 'www/index.html'),
21
+    protocol: 'file:',
22
+    slashes: true
23
+  }));
24
+
25
+  // Open the DevTools.
26
+  //mainWindow.webContents.openDevTools();
27
+
28
+  // Emitted when the window is closed.
29
+  mainWindow.on('closed', function () {
30
+    // Dereference the window object, usually you would store windows
31
+    // in an array if your app supports multi windows, this is the time
32
+    // when you should delete the corresponding element.
33
+    mainWindow = null
34
+  })
35
+}
36
+
37
+// This method will be called when Electron has finished
38
+// initialization and is ready to create browser windows.
39
+// Some APIs can only be used after this event occurs.
40
+app.on('ready', createWindow);
41
+
42
+// Quit when all windows are closed.
43
+app.on('window-all-closed', function () {
44
+  // On OS X it is common for applications and their menu bar
45
+  // to stay active until the user quits explicitly with Cmd + Q
46
+  if (process.platform !== 'darwin') {
47
+    app.quit()
48
+  }
49
+});
50
+
51
+app.on('activate', function () {
52
+  // On OS X it's common to re-create a window in the app when the
53
+  // dock icon is clicked and there are no other windows open.
54
+  if (mainWindow === null) {
55
+    createWindow()
56
+  }
57
+});
58
+
59
+// In this file you can include the rest of your app's specific main process
60
+// code. You can also put them in separate files and require them here.

+ 66
- 60
ionic-beer/package.json 查看文件

@@ -1,62 +1,68 @@
1 1
 {
2
-    "name": "ionic-beer",
3
-    "version": "0.0.1",
4
-    "author": "Ionic Framework",
5
-    "homepage": "http://ionicframework.com/",
6
-    "private": true,
7
-    "scripts": {
8
-        "clean": "ionic-app-scripts clean",
9
-        "build": "ionic-app-scripts build",
10
-        "lint": "ionic-app-scripts lint",
11
-        "ionic:build": "ionic-app-scripts build",
12
-        "ionic:serve": "ionic-app-scripts serve"
2
+  "name": "ionic-beer",
3
+  "version": "0.0.1",
4
+  "author": "Ionic Framework",
5
+  "homepage": "http://ionicframework.com/",
6
+  "private": true,
7
+  "main": "main.js",
8
+  "scripts": {
9
+    "start": "electron .",
10
+    "build": "ionic-app-scripts build --copy electron.copy.js",
11
+    "clean": "ionic-app-scripts clean",
12
+    "lint": "ionic-app-scripts lint",
13
+    "ionic:build": "ionic-app-scripts build",
14
+    "ionic:serve": "ionic-app-scripts serve"
15
+  },
16
+  "config": {
17
+    "ionic_copy": "electron.copy.js"
18
+  },
19
+  "dependencies": {
20
+    "@angular/common": "4.1.0",
21
+    "@angular/compiler": "4.1.0",
22
+    "@angular/compiler-cli": "4.1.0",
23
+    "@angular/core": "4.1.0",
24
+    "@angular/forms": "4.1.0",
25
+    "@angular/http": "4.1.0",
26
+    "@angular/platform-browser": "4.1.0",
27
+    "@angular/platform-browser-dynamic": "4.1.0",
28
+    "@ionic-native/core": "3.7.0",
29
+    "@ionic-native/splash-screen": "3.7.0",
30
+    "@ionic-native/status-bar": "3.7.0",
31
+    "@ionic/storage": "2.0.1",
32
+    "cordova-android": "^6.2.3",
33
+    "cordova-ios": "^4.4.0",
34
+    "cordova-plugin-console": "^1.0.5",
35
+    "cordova-plugin-device": "^1.1.4",
36
+    "cordova-plugin-splashscreen": "^4.0.3",
37
+    "cordova-plugin-statusbar": "^2.2.2",
38
+    "cordova-plugin-whitelist": "^1.3.1",
39
+    "ionic-angular": "3.2.1",
40
+    "ionic-plugin-keyboard": "^2.2.1",
41
+    "ionicons": "3.0.0",
42
+    "rxjs": "5.1.1",
43
+    "sw-toolbox": "3.6.0",
44
+    "zone.js": "0.8.10"
45
+  },
46
+  "devDependencies": {
47
+    "@ionic/app-scripts": "1.3.7",
48
+    "@ionic/cli-plugin-cordova": "1.4.0",
49
+    "@ionic/cli-plugin-ionic-angular": "1.3.1",
50
+    "electron": "^1.6.11",
51
+    "typescript": "2.2.1"
52
+  },
53
+  "description": "An Ionic project",
54
+  "cordova": {
55
+    "plugins": {
56
+      "cordova-plugin-console": {},
57
+      "cordova-plugin-device": {},
58
+      "cordova-plugin-splashscreen": {},
59
+      "cordova-plugin-statusbar": {},
60
+      "cordova-plugin-whitelist": {},
61
+      "ionic-plugin-keyboard": {}
13 62
     },
14
-    "dependencies": {
15
-        "@angular/common": "4.1.0",
16
-        "@angular/compiler": "4.1.0",
17
-        "@angular/compiler-cli": "4.1.0",
18
-        "@angular/core": "4.1.0",
19
-        "@angular/forms": "4.1.0",
20
-        "@angular/http": "4.1.0",
21
-        "@angular/platform-browser": "4.1.0",
22
-        "@angular/platform-browser-dynamic": "4.1.0",
23
-        "@ionic-native/core": "3.7.0",
24
-        "@ionic-native/splash-screen": "3.7.0",
25
-        "@ionic-native/status-bar": "3.7.0",
26
-        "@ionic/storage": "2.0.1",
27
-        "cordova-android": "^6.2.3",
28
-        "cordova-ios": "^4.4.0",
29
-        "cordova-plugin-console": "^1.0.5",
30
-        "cordova-plugin-device": "^1.1.4",
31
-        "cordova-plugin-splashscreen": "^4.0.3",
32
-        "cordova-plugin-statusbar": "^2.2.2",
33
-        "cordova-plugin-whitelist": "^1.3.1",
34
-        "ionic-angular": "3.2.1",
35
-        "ionic-plugin-keyboard": "^2.2.1",
36
-        "ionicons": "3.0.0",
37
-        "rxjs": "5.1.1",
38
-        "sw-toolbox": "3.6.0",
39
-        "zone.js": "0.8.10"
40
-    },
41
-    "devDependencies": {
42
-        "@ionic/app-scripts": "1.3.7",
43
-        "@ionic/cli-plugin-cordova": "1.4.0",
44
-        "@ionic/cli-plugin-ionic-angular": "1.3.1",
45
-        "typescript": "2.2.1"
46
-    },
47
-    "description": "An Ionic project",
48
-    "cordova": {
49
-        "plugins": {
50
-            "cordova-plugin-console": {},
51
-            "cordova-plugin-device": {},
52
-            "cordova-plugin-splashscreen": {},
53
-            "cordova-plugin-statusbar": {},
54
-            "cordova-plugin-whitelist": {},
55
-            "ionic-plugin-keyboard": {}
56
-        },
57
-        "platforms": [
58
-            "android",
59
-            "ios"
60
-        ]
61
-    }
62
-}
63
+    "platforms": [
64
+      "android",
65
+      "ios"
66
+    ]
67
+  }
68
+}