Add standalone desktop launch modes

This commit is contained in:
Курнат Андрей
2026-06-01 23:15:20 +03:00
parent 91e8a6e9fd
commit c8c1be7a30
6 changed files with 169 additions and 26 deletions
+66 -13
View File
@@ -3,6 +3,49 @@ const fs = require("node:fs/promises");
const path = require("node:path");
const isDev = !app.isPackaged;
const applicationModes = {
word: {
title: "QWord",
windowTitle: "Документ1 - QWord",
route: "/qword"
},
sheets: {
title: "QExcell",
windowTitle: "Книга1 - QExcell",
route: "/qexcell"
},
slides: {
title: "QPowerPoint",
windowTitle: "Презентация1 - QPowerPoint",
route: "/qpowerpoint"
},
mail: {
title: "QOutlook",
windowTitle: "Почта - QOutlook",
route: "/qoutlook"
}
};
const applicationAliases = {
word: "word",
qword: "word",
docx: "word",
sheets: "sheets",
sheet: "sheets",
excel: "sheets",
excell: "sheets",
qexcell: "sheets",
xlsx: "sheets",
slides: "slides",
slide: "slides",
powerpoint: "slides",
qpowerpoint: "slides",
pptx: "slides",
mail: "mail",
outlook: "mail",
qoutlook: "mail",
eml: "mail",
msg: "mail"
};
const fileKinds = {
docx: {
title: "Открыть документ Word",
@@ -66,21 +109,28 @@ function sendFocusedCommand(command) {
}
}
function createApplicationMenu() {
function applicationModeFromArgs(argv = process.argv, env = process.env) {
const explicitArg = argv.find((argument) => argument.startsWith("--qoffice-app=") || argument.startsWith("--app="));
const rawMode = explicitArg?.split("=")[1] ?? env.QOFFICE_APP ?? "";
const mode = applicationAliases[String(rawMode).trim().toLowerCase()] ?? "word";
return applicationModes[mode];
}
function createApplicationMenu(applicationMode) {
const isMac = process.platform === "darwin";
const template = [
...(isMac
? [
{
label: "QOffice",
label: applicationMode.title,
submenu: [
{ role: "about", label: "О QOffice" },
{ role: "about", label: `О ${applicationMode.title}` },
{ type: "separator" },
{ role: "hide", label: "Скрыть QOffice" },
{ role: "hide", label: `Скрыть ${applicationMode.title}` },
{ role: "hideOthers", label: "Скрыть остальные" },
{ role: "unhide", label: "Показать все" },
{ type: "separator" },
{ role: "quit", label: "Выйти из QOffice" }
{ role: "quit", label: `Выйти из ${applicationMode.title}` }
]
}
]
@@ -95,7 +145,7 @@ function createApplicationMenu() {
{ type: "separator" },
{ label: "Печать...", accelerator: "CmdOrCtrl+P", click: () => sendFocusedCommand("print") },
{ type: "separator" },
isMac ? { role: "close", label: "Закрыть окно" } : { role: "quit", label: "Выход" }
isMac ? { role: "close", label: "Закрыть окно" } : { role: "quit", label: `Выход из ${applicationMode.title}` }
]
},
{
@@ -213,13 +263,13 @@ ipcMain.handle("qoffice:export-pdf", async (event, defaultFileName) => {
};
});
function createWindow() {
function createWindow(applicationMode) {
const mainWindow = new BrowserWindow({
width: 1440,
height: 920,
minWidth: 1080,
minHeight: 720,
title: "QOffice",
title: applicationMode.windowTitle,
backgroundColor: "#f6f8fb",
webPreferences: {
preload: path.join(__dirname, "preload.cjs"),
@@ -234,19 +284,22 @@ function createWindow() {
});
if (isDev) {
mainWindow.loadURL("http://127.0.0.1:5173");
mainWindow.loadURL(new URL(applicationMode.route, "http://127.0.0.1:5173").toString());
} else {
mainWindow.loadFile(path.join(__dirname, "../dist/index.html"));
mainWindow.loadFile(path.join(__dirname, "../dist/index.html"), { hash: applicationMode.route });
}
}
const launchApplicationMode = applicationModeFromArgs();
app.setName(launchApplicationMode.title);
app.whenReady().then(() => {
createApplicationMenu();
createWindow();
createApplicationMenu(launchApplicationMode);
createWindow(launchApplicationMode);
app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
createWindow(launchApplicationMode);
}
});
});