diff --git a/build/electron-vite-vue-ts.png b/build/electron-vite-vue-ts.png new file mode 100644 index 0000000..a4de429 Binary files /dev/null and b/build/electron-vite-vue-ts.png differ diff --git a/build/entitlements.mac.plist b/build/entitlements.mac.plist new file mode 100644 index 0000000..38c887b --- /dev/null +++ b/build/entitlements.mac.plist @@ -0,0 +1,12 @@ + + + + + com.apple.security.cs.allow-jit + + com.apple.security.cs.allow-unsigned-executable-memory + + com.apple.security.cs.allow-dyld-environment-variables + + + diff --git a/build/icon.icns b/build/icon.icns new file mode 100644 index 0000000..28644aa Binary files /dev/null and b/build/icon.icns differ diff --git a/build/icon.ico b/build/icon.ico new file mode 100644 index 0000000..72c391e Binary files /dev/null and b/build/icon.ico differ diff --git a/build/icon.png b/build/icon.png new file mode 100644 index 0000000..cf9e8b2 Binary files /dev/null and b/build/icon.png differ diff --git a/electron-builder.yml b/electron-builder.yml new file mode 100644 index 0000000..78c24b7 --- /dev/null +++ b/electron-builder.yml @@ -0,0 +1,43 @@ +appId: com.electron.app +productName: electron-app +directories: + buildResources: build +files: + - "!**/.vscode/*" + - "!src/*" + - "!electron.vite.config.{js,ts,mjs,cjs}" + - "!{.eslintignore,.eslintrc.cjs,.prettierignore,.prettierrc.yaml,dev-app-update.yml,CHANGELOG.md,README.md}" + - "!{.env,.env.*,.npmrc,pnpm-lock.yaml}" + - "!{tsconfig.json,tsconfig.node.json,tsconfig.web.json}" +asarUnpack: + - resources/** +win: + executableName: electron-app +nsis: + artifactName: ${name}-${version}-setup.${ext} + shortcutName: ${productName} + uninstallDisplayName: ${productName} + createDesktopShortcut: always +mac: + entitlementsInherit: build/entitlements.mac.plist + extendInfo: + - NSCameraUsageDescription: Application requests access to the device's camera. + - NSMicrophoneUsageDescription: Application requests access to the device's microphone. + - NSDocumentsFolderUsageDescription: Application requests access to the user's Documents folder. + - NSDownloadsFolderUsageDescription: Application requests access to the user's Downloads folder. + notarize: false +dmg: + artifactName: ${name}-${version}.${ext} +linux: + target: + - AppImage + maintainer: electronjs.org + category: Utility +appImage: + artifactName: ${name}-${version}.${ext} +npmRebuild: false +publish: + provider: generic + url: https://example.com/auto-updates +electronDownload: + mirror: https://npmmirror.com/mirrors/electron/ diff --git a/electron.vite.config.ts b/electron.vite.config.ts new file mode 100644 index 0000000..98ae2c6 --- /dev/null +++ b/electron.vite.config.ts @@ -0,0 +1,18 @@ +import { resolve } from 'path' +import { defineConfig, externalizeDepsPlugin, bytecodePlugin } from 'electron-vite' + +export default defineConfig({ + main: { + plugins: [externalizeDepsPlugin(), bytecodePlugin()] + }, + preload: { + plugins: [externalizeDepsPlugin(), bytecodePlugin()] + }, + renderer: { + resolve: { + alias: { + '@renderer': resolve('src/renderer/src') + } + }, + } +}) diff --git a/package.json b/package.json new file mode 100644 index 0000000..efeec73 --- /dev/null +++ b/package.json @@ -0,0 +1,32 @@ +{ + "name": "electron-app", + "version": "1.0.0", + "description": "An Electron application with Vue and TypeScript", + "main": "./out/main/index.js", + "author": "example.com", + "homepage": "https://electron-vite.org", + "scripts": { + "format": "prettier --write .", + "start": "electron-vite preview", + "dev": "electron-vite dev", + "build": "electron-vite build", + "postinstall": "electron-builder install-app-deps", + "build:unpack": "npm run build && electron-builder --dir", + "build:win": "npm run build && electron-builder --win", + "build:mac": "npm run build && electron-builder --mac", + "build:linux": "npm run build && electron-builder --linux" + }, + "dependencies": { + "@electron-toolkit/preload": "^3.0.1", + "@electron-toolkit/utils": "^3.0.0" + }, + "devDependencies": { + "@electron-toolkit/tsconfig": "^1.0.1", + "@types/node": "^20.14.12", + "electron": "^31.3.0", + "electron-builder": "^24.13.3", + "electron-vite": "^2.3.0", + "typescript": "^5.5.4", + "vite": "^5.3.5" + } +} diff --git a/resources/icon.png b/resources/icon.png new file mode 100644 index 0000000..cf9e8b2 Binary files /dev/null and b/resources/icon.png differ diff --git a/src/main/index.ts b/src/main/index.ts new file mode 100644 index 0000000..ff3b8a4 --- /dev/null +++ b/src/main/index.ts @@ -0,0 +1,74 @@ +import { app, shell, BrowserWindow, ipcMain } from 'electron' +import { join } from 'path' +import { electronApp, optimizer, is } from '@electron-toolkit/utils' +import icon from '../../resources/icon.png?asset' + +function createWindow(): void { + // Create the browser window. + const mainWindow = new BrowserWindow({ + width: 900, + height: 670, + show: false, + autoHideMenuBar: true, + ...(process.platform === 'linux' ? { icon } : {}), + webPreferences: { + preload: join(__dirname, '../preload/index.js'), + sandbox: false + } + }) + + mainWindow.on('ready-to-show', () => { + mainWindow.show() + }) + + mainWindow.webContents.setWindowOpenHandler((details) => { + shell.openExternal(details.url) + return { action: 'deny' } + }) + + // HMR for renderer base on electron-vite cli. + // Load the remote URL for development or the local html file for production. + if (is.dev && process.env['ELECTRON_RENDERER_URL']) { + mainWindow.loadURL(process.env['ELECTRON_RENDERER_URL']) + } else { + mainWindow.loadFile(join(__dirname, '../renderer/index.html')) + } +} + +// This method will be called when Electron has finished +// initialization and is ready to create browser windows. +// Some APIs can only be used after this event occurs. +app.whenReady().then(() => { + // Set app user model id for windows + electronApp.setAppUserModelId('com.electron') + + // Default open or close DevTools by F12 in development + // and ignore CommandOrControl + R in production. + // see https://github.com/alex8088/electron-toolkit/tree/master/packages/utils + app.on('browser-window-created', (_, window) => { + optimizer.watchWindowShortcuts(window) + }) + + // IPC test + ipcMain.on('ping', () => console.log('pong')) + + createWindow() + + app.on('activate', function () { + // On macOS it's common to re-create a window in the app when the + // dock icon is clicked and there are no other windows open. + if (BrowserWindow.getAllWindows().length === 0) createWindow() + }) +}) + +// Quit when all windows are closed, except on macOS. There, it's common +// for applications and their menu bar to stay active until the user quits +// explicitly with Cmd + Q. +app.on('window-all-closed', () => { + if (process.platform !== 'darwin') { + app.quit() + } +}) + +// In this file you can include the rest of your app"s specific main process +// code. You can also put them in separate files and require them here. diff --git a/src/preload/index.d.ts b/src/preload/index.d.ts new file mode 100644 index 0000000..a153669 --- /dev/null +++ b/src/preload/index.d.ts @@ -0,0 +1,8 @@ +import { ElectronAPI } from '@electron-toolkit/preload' + +declare global { + interface Window { + electron: ElectronAPI + api: unknown + } +} diff --git a/src/preload/index.ts b/src/preload/index.ts new file mode 100644 index 0000000..2d18524 --- /dev/null +++ b/src/preload/index.ts @@ -0,0 +1,22 @@ +import { contextBridge } from 'electron' +import { electronAPI } from '@electron-toolkit/preload' + +// Custom APIs for renderer +const api = {} + +// Use `contextBridge` APIs to expose Electron APIs to +// renderer only if context isolation is enabled, otherwise +// just add to the DOM global. +if (process.contextIsolated) { + try { + contextBridge.exposeInMainWorld('electron', electronAPI) + contextBridge.exposeInMainWorld('api', api) + } catch (error) { + console.error(error) + } +} else { + // @ts-ignore (define in dts) + window.electron = electronAPI + // @ts-ignore (define in dts) + window.api = api +} diff --git a/index.html b/src/renderer/index.html similarity index 100% rename from index.html rename to src/renderer/index.html diff --git a/subtitle/Black.Mirror.Bandersnatch.2018-arabic.vtt b/src/renderer/subtitle/Black.Mirror.Bandersnatch.2018-arabic.vtt similarity index 100% rename from subtitle/Black.Mirror.Bandersnatch.2018-arabic.vtt rename to src/renderer/subtitle/Black.Mirror.Bandersnatch.2018-arabic.vtt diff --git a/subtitle/Black.Mirror.Bandersnatch.2018.720p.WEBRip.XviD.AC3-FGT-Hungarian.vtt b/src/renderer/subtitle/Black.Mirror.Bandersnatch.2018.720p.WEBRip.XviD.AC3-FGT-Hungarian.vtt similarity index 100% rename from subtitle/Black.Mirror.Bandersnatch.2018.720p.WEBRip.XviD.AC3-FGT-Hungarian.vtt rename to src/renderer/subtitle/Black.Mirror.Bandersnatch.2018.720p.WEBRip.XviD.AC3-FGT-Hungarian.vtt diff --git a/subtitle/Black.Mirror.Bandersnatch.2018.720p.espanish.vtt b/src/renderer/subtitle/Black.Mirror.Bandersnatch.2018.720p.espanish.vtt similarity index 100% rename from subtitle/Black.Mirror.Bandersnatch.2018.720p.espanish.vtt rename to src/renderer/subtitle/Black.Mirror.Bandersnatch.2018.720p.espanish.vtt diff --git a/subtitle/Black.Mirror.Bandersnatch.2018.MULTi.1080p.NF.WEB-DL.x264-NSP_track9_[fre].vtt b/src/renderer/subtitle/Black.Mirror.Bandersnatch.2018.MULTi.1080p.NF.WEB-DL.x264-NSP_track9_[fre].vtt similarity index 100% rename from subtitle/Black.Mirror.Bandersnatch.2018.MULTi.1080p.NF.WEB-DL.x264-NSP_track9_[fre].vtt rename to src/renderer/subtitle/Black.Mirror.Bandersnatch.2018.MULTi.1080p.NF.WEB-DL.x264-NSP_track9_[fre].vtt diff --git a/subtitle/Black.Mirror.Bandersnatch.2018.WEBRip.720p.portuguese.vtt b/src/renderer/subtitle/Black.Mirror.Bandersnatch.2018.WEBRip.720p.portuguese.vtt similarity index 100% rename from subtitle/Black.Mirror.Bandersnatch.2018.WEBRip.720p.portuguese.vtt rename to src/renderer/subtitle/Black.Mirror.Bandersnatch.2018.WEBRip.720p.portuguese.vtt diff --git a/subtitle/Black.Mirror.Bandersnatch.2018.WEBRip.Netflix.German.vtt b/src/renderer/subtitle/Black.Mirror.Bandersnatch.2018.WEBRip.Netflix.German.vtt similarity index 100% rename from subtitle/Black.Mirror.Bandersnatch.2018.WEBRip.Netflix.German.vtt rename to src/renderer/subtitle/Black.Mirror.Bandersnatch.2018.WEBRip.Netflix.German.vtt diff --git a/subtitle/Black.Mirror.Bandersnatch.2018.WEBRip.x264-NoGRP-Indonesian-vtt-sharp.vtt b/src/renderer/subtitle/Black.Mirror.Bandersnatch.2018.WEBRip.x264-NoGRP-Indonesian-vtt-sharp.vtt similarity index 100% rename from subtitle/Black.Mirror.Bandersnatch.2018.WEBRip.x264-NoGRP-Indonesian-vtt-sharp.vtt rename to src/renderer/subtitle/Black.Mirror.Bandersnatch.2018.WEBRip.x264-NoGRP-Indonesian-vtt-sharp.vtt diff --git a/subtitle/Black.Mirror.Bandersnatch.2018.WEBRip.x264-NoGRP-persian-vtt-sharp.vtt b/src/renderer/subtitle/Black.Mirror.Bandersnatch.2018.WEBRip.x264-NoGRP-persian-vtt-sharp.vtt similarity index 100% rename from subtitle/Black.Mirror.Bandersnatch.2018.WEBRip.x264-NoGRP-persian-vtt-sharp.vtt rename to src/renderer/subtitle/Black.Mirror.Bandersnatch.2018.WEBRip.x264-NoGRP-persian-vtt-sharp.vtt diff --git a/subtitle/Black.Mirror.Bandersnatch.2018.WEBRip.x264-NoGRP.vtt b/src/renderer/subtitle/Black.Mirror.Bandersnatch.2018.WEBRip.x264-NoGRP.vtt similarity index 100% rename from subtitle/Black.Mirror.Bandersnatch.2018.WEBRip.x264-NoGRP.vtt rename to src/renderer/subtitle/Black.Mirror.Bandersnatch.2018.WEBRip.x264-NoGRP.vtt diff --git a/subtitle/Black.Mirror.Bandersnatch.2018.Web-05.12.14-NF-UniHebSubs-hebrew.vtt b/src/renderer/subtitle/Black.Mirror.Bandersnatch.2018.Web-05.12.14-NF-UniHebSubs-hebrew.vtt similarity index 100% rename from subtitle/Black.Mirror.Bandersnatch.2018.Web-05.12.14-NF-UniHebSubs-hebrew.vtt rename to src/renderer/subtitle/Black.Mirror.Bandersnatch.2018.Web-05.12.14-NF-UniHebSubs-hebrew.vtt diff --git a/subtitle/Black.Mirror_.Bandersnatch.French.WEBRip.Netflix.vtt b/src/renderer/subtitle/Black.Mirror_.Bandersnatch.French.WEBRip.Netflix.vtt similarity index 100% rename from subtitle/Black.Mirror_.Bandersnatch.French.WEBRip.Netflix.vtt rename to src/renderer/subtitle/Black.Mirror_.Bandersnatch.French.WEBRip.Netflix.vtt diff --git a/subtitle/BlackMirror.Bandersnatch-Turkish.vtt b/src/renderer/subtitle/BlackMirror.Bandersnatch-Turkish.vtt similarity index 100% rename from subtitle/BlackMirror.Bandersnatch-Turkish.vtt rename to src/renderer/subtitle/BlackMirror.Bandersnatch-Turkish.vtt diff --git a/subtitle/BlackMirror.Bandersnatch-russian.vtt b/src/renderer/subtitle/BlackMirror.Bandersnatch-russian.vtt similarity index 100% rename from subtitle/BlackMirror.Bandersnatch-russian.vtt rename to src/renderer/subtitle/BlackMirror.Bandersnatch-russian.vtt diff --git a/subtitle/Czarne.lustro_.Bandersnatch.WEBRip.Netflix.pl.vtt b/src/renderer/subtitle/Czarne.lustro_.Bandersnatch.WEBRip.Netflix.pl.vtt similarity index 100% rename from subtitle/Czarne.lustro_.Bandersnatch.WEBRip.Netflix.pl.vtt rename to src/renderer/subtitle/Czarne.lustro_.Bandersnatch.WEBRip.Netflix.pl.vtt diff --git a/subtitle/[SubtitleTools.com] Black.Mirror.Bandersnatch.2018.REPACK.1080p.WEB.X264-DEFLATE.Korean.vtt b/src/renderer/subtitle/[SubtitleTools.com] Black.Mirror.Bandersnatch.2018.REPACK.1080p.WEB.X264-DEFLATE.Korean.vtt similarity index 100% rename from subtitle/[SubtitleTools.com] Black.Mirror.Bandersnatch.2018.REPACK.1080p.WEB.X264-DEFLATE.Korean.vtt rename to src/renderer/subtitle/[SubtitleTools.com] Black.Mirror.Bandersnatch.2018.REPACK.1080p.WEB.X264-DEFLATE.Korean.vtt diff --git a/subtitle/black-mirror-bandersnatch-2018-nf-web-dl-720p-greek.vtt b/src/renderer/subtitle/black-mirror-bandersnatch-2018-nf-web-dl-720p-greek.vtt similarity index 100% rename from subtitle/black-mirror-bandersnatch-2018-nf-web-dl-720p-greek.vtt rename to src/renderer/subtitle/black-mirror-bandersnatch-2018-nf-web-dl-720p-greek.vtt diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..31bac6e --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,4 @@ +{ + "files": [], + "references": [{ "path": "./tsconfig.node.json" }, { "path": "./tsconfig.web.json" }] +} diff --git a/tsconfig.node.json b/tsconfig.node.json new file mode 100644 index 0000000..db23a68 --- /dev/null +++ b/tsconfig.node.json @@ -0,0 +1,8 @@ +{ + "extends": "@electron-toolkit/tsconfig/tsconfig.node.json", + "include": ["electron.vite.config.*", "src/main/**/*", "src/preload/**/*"], + "compilerOptions": { + "composite": true, + "types": ["electron-vite/node"] + } +} diff --git a/tsconfig.web.json b/tsconfig.web.json new file mode 100644 index 0000000..a43cbe0 --- /dev/null +++ b/tsconfig.web.json @@ -0,0 +1,17 @@ +{ + "extends": "@electron-toolkit/tsconfig/tsconfig.web.json", + "include": [ + "src/renderer/src/env.d.ts", + "src/renderer/src/**/*", + "src/preload/*.d.ts" + ], + "compilerOptions": { + "composite": true, + "baseUrl": ".", + "paths": { + "@renderer/*": [ + "src/renderer/src/*" + ] + } + } +} \ No newline at end of file