Skip to content

Commit

Permalink
Merge pull request #91 from caorushizi/dev/plugins
Browse files Browse the repository at this point in the history
style: 💄 eslint
  • Loading branch information
caorushizi authored Feb 24, 2024
2 parents 004fd56 + 178f748 commit 55f538d
Show file tree
Hide file tree
Showing 96 changed files with 1,365 additions and 2,836 deletions.
2 changes: 1 addition & 1 deletion .env.development
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
APP_TD_APPID=
APP_CLARITY_APPID=
APP_DOWNLOAD_DEBUG=true

GH_TOKEN=
LOAD_DEVTOOLS=
DEBUG_PLUGINS=false
1 change: 0 additions & 1 deletion .env.production
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
APP_TD_APPID=
APP_CLARITY_APPID=
APP_DOWNLOAD_DEBUG=

GH_TOKEN=
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"dev": "tsno run scripts/dev.ts && pnpm --parallel -F \"./packages/*\" run dev",
"build": "tsno run scripts/build.ts",
"build:mobile": "pnpm -F mobile run build",
"build:player": "pnpm -F player run build",
"build:plugin": "pnpm -F plugin run build",
"build:main": "pnpm -F main run build",
"build:renderer": "pnpm -F renderer run build",
Expand Down
4 changes: 2 additions & 2 deletions packages/main/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
extends: [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"prettier",
"plugin:prettier/recommended",
],
overrides: [],
ignorePatterns: ["app"],
Expand All @@ -15,7 +15,7 @@ module.exports = {
ecmaVersion: "latest",
sourceType: "module",
},
plugins: ["@typescript-eslint", "prettier"],
plugins: ["@typescript-eslint"],
rules: {
"prettier/prettier": "warn",
"@typescript-eslint/no-explicit-any": "warn",
Expand Down
Binary file modified packages/main/bin/win32/BBDown.exe
Binary file not shown.
Empty file removed packages/main/bin/win32/NO_UPDATE
Empty file.
Binary file removed packages/main/bin/win32/N_m3u8DL-CLI.exe
Binary file not shown.
Binary file added packages/main/bin/win32/N_m3u8DL-RE.exe
Binary file not shown.
11 changes: 6 additions & 5 deletions packages/main/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
"@types/fs-extra": "^11.0.4",
"@types/lodash": "^4.14.202",
"@types/node": "^20.11.5",
"@typescript-eslint/eslint-plugin": "6.19.0",
"@typescript-eslint/parser": "6.19.0",
"@types/semver": "^7.5.6",
"@typescript-eslint/eslint-plugin": "6.21.0",
"@typescript-eslint/parser": "6.21.0",
"chokidar": "^3.5.3",
"cross-env": "^7.0.3",
"dotenv": "^16.3.2",
Expand All @@ -36,15 +37,14 @@
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-promise": "6.1.1",
"prebuild-install": "^7.1.1",
"prettier": "3.2.4",
"prettier": "3.2.5",
"semver": "^7.5.4",
"typescript": "^5.3.3",
"vite": "^5.0.12"
},
"dependencies": {
"@cliqz/adblocker-electron": "^1.26.15",
"@cliqz/adblocker-electron-preload": "^1.26.15",
"@types/semver": "^7.5.6",
"axios": "^1.6.5",
"better-sqlite3": "^9.3.0",
"cheerio": "1.0.0-rc.12",
Expand All @@ -56,10 +56,11 @@
"electron-store": "^8.1.0",
"execa": "^8.0.1",
"fs-extra": "^11.2.0",
"iconv-lite": "^0.6.3",
"inversify": "^6.0.2",
"lodash": "^4.17.21",
"node-pty": "^1.0.0",
"reflect-metadata": "^0.2.1",
"strip-ansi": "^7.1.0",
"ts-node": "^10.9.2",
"typeorm": "^0.3.19"
}
Expand Down
1 change: 1 addition & 0 deletions packages/main/scripts/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export const external = [
"aws-sdk",
"mock-aws-s3",
"@cliqz/adblocker-electron-preload",
"node-pty",
];
52 changes: 30 additions & 22 deletions packages/main/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,60 @@ import { Menu, Tray, app, nativeImage, nativeTheme } from "electron";
import TrayIcon from "./tray-icon.png";
import path from "path";
import MainWindow from "./windows/MainWindow";
import ProtocolService from "./services/ProtocolService";
import UpdateService from "./services/UpdateService";
import IpcHandlerService from "./services/IpcHandlerService";
import DatabaseService from "./services/DatabaseService";
import WebviewService from "./services/WebviewService";
import DevToolsService from "./services/DevToolsService";
import StoreService from "./services/StoreService";
import VideoRepository from "./repository/VideoRepository";
import VideoService from "./services/VideoService";
import ElectronDevtools from "./vendor/ElectronDevtools";
import ElectronStore from "./vendor/ElectronStore";
import ElectronUpdater from "./vendor/ElectronUpdater";
import TypeORM from "./vendor/TypeORM";
import ProtocolService from "./core/protocol";
import IpcHandlerService from "./core/ipc";

@injectable()
export default class ElectronApp {
constructor(
@inject(TYPES.MainWindow)
private readonly mainWindow: MainWindow,
@inject(TYPES.ProtocolService)
private readonly protocolService: ProtocolService,
@inject(TYPES.UpdateService)
private readonly updateService: UpdateService,
private readonly protocol: ProtocolService,
@inject(TYPES.ElectronUpdater)
private readonly updater: ElectronUpdater,
@inject(TYPES.IpcHandlerService)
private readonly ipcHandler: IpcHandlerService,
@inject(TYPES.DatabaseService)
private readonly dataService: DatabaseService,
private readonly ipc: IpcHandlerService,
@inject(TYPES.TypeORM)
private readonly db: TypeORM,
@inject(TYPES.WebviewService)
private readonly webview: WebviewService,
@inject(TYPES.VideoRepository)
private readonly videoRepository: VideoRepository,
@inject(TYPES.DevToolsService)
private readonly devTools: DevToolsService,
@inject(TYPES.StoreService)
private readonly storeService: StoreService,
@inject(TYPES.ElectronDevtools)
private readonly devTools: ElectronDevtools,
@inject(TYPES.ElectronStore)
private readonly store: ElectronStore,
@inject(TYPES.VideoService)
private readonly videoService: VideoService,
) {}

private async seriveInit(): Promise<void> {
this.protocolService.create();
await this.dataService.init();
this.mainWindow.init();
this.ipcHandler.init();
this.updateService.init();
this.webview.init(), this.devTools.init();
this.webview.init();
this.videoService.init();
}

private async vendorInit() {
await this.db.init();
this.updater.init();
this.devTools.init();
}

async init(): Promise<void> {
this.protocol.create();
this.ipc.init();

// vendor
await this.vendorInit();
// service
await this.seriveInit();

app.on("activate", () => {
Expand All @@ -64,7 +72,7 @@ export default class ElectronApp {
}

initAppTheme(): void {
const theme = this.storeService.get("theme");
const theme = this.store.get("theme");
nativeTheme.themeSource = theme;
}

Expand Down
14 changes: 6 additions & 8 deletions packages/main/src/controller/DownloadController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@ import {
DownloadStatus,
} from "../interfaces";
import { TYPES } from "../types";
import { downloader } from "../helper";
import MainWindow from "../windows/MainWindow";
import StoreService from "../services/StoreService";
import ElectronStore from "../vendor/ElectronStore";
import DownloadService from "../services/DownloadService";
import VideoRepository from "../repository/VideoRepository";
import { existsSync } from "fs-extra";

@injectable()
export default class DownloadController implements Controller {
constructor(
@inject(TYPES.StoreService)
private readonly storeService: StoreService,
@inject(TYPES.ElectronStore)
private readonly store: ElectronStore,
@inject(TYPES.VideoRepository)
private readonly videoRepository: VideoRepository,
@inject(TYPES.DownloadService)
Expand Down Expand Up @@ -62,7 +61,7 @@ export default class DownloadController implements Controller {

@handle("get-download-items")
async getDownloadItems(e: IpcMainEvent, pagination: DownloadItemPagination) {
const localDir = this.storeService.get("local");
const localDir = this.store.get("local");
const videos = await this.videoRepository.findVideos(pagination);
const newVideos = videos.list.map((video) => {
if (video.status === DownloadStatus.Success) {
Expand All @@ -88,10 +87,10 @@ export default class DownloadController implements Controller {
return Promise.reject("没有找到该视频");
}
const { name, url, headers, type } = video;
const local = this.storeService.get("local");
const local = this.store.get("local");

// 从配置中添加参数
const deleteSegments = this.storeService.get("deleteSegments");
const deleteSegments = this.store.get("deleteSegments");

const task: Task = {
id: vid,
Expand All @@ -103,7 +102,6 @@ export default class DownloadController implements Controller {
headers,
deleteSegments,
},
process: downloader,
};
await this.videoRepository.changeVideoStatus(vid, DownloadStatus.Watting);
this.downloadService.addTask(task);
Expand Down
31 changes: 11 additions & 20 deletions packages/main/src/controller/HomeController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ import { TYPES } from "../types";
import fs from "fs-extra";
import MainWindow from "../windows/MainWindow";
import BrowserWindow from "../windows/BrowserWindow";
import PlayerWindow from "../windows/PlayerWindow";
import StoreService from "../services/StoreService";
import ElectronStore from "../vendor/ElectronStore";
import WebviewService from "../services/WebviewService";
import FavoriteRepository from "../repository/FavoriteRepository";
import VideoRepository from "../repository/VideoRepository";
Expand All @@ -30,8 +29,8 @@ export default class HomeController implements Controller {
private sharedState: Record<string, any> = {};

constructor(
@inject(TYPES.StoreService)
private readonly storeService: StoreService,
@inject(TYPES.ElectronStore)
private readonly store: ElectronStore,
@inject(TYPES.FavoriteRepository)
private readonly favoriteRepository: FavoriteRepository,
@inject(TYPES.MainWindow)
Expand All @@ -40,8 +39,6 @@ export default class HomeController implements Controller {
private readonly videoRepository: VideoRepository,
@inject(TYPES.BrowserWindow)
private readonly browserWindow: BrowserWindow,
@inject(TYPES.PlayerWindow)
private readonly playerWindow: PlayerWindow,
@inject(TYPES.WebviewService)
private readonly webviewService: WebviewService,
) {}
Expand All @@ -53,7 +50,7 @@ export default class HomeController implements Controller {
dbPath: db,
workspace: workspace,
platform: process.platform,
local: this.storeService.get("local"),
local: this.store.get("local"),
};
}

Expand All @@ -74,7 +71,7 @@ export default class HomeController implements Controller {

@handle("get-app-store")
getAppStore() {
return this.storeService.store;
return this.store.store;
}

@handle("on-favorite-item-context-menu")
Expand Down Expand Up @@ -118,7 +115,7 @@ export default class HomeController implements Controller {

if (!result.canceled) {
const dir = result.filePaths[0];
this.storeService.set("local", dir);
this.store.set("local", dir);
return dir;
}
return "";
Expand All @@ -128,12 +125,12 @@ export default class HomeController implements Controller {
async setAppStore(e: IpcMainEvent, key: keyof AppStore, val: any) {
// useProxy
if (key === "useProxy") {
const proxy = this.storeService.get("proxy");
const proxy = this.store.get("proxy");
this.webviewService.setProxy(val, proxy);
}
// proxy
if (key === "proxy") {
const useProxy = this.storeService.get("useProxy");
const useProxy = this.store.get("useProxy");
useProxy && this.webviewService.setProxy(true, val);
}
// block
Expand All @@ -149,7 +146,7 @@ export default class HomeController implements Controller {
this.webviewService.setUserAgent(val);
}

this.storeService.set(key, val);
this.store.set(key, val);
}

@handle("open-dir")
Expand Down Expand Up @@ -215,7 +212,7 @@ export default class HomeController implements Controller {
@handle("convert-to-audio")
async convertToAudio(e: IpcMainEvent, id: number) {
const video = await this.videoRepository.findVideo(id);
const local = this.storeService.get("local");
const local = this.store.get("local");
const input = path.join(local, `${video?.name}.mp4`);
const output = path.join(local, `${video?.name}.mp3`);

Expand All @@ -237,13 +234,7 @@ export default class HomeController implements Controller {
// 关闭浏览器窗口
this.browserWindow.hideWindow();
// 修改设置中的属性
this.storeService.set("openInNewWindow", false);
}

@handle("open-player-window")
async openPlayerWindow(event: IpcMainEvent, name: string) {
// 打开播放器窗口
this.playerWindow.openWindow(name);
this.store.set("openInNewWindow", false);
}

@handle("get-local-ip")
Expand Down
8 changes: 4 additions & 4 deletions packages/main/src/controller/WebviewController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import { handle } from "../helper";
import { type Controller } from "../interfaces";
import { TYPES } from "../types";
import WebviewService from "../services/WebviewService";
import StoreService from "../services/StoreService";
import ElectronStore from "../vendor/ElectronStore";

@injectable()
export default class WebviewController implements Controller {
constructor(
@inject(TYPES.WebviewService)
private readonly webview: WebviewService,
@inject(TYPES.StoreService)
private readonly storeService: StoreService,
@inject(TYPES.ElectronStore)
private readonly store: ElectronStore,
) {}

@handle("set-webview-bounds")
Expand Down Expand Up @@ -75,6 +75,6 @@ export default class WebviewController implements Controller {
@handle("webview-change-user-agent")
async webviewChangeUserAgent(e: IpcMainEvent, isMobile: boolean) {
this.webview.setUserAgent(isMobile);
this.storeService.set("isMobile", isMobile);
this.store.set("isMobile", isMobile);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import { ipcMain } from "electron";
import { inject, injectable, multiInject } from "inversify";
import { Controller } from "../interfaces";
import { TYPES } from "../types";
import LoggerService from "./LoggerService";
import ElectronLogger from "../vendor/ElectronLogger";
import { error, success } from "../helper/utils";

@injectable()
export default class IpcHandlerService {
constructor(
@multiInject(TYPES.Controller)
private readonly controllers: Controller[],
@inject(TYPES.LoggerService)
private readonly logger: LoggerService,
@inject(TYPES.ElectronLogger)
private readonly logger: ElectronLogger,
) {}

private registerIpc(
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions packages/main/src/core/vendor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface Vendor {
init(): Promise<void>;
}
File renamed without changes.
Loading

0 comments on commit 55f538d

Please sign in to comment.