This repository has been archived by the owner on Mar 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
172 lines (160 loc) · 5.39 KB
/
main.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
172
// Imports dependencies for executing electron
const { app, ipcMain, BrowserWindow, Menu, MenuItem, globalShortcut } = require("electron");
const contextMenu = require('electron-context-menu');
// Imports node-pty, which is required for the actual terminal process
const pty = require("node-pty");
// Gets the os you are on, to switch between eg. bash and zsh depending on your operating system
const os = require("os");
// This is a custom function that imports the settings library
const { getSettings } = require("./BackEnd/settings");
// This is the auto updater that updates the application when a new version comes out.
const { autoUpdater } = require("electron-updater");
// This gets the required settings from the settings file using the getSettings(); function
const { cols, rows, shellSettings, blurType, completeTransparent, showContextMenu } =
getSettings();
// Enable live reload for all the files inside your project directory
require("electron-reload")(__dirname, {
// Note that the path to electron may vary according to the main file
electron: require(`${__dirname}/node_modules/electron`),
});
if(showContextMenu)
{
contextMenu({
showSaveImageAs: true,
showLookUpSelectrion: true,
showSearchWithGoogle: true,
showSelectAll: true,
showCopyImage: true,
showCopyImageAddress: true,
showSaveImage: true,
showSaveLinkAs: true,
showInspectElement: true,
showServices: true
});
}
// This logs the settings (Good for debugging purposes)
// console.log(getSettings());
// This gets what shell to use using your operating system.
var shell =
os.platform() === "win32"
? "powershell.exe"
: shellSettings; /* fish shell path: "/opt/homebrew/bin/fish"*/
let mainWindow;
let ptyProcess;
// This is the configuration for the electron window
function createWindow() {
// Creates the window object
let mainWindow = new BrowserWindow({
// The height of the application
height: 961,
// The width of the application
width: 1555,
// This starts the application in the center of your screen
center: true,
// This disables the default macOS window bar
frame: false,
// This allows for the see-trough window
transparent: true,
// Web permissions to make the application actually work as intended
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
enableRemoteModule: true,
allowRunningInsecureContent: true,
},
});
// This loads the terminal using dynamic directories
mainWindow.loadURL(`file://${__dirname}/FrontEnd/index.html`);
// type string | null - Can be appearance-based, light, dark, titlebar, selection, menu, popover, sidebar, medium-light, ultra-dark, header, sheet, window, hud, fullscreen-ui, tooltip, content, under-window, or under-page.
//mainWindow.setVibrancy("hud");
// When the main window is closed, it sets the main window to nothing
mainWindow.on("closed", function () {
mainWindow = null;
});
// This checks if there is a new version available, and notifies it to the process
autoUpdater.checkForUpdatesAndNotify();
// When there is an update available, it changes the window to the updating screen
autoUpdater.on("update-available", function () {
mainWindow.loadURL(`file://${__dirname}/FrontEnd/updater.html`);
});
// When the update has been downloaded, it quits the application and installs it
autoUpdater.on("update-downloaded", (updateInfo) => {
setTimeout(() => {
autoUpdater.quitAndInstall();
app.exit();
}, 10000);
});
// If the completeTransparent setting is enabled, it sets the blurry transparency.
if (!completeTransparent) {
mainWindow.setVibrancy(blurType);
}
//ipcing
// This starts the pty process, with basic terminal configurations
let ptyProcess = pty.spawn(shell, [], {
name: "xterm-color",
cols: cols,
rows: rows,
cwd: process.env.HOME,
env: process.env,
});
// This sends your input to the ptyProcess
ptyProcess.on("data", function (data) {
mainWindow.webContents.send("terminal.incomingData", data);
// console.log("Sent data to terminal");
console.log(data);
});
// Exits the application
ptyProcess.onExit((exitCode) => {
app.quit();
});
/*ptyProcess.onData((data) => {
console.log(data);
});*/
// Write in the terminal
ipcMain.on("terminal.keystroke", (event, key) => {
ptyProcess.write(key);
});
// This resizes the terminal when called
ipcMain.on("terminal.resize", (event, size) => {
ptyProcess.resize(size.cols, size.rows);
console.log("resized");
});
}
// Create a window when the app is ready
app.on("ready", createWindow);
app.on("add-window", createWindow);
/*
const menu = new Menu();
menu.append(
new MenuItem({
label: "Electron",
submenu: [
{
role: "NewWindow",
accelerator: process.platform === "darwin" ? "Shift+Cmd+N" : "Shift+Ctrl+N",
click: () => {
createWindow();
},
},
],
})
);
Menu.setApplicationMenu(menu);*/
app.whenReady().then(() => {
// Register a 'CommandOrControl+Y' shortcut listener.
globalShortcut.register('CommandOrControl+Shift+N', () => {
createWindow();
})
})
// When there are no windows, it just quits the entire process
app.on("window-all-closed", function () {
if (process.platform !== "darwin") {
app.quit();
}
});
// When the app is activated it creates a new window
app.on("activate", function () {
if (mainWindow === null) {
createWindow();
}
});