Skip to content

Commit 5cce7cc

Browse files
authored
Merge branch 'staging' into linuxBuild
2 parents 0a8205b + fb5c7af commit 5cce7cc

File tree

12 files changed

+338
-265
lines changed

12 files changed

+338
-265
lines changed

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "spearmint",
33
"version": "0.6.0",
44
"description": "An open-source developer tool that simplifies testing and hopes to help increase awareness about web accessibility.",
5-
"author": "team spearmint <germanbluemax@gmail.com>",
5+
"author": "team spearmint",
66
"build": {
77
"appId": "com.spearmint",
88
"files": [
@@ -21,6 +21,9 @@
2121
}
2222
},
2323
"main": "public/electron.js",
24+
"bugs": {
25+
"url": "https://github.com/oslabs-beta/spearmint_LA42/issues",
26+
},
2427
"homepage": "./",
2528
"private": true,
2629
"dependencies": {
@@ -65,6 +68,7 @@
6568
"react-build": "NODE_ENV=production react-scripts build",
6669
"electron-build": "NODE_ENV=production electron-builder -l",
6770
"electron-rebuild": "electron-rebuild -f -w node-pty",
71+
"postinstall": "electron-builder install-app-deps",
6872
"release": "npm run react-build && electron-builder --publish=always",
6973
"start-windows": "cross-env NODE_ENV=development concurrently \"cross-env BROWSER=none react-app-rewired start\" \"wait-on http://localhost:3000 && electron .\"",
7074
"start": "NODE_ENV=development concurrently \"cross-env BROWSER=none react-app-rewired start\" \"wait-on http://localhost:3000 && electron .\""

public/electron.js

Lines changed: 165 additions & 167 deletions
Original file line numberDiff line numberDiff line change
@@ -1,167 +1,165 @@
1-
const { app, BrowserWindow, ipcMain, dialog } = require('electron');
2-
const path = require('path');
3-
const isDev = require('electron-is-dev');
4-
const fs = require('fs');
5-
const os = require('os');
6-
const pty = require('node-pty');
7-
8-
//Dynamic variable to change terminal type based on os
9-
const shell = os.platform() === 'win32' ? 'powershell.exe' : 'bash';
10-
11-
12-
13-
let mainWindow;
14-
15-
if (isDev) console.log('electron version', process.versions.electron);
16-
17-
if (isDev) {
18-
const {
19-
default: installExtension,
20-
REACT_DEVELOPER_TOOLS,
21-
} = require('electron-devtools-installer');
22-
function addDevTools() {
23-
app.whenReady().then(() => {
24-
installExtension(REACT_DEVELOPER_TOOLS)
25-
.then((name) => console.log(`Added Extension: ${name}`))
26-
.catch((err) => console.log('An error occurred: ', err));
27-
});
28-
}
29-
};
30-
31-
function createWindow() {
32-
mainWindow = new BrowserWindow({
33-
width: 1550,
34-
height: 750,
35-
minHeight: 750,
36-
icon: path.join(__dirname, 'icon.png'),
37-
webPreferences: {
38-
nodeIntegration: true,
39-
webviewTag: true,
40-
contextIsolation: false,
41-
},
42-
});
43-
mainWindow.loadURL(
44-
isDev ? 'http://localhost:3000' : `file://${path.join(__dirname, '../build/index.html')}`
45-
);
46-
mainWindow.on('closed', () => (mainWindow = null));
47-
48-
// PTY PROCESS FOR IN APP TERMINAL
49-
let ptyArgs = {
50-
name: 'xterm-color',
51-
cols: 80,
52-
rows: 80,
53-
cwd: process.env.HOME,
54-
env: process.env,
55-
}
56-
57-
58-
const ptyProcess = pty.spawn(shell, [], ptyArgs);
59-
// with ptyProcess, we want to send incoming data to the channel terminal.incData
60-
ptyProcess.on('data', (data) => {
61-
mainWindow.webContents.send('terminal.incData', data);
62-
});
63-
// in the main process, at terminal.toTerm channel, when data is received,
64-
// main process will write to ptyProcess
65-
ipcMain.on('terminal.toTerm', function(event, data) {
66-
ptyProcess.write(data);
67-
})
68-
};
69-
70-
71-
// EDITORVIEW.JSX SAVE FILE FUNCTIONALITY
72-
ipcMain.on('EditorView.saveFile', (e, filePath, editedText) => {
73-
fs.writeFile(filePath, editedText, (err) => {
74-
if (err) throw err;
75-
});
76-
// Return a success message upon save
77-
e.returnValue = 'Changes Saved'
78-
});
79-
80-
/*
81-
EXPORTFILEMODAL.JSX FILE FUNCTIONALITY
82-
(check existence and create folder)
83-
*/
84-
ipcMain.on('ExportFileModal.exists', (e, fileOrFolderPath) => {
85-
e.returnValue = fs.existsSync(fileOrFolderPath, (err) => {
86-
if (err) throw err;
87-
});
88-
});
89-
90-
ipcMain.on('ExportFileModal.mkdir', (e, folderPath) => {
91-
e.returnValue = fs.mkdirSync(folderPath, (err) => {
92-
if (err) throw err;
93-
});
94-
});
95-
96-
ipcMain.on('ExportFileModal.fileCreate', (e, filePath, file) => {
97-
e.returnValue = fs.writeFile(filePath, file, (err) => {
98-
if (err) throw err;
99-
});
100-
});
101-
102-
ipcMain.on('ExportFileModal.readFile', (e, filePath) => {
103-
e.returnValue = fs.readFileSync(filePath, 'utf8', (err) => {
104-
if (err) throw err;
105-
});
106-
});
107-
108-
// OPENFOLDERBUTTON.JSX FILE FUNCTIONALITY
109-
ipcMain.on('OpenFolderButton.isDirectory' , (e, filePath) => {
110-
e.returnValue = fs.statSync(filePath).isDirectory();
111-
});
112-
113-
ipcMain.on('OpenFolderButton.dialog' , (e) => {
114-
const dialogOptions = {
115-
properties: ['openDirectory', 'createDirectory'],
116-
filters: [
117-
{ name: 'Javascript Files', extensions: ['js', 'jsx'] },
118-
{ name: 'Style', extensions: ['css'] },
119-
{ name: 'Html', extensions: ['html'] },
120-
],
121-
message: 'Please select your project folder',
122-
};
123-
e.returnValue = dialog.showOpenDialogSync(dialogOptions);
124-
});
125-
126-
/*
127-
UNIVERSAL IPC CALLS
128-
(The following IPC calls are made from various components in the codebase)
129-
*/
130-
ipcMain.on('Universal.stat' , (e, filePath) => {
131-
e.returnValue = fs.statSync(filePath).isDirectory();
132-
});
133-
134-
ipcMain.on('Universal.readDir', (e, projectFilePath) => {
135-
e.returnValue = fs.readdirSync(projectFilePath, (err) => {
136-
if (err) throw err;
137-
});
138-
});
139-
140-
ipcMain.on('Universal.readFile', (e, filePath) => {
141-
e.returnValue = fs.readFileSync(filePath, 'utf8', (err) => {
142-
if (err) throw err;
143-
});
144-
});
145-
146-
ipcMain.on('Universal.path', (e, folderPath, filePath) => {
147-
e.returnValue = path.relative(folderPath, filePath, (err) => {
148-
if (err) throw err;
149-
});
150-
})
151-
152-
// ELECTRON BOILERPLATE FOR DEVTOOLS AND WINDOW CREATION
153-
if (isDev) {
154-
app.on('ready', addDevTools);
155-
}
156-
157-
app.on('ready', createWindow);
158-
app.on('window-all-closed', () => {
159-
if (process.platform !== 'darwin') {
160-
app.quit();
161-
}
162-
});
163-
app.on('activate', () => {
164-
if (mainWindow === null) {
165-
createWindow();
166-
}
167-
});
1+
const {
2+
app, BrowserWindow, ipcMain, dialog,
3+
} = require('electron');
4+
const path = require('path');
5+
const isDev = require('electron-is-dev');
6+
const fs = require('fs');
7+
const os = require('os');
8+
const pty = require('node-pty');
9+
10+
//Dynamic variable to change terminal type based on os
11+
const shell = os.platform() === 'win32' ? 'powershell.exe' : 'bash';
12+
13+
let mainWindow;
14+
15+
if (isDev) console.log('electron version', process.versions.electron);
16+
17+
if (isDev) {
18+
const {
19+
default: installExtension,
20+
REACT_DEVELOPER_TOOLS,
21+
} = require('electron-devtools-installer');
22+
function addDevTools() {
23+
app.whenReady().then(() => {
24+
installExtension(REACT_DEVELOPER_TOOLS)
25+
.then((name) => console.log(`Added Extension: ${name}`))
26+
.catch((err) => console.log('An error occurred: ', err));
27+
});
28+
}
29+
};
30+
31+
function createWindow() {
32+
mainWindow = new BrowserWindow({
33+
width: 1550,
34+
height: 750,
35+
minHeight: 750,
36+
icon: path.join(__dirname, 'icon.png'),
37+
webPreferences: {
38+
nodeIntegration: true,
39+
webviewTag: true,
40+
contextIsolation: false,
41+
},
42+
});
43+
mainWindow.loadURL(
44+
isDev ? 'http://localhost:3000' : `file://${path.join(__dirname, '../build/index.html')}`,
45+
);
46+
mainWindow.on('closed', () => (mainWindow = null));
47+
48+
// PTY PROCESS FOR IN APP TERMINAL
49+
const ptyArgs = {
50+
name: 'xterm-color',
51+
cols: 80,
52+
rows: 80,
53+
cwd: process.env.HOME,
54+
env: process.env,
55+
};
56+
57+
const ptyProcess = pty.spawn(shell, [], ptyArgs);
58+
// with ptyProcess, we want to send incoming data to the channel terminal.incData
59+
ptyProcess.on('data', (data) => {
60+
mainWindow.webContents.send('terminal.incData', data);
61+
});
62+
// in the main process, at terminal.toTerm channel, when data is received,
63+
// main process will write to ptyProcess
64+
ipcMain.on('terminal.toTerm', (event, data) => {
65+
ptyProcess.write(data);
66+
});
67+
}
68+
69+
// EDITORVIEW.JSX SAVE FILE FUNCTIONALITY
70+
ipcMain.on('EditorView.saveFile', (e, filePath, editedText) => {
71+
fs.writeFile(filePath, editedText, (err) => {
72+
if (err) throw err;
73+
});
74+
// Return a success message upon save
75+
e.returnValue = 'Changes Saved';
76+
});
77+
78+
/*
79+
EXPORTFILEMODAL.JSX FILE FUNCTIONALITY
80+
(check existence and create folder)
81+
*/
82+
ipcMain.on('ExportFileModal.exists', (e, fileOrFolderPath) => {
83+
e.returnValue = fs.existsSync(fileOrFolderPath, (err) => {
84+
if (err) throw err;
85+
});
86+
});
87+
88+
ipcMain.on('ExportFileModal.mkdir', (e, folderPath) => {
89+
e.returnValue = fs.mkdirSync(folderPath, (err) => {
90+
if (err) throw err;
91+
});
92+
});
93+
94+
ipcMain.on('ExportFileModal.fileCreate', (e, filePath, file) => {
95+
e.returnValue = fs.writeFile(filePath, file, (err) => {
96+
if (err) throw err;
97+
});
98+
});
99+
100+
ipcMain.on('ExportFileModal.readFile', (e, filePath) => {
101+
e.returnValue = fs.readFileSync(filePath, 'utf8', (err) => {
102+
if (err) throw err;
103+
});
104+
});
105+
106+
// OPENFOLDERBUTTON.JSX FILE FUNCTIONALITY
107+
ipcMain.on('OpenFolderButton.isDirectory', (e, filePath) => {
108+
e.returnValue = fs.statSync(filePath).isDirectory();
109+
});
110+
111+
ipcMain.on('OpenFolderButton.dialog', (e) => {
112+
const dialogOptions = {
113+
properties: ['openDirectory', 'createDirectory'],
114+
filters: [
115+
{ name: 'Javascript Files', extensions: ['js', 'jsx'] },
116+
{ name: 'Style', extensions: ['css'] },
117+
{ name: 'Html', extensions: ['html'] },
118+
],
119+
message: 'Please select your project folder',
120+
};
121+
e.returnValue = dialog.showOpenDialogSync(dialogOptions);
122+
});
123+
124+
/*
125+
UNIVERSAL IPC CALLS
126+
(The following IPC calls are made from various components in the codebase)
127+
*/
128+
ipcMain.on('Universal.stat' , (e, filePath) => {
129+
e.returnValue = fs.statSync(filePath).isDirectory();
130+
});
131+
132+
ipcMain.on('Universal.readDir', (e, projectFilePath) => {
133+
e.returnValue = fs.readdirSync(projectFilePath, (err) => {
134+
if (err) throw err;
135+
});
136+
});
137+
138+
ipcMain.on('Universal.readFile', (e, filePath) => {
139+
e.returnValue = fs.readFileSync(filePath, 'utf8', (err) => {
140+
if (err) throw err;
141+
});
142+
});
143+
144+
ipcMain.on('Universal.path', (e, folderPath, filePath) => {
145+
e.returnValue = path.relative(folderPath, filePath, (err) => {
146+
if (err) throw err;
147+
});
148+
})
149+
150+
// ELECTRON BOILERPLATE FOR DEVTOOLS AND WINDOW CREATION
151+
if (isDev) {
152+
app.on('ready', addDevTools);
153+
}
154+
155+
app.on('ready', createWindow);
156+
app.on('window-all-closed', () => {
157+
if (process.platform !== 'darwin') {
158+
app.quit();
159+
}
160+
});
161+
app.on('activate', () => {
162+
if (mainWindow === null) {
163+
createWindow();
164+
}
165+
});

0 commit comments

Comments
 (0)