Skip to content
This repository was archived by the owner on Oct 18, 2024. It is now read-only.

Commit 0eb6eb9

Browse files
authored
Merge branch 'main' into feature/laravel-reverb
2 parents 605589e + 861dfab commit 0eb6eb9

24 files changed

+11493
-8768
lines changed

.github/funding.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github: simonhamp

SECURITY.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## Security contact information
2+
3+
To report a security vulnerability, please use the
4+
[Tidelift security contact](https://tidelift.com/security).
5+
Tidelift will coordinate the fix and disclosure.

dist/index.js

Lines changed: 135 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -11,137 +11,179 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
1111
var __importDefault = (this && this.__importDefault) || function (mod) {
1212
return (mod && mod.__esModule) ? mod : { "default": mod };
1313
};
14+
const electron_1 = require("electron");
1415
const electron_updater_1 = require("electron-updater");
1516
const state_1 = __importDefault(require("./server/state"));
1617
const utils_1 = require("@electron-toolkit/utils");
1718
const server_1 = require("./server");
1819
const utils_2 = require("./server/utils");
19-
const electron_1 = require("electron");
2020
const path_1 = require("path");
2121
const ps_node_1 = __importDefault(require("ps-node"));
22-
let phpProcesses = [];
23-
let websocketProcess;
24-
let schedulerInterval;
25-
const killChildProcesses = () => {
26-
let processes = [
27-
...phpProcesses,
28-
websocketProcess,
29-
].filter((p) => p !== undefined);
30-
processes.forEach((process) => {
31-
try {
32-
ps_node_1.default.kill(process.pid);
33-
}
34-
catch (err) {
35-
console.error(err);
36-
}
37-
});
38-
};
3922
class NativePHP {
23+
constructor() {
24+
this.processes = [];
25+
this.schedulerInterval = undefined;
26+
}
4027
bootstrap(app, icon, phpBinary, cert) {
41-
require('@electron/remote/main').initialize();
28+
require("@electron/remote/main").initialize();
4229
state_1.default.icon = icon;
4330
state_1.default.php = phpBinary;
4431
state_1.default.caCert = cert;
4532
this.bootstrapApp(app);
4633
this.addEventListeners(app);
47-
this.addTerminateListeners(app);
4834
}
4935
addEventListeners(app) {
50-
app.on('open-url', (event, url) => {
51-
(0, utils_2.notifyLaravel)('events', {
52-
event: '\\Native\\Laravel\\Events\\App\\OpenedFromURL',
53-
payload: [url]
36+
app.on("open-url", (event, url) => {
37+
(0, utils_2.notifyLaravel)("events", {
38+
event: "\\Native\\Laravel\\Events\\App\\OpenedFromURL",
39+
payload: [url],
5440
});
5541
});
56-
app.on('open-file', (event, path) => {
57-
(0, utils_2.notifyLaravel)('events', {
58-
event: '\\Native\\Laravel\\Events\\App\\OpenFile',
59-
payload: [path]
42+
app.on("open-file", (event, path) => {
43+
(0, utils_2.notifyLaravel)("events", {
44+
event: "\\Native\\Laravel\\Events\\App\\OpenFile",
45+
payload: [path],
6046
});
6147
});
62-
app.on('window-all-closed', () => {
63-
if (process.platform !== 'darwin') {
48+
app.on("window-all-closed", () => {
49+
if (process.platform !== "darwin") {
6450
app.quit();
6551
}
6652
});
67-
}
68-
addTerminateListeners(app) {
69-
app.on('before-quit', (e) => {
70-
if (schedulerInterval) {
71-
clearInterval(schedulerInterval);
53+
app.on("before-quit", () => {
54+
if (this.schedulerInterval) {
55+
clearInterval(this.schedulerInterval);
56+
}
57+
this.killChildProcesses();
58+
});
59+
app.on("browser-window-created", (_, window) => {
60+
utils_1.optimizer.watchWindowShortcuts(window);
61+
});
62+
app.on("activate", function (event, hasVisibleWindows) {
63+
if (!hasVisibleWindows) {
64+
(0, utils_2.notifyLaravel)("booted");
7265
}
73-
killChildProcesses();
66+
event.preventDefault();
7467
});
7568
}
7669
bootstrapApp(app) {
77-
let nativePHPConfig = {};
78-
(0, server_1.retrieveNativePHPConfig)().then((result) => {
70+
return __awaiter(this, void 0, void 0, function* () {
71+
yield app.whenReady();
72+
const config = yield this.loadConfig();
73+
this.setDockIcon();
74+
this.setAppUserModelId(config);
75+
this.setDeepLinkHandler(config);
76+
this.startAutoUpdater(config);
77+
yield this.startElectronApi();
78+
state_1.default.phpIni = yield this.loadPhpIni();
79+
yield this.startPhpApp();
80+
yield this.startQueueWorker();
81+
yield this.startWebsockets();
82+
this.startScheduler();
83+
yield (0, utils_2.notifyLaravel)("booted");
84+
});
85+
}
86+
loadConfig() {
87+
return __awaiter(this, void 0, void 0, function* () {
88+
let config = {};
7989
try {
80-
nativePHPConfig = JSON.parse(result.stdout);
90+
const result = yield (0, server_1.retrieveNativePHPConfig)();
91+
config = JSON.parse(result.stdout);
8192
}
82-
catch (e) {
83-
console.error(e);
93+
catch (error) {
94+
console.error(error);
8495
}
85-
}).catch((err) => {
86-
console.error(err);
87-
}).finally(() => {
88-
this.setupApp(nativePHPConfig);
96+
return config;
8997
});
9098
}
91-
setupApp(nativePHPConfig) {
92-
electron_1.app.whenReady().then(() => __awaiter(this, void 0, void 0, function* () {
93-
var _a;
94-
if (process.platform === 'darwin' && process.env.NODE_ENV === 'development') {
95-
electron_1.app.dock.setIcon(state_1.default.icon);
99+
setDockIcon() {
100+
if (process.platform === "darwin" &&
101+
process.env.NODE_ENV === "development") {
102+
electron_1.app.dock.setIcon(state_1.default.icon);
103+
}
104+
}
105+
setAppUserModelId(config) {
106+
utils_1.electronApp.setAppUserModelId(config === null || config === void 0 ? void 0 : config.app_id);
107+
}
108+
setDeepLinkHandler(config) {
109+
const deepLinkProtocol = config === null || config === void 0 ? void 0 : config.deeplink_scheme;
110+
if (deepLinkProtocol) {
111+
if (process.defaultApp) {
112+
if (process.argv.length >= 2) {
113+
electron_1.app.setAsDefaultProtocolClient(deepLinkProtocol, process.execPath, [
114+
(0, path_1.resolve)(process.argv[1]),
115+
]);
116+
}
96117
}
97-
electron_1.app.on('browser-window-created', (_, window) => {
98-
utils_1.optimizer.watchWindowShortcuts(window);
99-
});
100-
let phpIniSettings = {};
118+
else {
119+
electron_1.app.setAsDefaultProtocolClient(deepLinkProtocol);
120+
}
121+
}
122+
}
123+
startAutoUpdater(config) {
124+
var _a;
125+
if (((_a = config === null || config === void 0 ? void 0 : config.updater) === null || _a === void 0 ? void 0 : _a.enabled) === true) {
126+
electron_updater_1.autoUpdater.checkForUpdatesAndNotify();
127+
}
128+
}
129+
startElectronApi() {
130+
return __awaiter(this, void 0, void 0, function* () {
131+
const electronApi = yield (0, server_1.startAPI)();
132+
state_1.default.electronApiPort = electronApi.port;
133+
console.log("Electron API server started on port", electronApi.port);
134+
});
135+
}
136+
loadPhpIni() {
137+
return __awaiter(this, void 0, void 0, function* () {
138+
let config = {};
101139
try {
102-
let { stdout } = yield (0, server_1.retrievePhpIniSettings)();
103-
phpIniSettings = JSON.parse(stdout);
140+
const result = yield (0, server_1.retrievePhpIniSettings)();
141+
config = JSON.parse(result.stdout);
104142
}
105-
catch (e) {
106-
console.error(e);
143+
catch (error) {
144+
console.error(error);
107145
}
108-
utils_1.electronApp.setAppUserModelId(nativePHPConfig === null || nativePHPConfig === void 0 ? void 0 : nativePHPConfig.app_id);
109-
const deepLinkProtocol = nativePHPConfig === null || nativePHPConfig === void 0 ? void 0 : nativePHPConfig.deeplink_scheme;
110-
if (deepLinkProtocol) {
111-
if (process.defaultApp) {
112-
if (process.argv.length >= 2) {
113-
electron_1.app.setAsDefaultProtocolClient(deepLinkProtocol, process.execPath, [(0, path_1.resolve)(process.argv[1])]);
114-
}
115-
}
116-
else {
117-
electron_1.app.setAsDefaultProtocolClient(deepLinkProtocol);
118-
}
146+
return config;
147+
});
148+
}
149+
startPhpApp() {
150+
return __awaiter(this, void 0, void 0, function* () {
151+
this.processes.push(yield (0, server_1.startPhpApp)());
152+
});
153+
}
154+
startQueueWorker() {
155+
return __awaiter(this, void 0, void 0, function* () {
156+
this.processes.push(yield (0, server_1.startQueue)());
157+
});
158+
}
159+
startWebsockets() {
160+
return __awaiter(this, void 0, void 0, function* () {
161+
this.processes.push(yield (0, server_1.startWebsockets)());
162+
});
163+
}
164+
startScheduler() {
165+
const now = new Date();
166+
const delay = (60 - now.getSeconds()) * 1000 + (1000 - now.getMilliseconds());
167+
setTimeout(() => {
168+
console.log("Running scheduler...");
169+
(0, server_1.runScheduler)();
170+
this.schedulerInterval = setInterval(() => {
171+
console.log("Running scheduler...");
172+
(0, server_1.runScheduler)();
173+
}, 60 * 1000);
174+
}, delay);
175+
}
176+
killChildProcesses() {
177+
this.processes
178+
.filter((p) => p !== undefined)
179+
.forEach((process) => {
180+
try {
181+
ps_node_1.default.kill(process.pid);
119182
}
120-
const apiPort = yield (0, server_1.startAPI)();
121-
console.log('API server started on port', apiPort.port);
122-
phpProcesses = yield (0, server_1.servePhpApp)(apiPort.port, phpIniSettings);
123-
websocketProcess = (0, server_1.serveWebsockets)();
124-
yield (0, utils_2.notifyLaravel)('booted');
125-
if (((_a = nativePHPConfig === null || nativePHPConfig === void 0 ? void 0 : nativePHPConfig.updater) === null || _a === void 0 ? void 0 : _a.enabled) === true) {
126-
electron_updater_1.autoUpdater.checkForUpdatesAndNotify();
183+
catch (err) {
184+
console.error(err);
127185
}
128-
let now = new Date();
129-
let delay = (60 - now.getSeconds()) * 1000 + (1000 - now.getMilliseconds());
130-
setTimeout(() => {
131-
console.log("Running scheduler...");
132-
(0, server_1.runScheduler)(apiPort.port, phpIniSettings);
133-
schedulerInterval = setInterval(() => {
134-
console.log("Running scheduler...");
135-
(0, server_1.runScheduler)(apiPort.port, phpIniSettings);
136-
}, 60 * 1000);
137-
}, delay);
138-
electron_1.app.on('activate', function (event, hasVisibleWindows) {
139-
if (!hasVisibleWindows) {
140-
(0, utils_2.notifyLaravel)('booted');
141-
}
142-
event.preventDefault();
143-
});
144-
}));
186+
});
145187
}
146188
}
147189
module.exports = new NativePHP();

dist/server/api.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const contextMenu_1 = __importDefault(require("./api/contextMenu"));
3333
const settings_1 = __importDefault(require("./api/settings"));
3434
const shell_1 = __importDefault(require("./api/shell"));
3535
const progressBar_1 = __importDefault(require("./api/progressBar"));
36+
const powerMonitor_1 = __importDefault(require("./api/powerMonitor"));
3637
function startAPIServer(randomSecret) {
3738
return __awaiter(this, void 0, void 0, function* () {
3839
const port = yield (0, get_port_1.default)({
@@ -58,6 +59,7 @@ function startAPIServer(randomSecret) {
5859
httpServer.use("/api/context", contextMenu_1.default);
5960
httpServer.use("/api/menu-bar", menuBar_1.default);
6061
httpServer.use("/api/progress-bar", progressBar_1.default);
62+
httpServer.use("/api/power-monitor", powerMonitor_1.default);
6163
if (process.env.NODE_ENV === "development") {
6264
httpServer.use("/api/debug", debug_1.default);
6365
}

dist/server/api/debug.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@ const express_1 = __importDefault(require("express"));
77
const state_1 = __importDefault(require("../state"));
88
const router = express_1.default.Router();
99
router.post('/log', (req, res) => {
10+
var _a;
1011
const { level, message, context } = req.body;
1112
Object.values(state_1.default.windows).forEach(window => {
1213
window.webContents.send('log', { level, message, context });
1314
});
15+
if ((_a = state_1.default.activeMenuBar) === null || _a === void 0 ? void 0 : _a.window) {
16+
state_1.default.activeMenuBar.window.webContents.send('log', { level, message, context });
17+
}
1418
res.sendStatus(200);
1519
});
1620
exports.default = router;

dist/server/api/powerMonitor.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
"use strict";
2+
var __importDefault = (this && this.__importDefault) || function (mod) {
3+
return (mod && mod.__esModule) ? mod : { "default": mod };
4+
};
5+
Object.defineProperty(exports, "__esModule", { value: true });
6+
const express_1 = __importDefault(require("express"));
7+
const electron_1 = require("electron");
8+
const utils_1 = require("../utils");
9+
const router = express_1.default.Router();
10+
router.get('/get-system-idle-state', (req, res) => {
11+
res.json({
12+
result: electron_1.powerMonitor.getSystemIdleState(req.body.threshold),
13+
});
14+
});
15+
router.get('/get-system-idle-time', (req, res) => {
16+
res.json({
17+
result: electron_1.powerMonitor.getSystemIdleTime(),
18+
});
19+
});
20+
router.get('/get-current-thermal-state', (req, res) => {
21+
res.json({
22+
result: electron_1.powerMonitor.getCurrentThermalState(),
23+
});
24+
});
25+
router.get('/is-on-battery-power', (req, res) => {
26+
res.json({
27+
result: electron_1.powerMonitor.isOnBatteryPower(),
28+
});
29+
});
30+
electron_1.powerMonitor.addListener('on-ac', () => {
31+
(0, utils_1.notifyLaravel)("events", {
32+
event: `\\Native\\Laravel\\Events\\PowerMonitor\\PowerStateChanged`,
33+
payload: {
34+
state: 'on-ac'
35+
}
36+
});
37+
});
38+
electron_1.powerMonitor.addListener('on-battery', () => {
39+
(0, utils_1.notifyLaravel)("events", {
40+
event: `\\Native\\Laravel\\Events\\PowerMonitor\\PowerStateChanged`,
41+
payload: {
42+
state: 'on-battery'
43+
}
44+
});
45+
});
46+
electron_1.powerMonitor.addListener('thermal-state-change', (state) => {
47+
(0, utils_1.notifyLaravel)("events", {
48+
event: `\\Native\\Laravel\\Events\\PowerMonitor\\ThermalStateChanged`,
49+
payload: {
50+
state
51+
}
52+
});
53+
});
54+
electron_1.powerMonitor.addListener('speed-limit-change', (limit) => {
55+
(0, utils_1.notifyLaravel)("events", {
56+
event: `\\Native\\Laravel\\Events\\PowerMonitor\\SpeedLimitChanged`,
57+
payload: {
58+
limit
59+
}
60+
});
61+
});
62+
exports.default = router;

0 commit comments

Comments
 (0)