diff --git a/electron-builder.json b/electron-builder.json index f73a632..e140ae4 100644 --- a/electron-builder.json +++ b/electron-builder.json @@ -11,12 +11,12 @@ }, "win": { "target": "nsis", - "icon": "build/renderer/aniflix512.png" + "icon": "build/main/static/icon.png" }, "linux": { "target": ["deb"], "category": "Video", - "icon": "build/renderer/aniflix512.png" + "icon": "build/main/static/icon.png" }, "files": [ "build/main/**/*", diff --git a/scripts/build.js b/scripts/build.js index 4abd4bc..2e4c918 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -1,32 +1,45 @@ -const Path = require('path'); -const Chalk = require('chalk'); -const FileSystem = require('fs'); -const Vite = require('vite'); -const compileTs = require('./private/tsc'); +const Path = require("path"); +const Chalk = require("chalk"); +const FileSystem = require("fs"); +const Vite = require("vite"); +const compileTs = require("./private/tsc"); function buildRenderer() { - return Vite.build({ - configFile: Path.join(__dirname, '..', 'vite.config.js'), - base: './', - mode: 'production' - }); + return Vite.build({ + configFile: Path.join(__dirname, "..", "vite.config.js"), + base: "./", + mode: "production", + }); +} + +function copyStaticFiles() { + copy("static"); +} + +function copy(path) { + FileSystem.cpSync( + Path.join(__dirname, "..", "src", "main", path), + Path.join(__dirname, "..", "build", "main", path), + { recursive: true } + ); } function buildMain() { - const mainPath = Path.join(__dirname, '..', 'src', 'main'); - return compileTs(mainPath); + const mainPath = Path.join(__dirname, "..", "src", "main"); + return compileTs(mainPath); } -FileSystem.rmSync(Path.join(__dirname, '..', 'build'), { - recursive: true, - force: true, -}) +FileSystem.rmSync(Path.join(__dirname, "..", "build"), { + recursive: true, + force: true, +}); -console.log(Chalk.blueBright('Transpiling renderer & main...')); +console.log(Chalk.blueBright("Transpiling renderer & main...")); -Promise.allSettled([ - buildRenderer(), - buildMain(), -]).then(() => { - console.log(Chalk.greenBright('Renderer & main successfully transpiled! (ready to be built with electron-builder)')); +Promise.allSettled([buildRenderer(), buildMain(), copyStaticFiles()]).then(() => { + console.log( + Chalk.greenBright( + "Renderer & main successfully transpiled! (ready to be built with electron-builder)" + ) + ); }); diff --git a/src/main/main.ts b/src/main/main.ts index ea34829..8d0187d 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -4,15 +4,14 @@ import { ipcMain, OnHeadersReceivedListenerDetails, session, - Menu, - MenuItem, } from "electron"; import { join } from "path"; +import setApplicationMenu from "./menu"; function createWindow() { const mainWindow = new BrowserWindow({ show: false, - icon: join(__dirname, "./static/aniflix512.png"), + icon: join(__dirname, "./static/icon.png"), webPreferences: { preload: join(__dirname, "preload.js"), nodeIntegration: true, @@ -24,24 +23,7 @@ function createWindow() { mainWindow.maximize(); mainWindow.show(); - const menu = new Menu(); - menu.append( - new MenuItem({ - label: "Electron", - submenu: [ - { - role: "help", - accelerator: - process.platform === "darwin" ? "Alt+Cmd+I" : "Alt+Shift+I", - click: () => { - console.log("Electron rocks!"); - }, - }, - ], - }) - ); - - // Menu.setApplicationMenu(menu); + setApplicationMenu(); if (process.env.NODE_ENV === "development") { const rendererPort = process.argv[2]; @@ -77,7 +59,3 @@ app.whenReady().then(() => { app.on("window-all-closed", function () { if (process.platform !== "darwin") app.quit(); }); - -ipcMain.on("message", (event, message) => { - console.log(message); -}); diff --git a/src/main/menu.ts b/src/main/menu.ts new file mode 100644 index 0000000..e186976 --- /dev/null +++ b/src/main/menu.ts @@ -0,0 +1,40 @@ +import { Menu, MenuItem, MenuItemConstructorOptions, shell } from "electron"; + +export default function () { + const template: Array = [ + { + label: "Reload", + submenu: [{ role: "reload" }, { role: "forceReload" }], + }, + { + label: "View", + submenu: [ + { role: "resetZoom" }, + { role: "zoomIn" }, + { role: "zoomOut" }, + { role: "quit" }, + ], + }, + { + label: "Help", + submenu: [ + { + label: "Support", + click: () => { + shell.openExternal("https://github.com/sponsors/rizkhal"); + }, + }, + { + label: "Contact", + click: () => { + shell.openExternal("https://t.me/rizkhal"); + }, + }, + ], + }, + ]; + + let menu = Menu.buildFromTemplate(template); + + Menu.setApplicationMenu(menu); +} diff --git a/src/main/static/aniflix256.png b/src/main/static/aniflix256.png deleted file mode 100644 index 3c88876..0000000 Binary files a/src/main/static/aniflix256.png and /dev/null differ diff --git a/src/main/static/aniflix512.png b/src/main/static/aniflix512.png deleted file mode 100644 index a97d53d..0000000 Binary files a/src/main/static/aniflix512.png and /dev/null differ diff --git a/src/main/static/icon.png b/src/main/static/icon.png new file mode 100644 index 0000000..6e46aa3 Binary files /dev/null and b/src/main/static/icon.png differ diff --git a/src/renderer/layouts/ProtectedLayout.vue b/src/renderer/layouts/ProtectedLayout.vue index 96eea39..85c33f4 100644 --- a/src/renderer/layouts/ProtectedLayout.vue +++ b/src/renderer/layouts/ProtectedLayout.vue @@ -1,6 +1,30 @@