You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.3 KiB
JavaScript

import { app, BrowserWindow, ipcMain } from "electron";
import path from "path";
import { fileURLToPath } from "url";
const __filename$1 = fileURLToPath(import.meta.url);
const __dirname$1 = path.dirname(__filename$1);
let mainWindow = null;
const isDev = process.env.NODE_ENV === "development";
const createWindow = () => {
mainWindow = new BrowserWindow({
width: 600,
height: 800,
webPreferences: {
nodeIntegration: false,
contextIsolation: true
// preload: path.join(__dirname, '../../../dist-electron/preload/index.js'),
},
autoHideMenuBar: true
});
if (process.env.VITE_DEV_SERVER_URL) {
mainWindow.loadURL(process.env.VITE_DEV_SERVER_URL);
} else {
mainWindow.loadFile(path.join(__dirname$1, "../../dist/index.html"));
}
if (isDev) {
mainWindow.webContents.openDevTools();
}
};
app.whenReady().then(() => {
createWindow();
app.on("activate", function() {
if (BrowserWindow.getAllWindows().length === 0) createWindow();
});
});
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
});
ipcMain.handle("print-ticket", async (event, ticketInfo) => {
console.log("打印小票:", ticketInfo, event);
await new Promise((resolve) => setTimeout(resolve, 1e3));
return {
success: true,
message: "小票打印成功"
};
});