Commit ce533dbe10ead70d29fbc1c92fa3d02700125aac
trying to build from ticktack-builder (electron entry needs to be index.js?)
Matt McKegg committed on 8/14/2017, 5:02:31 AMParent: 8737709db876420b4db1aea9a323d248fd75fe20
Files changed
index.js | changed |
main.js | changed |
package.json | changed |
electron.js | deleted |
index.js | ||
---|---|---|
@@ -1,9 +1,135 @@ | ||
1 | -const ticktack = { | |
2 | - app: require('./app'), | |
3 | - blob: require('./blob'), | |
4 | - config: require('./config'), | |
5 | - router: require('./router'), | |
6 | - styles: require('./styles') | |
1 | +var defaultMenu = require('electron-default-menu') | |
2 | +var WindowState = require('electron-window-state') | |
3 | +var electron = require('electron') | |
4 | +var Menu = electron.Menu | |
5 | +var Path = require('path') | |
6 | + | |
7 | +var windows = {} | |
8 | +var quitting = false | |
9 | + | |
10 | +electron.app.on('ready', () => { | |
11 | + var menu = defaultMenu(electron.app, electron.shell) | |
12 | + var view = menu.find(x => x.label === 'View') | |
13 | + view.submenu = [ | |
14 | + { role: 'reload' }, | |
15 | + { role: 'toggledevtools' }, | |
16 | + { type: 'separator' }, | |
17 | + { role: 'resetzoom' }, | |
18 | + { role: 'zoomin' }, | |
19 | + { role: 'zoomout' }, | |
20 | + { type: 'separator' }, | |
21 | + { role: 'togglefullscreen' } | |
22 | + ] | |
23 | + if (process.platform === 'darwin') { | |
24 | + var win = menu.find(x => x.label === 'Window') | |
25 | + win.submenu = [ | |
26 | + { role: 'minimize' }, | |
27 | + { role: 'zoom' }, | |
28 | + { role: 'close', label: 'Close' }, | |
29 | + { type: 'separator' }, | |
30 | + { role: 'front' } | |
31 | + ] | |
32 | + } | |
33 | + | |
34 | + Menu.setApplicationMenu(Menu.buildFromTemplate(menu)) | |
35 | + | |
36 | + startBackgroundProcess() | |
37 | + | |
38 | + // wait until server has started before opening main window | |
39 | + electron.ipcMain.once('server-started', function (ev, config) { | |
40 | + openMainWindow() | |
41 | + }) | |
42 | + | |
43 | + electron.app.on('before-quit', function () { | |
44 | + quitting = true | |
45 | + }) | |
46 | + | |
47 | + // allow inspecting of background process | |
48 | + electron.ipcMain.on('open-background-devtools', function (ev, config) { | |
49 | + if (windows.background) { | |
50 | + windows.background.webContents.openDevTools({detach: true}) | |
51 | + } | |
52 | + }) | |
53 | +}) | |
54 | + | |
55 | +function startBackgroundProcess () { | |
56 | + if (!windows.background) { | |
57 | + windows.background = openWindow(Path.join(__dirname, 'background-process.js'), { | |
58 | + connect: false, | |
59 | + center: true, | |
60 | + fullscreen: false, | |
61 | + fullscreenable: false, | |
62 | + height: 150, | |
63 | + maximizable: false, | |
64 | + minimizable: false, | |
65 | + resizable: false, | |
66 | + show: false, | |
67 | + skipTaskbar: true, | |
68 | + title: 'ticktack-server', | |
69 | + useContentSize: true, | |
70 | + width: 150 | |
71 | + }) | |
72 | + } | |
7 | 73 | } |
8 | 74 | |
9 | -module.exports = ticktack | |
75 | +function openMainWindow () { | |
76 | + if (!windows.main) { | |
77 | + var windowState = WindowState({ | |
78 | + defaultWidth: 1024, | |
79 | + defaultHeight: 768 | |
80 | + }) | |
81 | + windows.main = openWindow(Path.join(__dirname, 'main.js'), { | |
82 | + minWidth: 800, | |
83 | + x: windowState.x, | |
84 | + y: windowState.y, | |
85 | + width: windowState.width, | |
86 | + height: windowState.height, | |
87 | + autoHideMenuBar: true, | |
88 | + title: 'Ticktack', | |
89 | + show: true, | |
90 | + backgroundColor: '#EEE', | |
91 | + icon: './assets/icon.png' | |
92 | + }) | |
93 | + windowState.manage(windows.main) | |
94 | + windows.main.setSheetOffset(40) | |
95 | + windows.main.on('close', function (e) { | |
96 | + if (!quitting && process.platform === 'darwin') { | |
97 | + e.preventDefault() | |
98 | + windows.main.hide() | |
99 | + } | |
100 | + }) | |
101 | + windows.main.on('closed', function () { | |
102 | + windows.main = null | |
103 | + if (process.platform !== 'darwin') electron.app.quit() | |
104 | + }) | |
105 | + } | |
106 | +} | |
107 | + | |
108 | +function openWindow (path, opts) { | |
109 | + var window = new electron.BrowserWindow(opts) | |
110 | + window.webContents.on('dom-ready', function () { | |
111 | + window.webContents.executeJavaScript(` | |
112 | + var electron = require('electron') | |
113 | + var h = require('mutant/h') | |
114 | + electron.webFrame.setZoomLevelLimits(1, 1) | |
115 | + var title = ${JSON.stringify(opts.title || 'Ticktack')} | |
116 | + document.documentElement.querySelector('head').appendChild( | |
117 | + h('title', title) | |
118 | + ) | |
119 | + require(${JSON.stringify(path)}) | |
120 | + `) | |
121 | + }) | |
122 | + | |
123 | + window.webContents.on('will-navigate', function (e, url) { | |
124 | + e.preventDefault() | |
125 | + electron.shell.openExternal(url) | |
126 | + }) | |
127 | + | |
128 | + window.webContents.on('new-window', function (e, url) { | |
129 | + e.preventDefault() | |
130 | + electron.shell.openExternal(url) | |
131 | + }) | |
132 | + | |
133 | + window.loadURL('file://' + Path.join(__dirname, 'assets', 'base.html')) | |
134 | + return window | |
135 | +} |
main.js | ||
---|---|---|
@@ -9,9 +9,15 @@ | ||
9 | 9 | require('./context-menu') |
10 | 10 | |
11 | 11 | // from more specialized to more general |
12 | 12 | const sockets = combine( |
13 | - require('./'), | |
13 | + { | |
14 | + app: require('./app'), | |
15 | + blob: require('./blob'), | |
16 | + config: require('./config'), | |
17 | + router: require('./router'), | |
18 | + styles: require('./styles') | |
19 | + }, | |
14 | 20 | require('patch-history'), |
15 | 21 | require('patchcore') |
16 | 22 | ) |
17 | 23 |
package.json | ||
---|---|---|
@@ -4,9 +4,9 @@ | ||
4 | 4 | "description": "", |
5 | 5 | "main": "index.js", |
6 | 6 | "scripts": { |
7 | 7 | "rebuild": "cross-script npm rebuild --runtime=electron \"--target=$(electron -v)\" \"--abi=$(electron --abi)\" --disturl=https://atom.io/download/atom-shell", |
8 | - "start": "electron electron.js", | |
8 | + "start": "electron .", | |
9 | 9 | "postinstall": "npm run rebuild", |
10 | 10 | "test": "echo \"Error: no test specified\" && exit 1" |
11 | 11 | }, |
12 | 12 | "repository": { |
electron.js | ||
---|---|---|
@@ -1,135 +1,0 @@ | ||
1 | -var defaultMenu = require('electron-default-menu') | |
2 | -var WindowState = require('electron-window-state') | |
3 | -var electron = require('electron') | |
4 | -var Menu = electron.Menu | |
5 | -var Path = require('path') | |
6 | - | |
7 | -var windows = {} | |
8 | -var quitting = false | |
9 | - | |
10 | -electron.app.on('ready', () => { | |
11 | - var menu = defaultMenu(electron.app, electron.shell) | |
12 | - var view = menu.find(x => x.label === 'View') | |
13 | - view.submenu = [ | |
14 | - { role: 'reload' }, | |
15 | - { role: 'toggledevtools' }, | |
16 | - { type: 'separator' }, | |
17 | - { role: 'resetzoom' }, | |
18 | - { role: 'zoomin' }, | |
19 | - { role: 'zoomout' }, | |
20 | - { type: 'separator' }, | |
21 | - { role: 'togglefullscreen' } | |
22 | - ] | |
23 | - if (process.platform === 'darwin') { | |
24 | - var win = menu.find(x => x.label === 'Window') | |
25 | - win.submenu = [ | |
26 | - { role: 'minimize' }, | |
27 | - { role: 'zoom' }, | |
28 | - { role: 'close', label: 'Close' }, | |
29 | - { type: 'separator' }, | |
30 | - { role: 'front' } | |
31 | - ] | |
32 | - } | |
33 | - | |
34 | - Menu.setApplicationMenu(Menu.buildFromTemplate(menu)) | |
35 | - | |
36 | - startBackgroundProcess() | |
37 | - | |
38 | - // wait until server has started before opening main window | |
39 | - electron.ipcMain.once('server-started', function (ev, config) { | |
40 | - openMainWindow() | |
41 | - }) | |
42 | - | |
43 | - electron.app.on('before-quit', function () { | |
44 | - quitting = true | |
45 | - }) | |
46 | - | |
47 | - // allow inspecting of background process | |
48 | - electron.ipcMain.on('open-background-devtools', function (ev, config) { | |
49 | - if (windows.background) { | |
50 | - windows.background.webContents.openDevTools({detach: true}) | |
51 | - } | |
52 | - }) | |
53 | -}) | |
54 | - | |
55 | -function startBackgroundProcess () { | |
56 | - if (!windows.background) { | |
57 | - windows.background = openWindow(Path.join(__dirname, 'background-process.js'), { | |
58 | - connect: false, | |
59 | - center: true, | |
60 | - fullscreen: false, | |
61 | - fullscreenable: false, | |
62 | - height: 150, | |
63 | - maximizable: false, | |
64 | - minimizable: false, | |
65 | - resizable: false, | |
66 | - show: false, | |
67 | - skipTaskbar: true, | |
68 | - title: 'ticktack-server', | |
69 | - useContentSize: true, | |
70 | - width: 150 | |
71 | - }) | |
72 | - } | |
73 | -} | |
74 | - | |
75 | -function openMainWindow () { | |
76 | - if (!windows.main) { | |
77 | - var windowState = WindowState({ | |
78 | - defaultWidth: 1024, | |
79 | - defaultHeight: 768 | |
80 | - }) | |
81 | - windows.main = openWindow(Path.join(__dirname, 'main.js'), { | |
82 | - minWidth: 800, | |
83 | - x: windowState.x, | |
84 | - y: windowState.y, | |
85 | - width: windowState.width, | |
86 | - height: windowState.height, | |
87 | - autoHideMenuBar: true, | |
88 | - title: 'Ticktack', | |
89 | - show: true, | |
90 | - backgroundColor: '#EEE', | |
91 | - icon: './assets/icon.png' | |
92 | - }) | |
93 | - windowState.manage(windows.main) | |
94 | - windows.main.setSheetOffset(40) | |
95 | - windows.main.on('close', function (e) { | |
96 | - if (!quitting && process.platform === 'darwin') { | |
97 | - e.preventDefault() | |
98 | - windows.main.hide() | |
99 | - } | |
100 | - }) | |
101 | - windows.main.on('closed', function () { | |
102 | - windows.main = null | |
103 | - if (process.platform !== 'darwin') electron.app.quit() | |
104 | - }) | |
105 | - } | |
106 | -} | |
107 | - | |
108 | -function openWindow (path, opts) { | |
109 | - var window = new electron.BrowserWindow(opts) | |
110 | - window.webContents.on('dom-ready', function () { | |
111 | - window.webContents.executeJavaScript(` | |
112 | - var electron = require('electron') | |
113 | - var h = require('mutant/h') | |
114 | - electron.webFrame.setZoomLevelLimits(1, 1) | |
115 | - var title = ${JSON.stringify(opts.title || 'Ticktack')} | |
116 | - document.documentElement.querySelector('head').appendChild( | |
117 | - h('title', title) | |
118 | - ) | |
119 | - require(${JSON.stringify(path)}) | |
120 | - `) | |
121 | - }) | |
122 | - | |
123 | - window.webContents.on('will-navigate', function (e, url) { | |
124 | - e.preventDefault() | |
125 | - electron.shell.openExternal(url) | |
126 | - }) | |
127 | - | |
128 | - window.webContents.on('new-window', function (e, url) { | |
129 | - e.preventDefault() | |
130 | - electron.shell.openExternal(url) | |
131 | - }) | |
132 | - | |
133 | - window.loadURL('file://' + Path.join(__dirname, 'assets', 'base.html')) | |
134 | - return window | |
135 | -} |
Built with git-ssb-web