forked from mapbox/mapbox-studio-classic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex-shell.js
172 lines (159 loc) · 4.33 KB
/
index-shell.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
var atom = require('app');
var path = require('path');
var spawn = require('child_process').spawn;
var BrowserWindow = require('browser-window');
var Menu = require('menu');
var node = path.resolve(path.join(__dirname, 'vendor', 'node'));
var script = path.resolve(path.join(__dirname, 'index-server.js'));
// Start the server child process.
var server = spawn(node, [script, '--shell=true']);
server.on('exit', process.exit);
server.stdout.once('data', function(data) {
var matches = data.toString().match(/Mapbox Studio @ http:\/\/localhost:([0-9]+)\//);
if (!matches) {
console.warn('Server port not found');
process.exit(1);
}
serverPort = matches[1];
loadURL();
});
server.stdout.pipe(process.stdout);
server.stderr.pipe(process.stderr);
var serverPort = null;
var mainWindow = null;
// Report crashes to our server.
require('crash-reporter').start();
atom.on('window-all-closed', function() {
if (server) server.kill();
process.exit();
});
atom.on('ready', makeWindow);
function makeWindow() {
// Create the browser window.
mainWindow = new BrowserWindow({
width: 960,
height: 600,
title: 'Mapbox Studio',
'node-integration': 'all',
'web-preferences': {
webgl: true,
java: false,
webaudio: false
}
});
mainWindow.loadUrl('file://' + path.join(__dirname, 'app', 'loading.html'));
// Emitted when the window is closed.
mainWindow.on('closed', function() {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
mainWindow = null;
});
// Prevent page changes from updating the window title (typically to 'Untitled').
mainWindow.on('page-title-updated', function(e) {
e.preventDefault();
});
createMenu();
loadURL();
}
function loadURL() {
if (!mainWindow) return;
if (!serverPort) return;
mainWindow.loadUrl('http://localhost:'+serverPort);
}
function createMenu() {
var template;
if (process.platform == 'darwin') {
template = [
{
label: 'Mapbox Studio',
submenu: [
{
label: 'About Mapbox Studio',
selector: 'orderFrontStandardAboutPanel:'
},
{
type: 'separator'
},
{
label: 'Hide Mapbox Studio',
accelerator: 'Command+H',
selector: 'hide:'
},
{
label: 'Hide Others',
accelerator: 'Command+Shift+H',
selector: 'hideOtherApplications:'
},
{
label: 'Show All',
selector: 'unhideAllApplications:'
},
{
type: 'separator'
},
{
label: 'Quit Mapbox Studio',
accelerator: 'Command+Q',
selector: 'performClose:'
},
]
},
{
label: 'Edit',
submenu: [
{
label: 'Cut',
accelerator: 'Command+X',
selector: 'cut:'
},
{
label: 'Copy',
accelerator: 'Command+C',
selector: 'copy:'
},
{
label: 'Paste',
accelerator: 'Command+V',
selector: 'paste:'
}
]
},
{
label: 'View',
submenu: [
{
label: 'Reload',
accelerator: 'Command+R',
click: function() { mainWindow.restart(); }
},
{
label: 'Toggle Developer Tools',
accelerator: 'Alt+Command+I',
click: function() { mainWindow.toggleDevTools(); }
},
{
type: 'separator'
},
{
label: 'Toggle Full Screen',
accelerator: 'Ctrl+Command+F',
click: function() { mainWindow.setFullScreen(!mainWindow.isFullScreen()); }
},
]
},
{
label: 'Window',
submenu: [
{
label: 'Minimize',
accelerator: 'Command+M',
selector: 'performMiniaturize:'
}
]
},
];
menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);
}
}