Skip to content

Commit

Permalink
feat: 忘了
Browse files Browse the repository at this point in the history
  • Loading branch information
maotoumao committed Jun 26, 2023
1 parent d0b5e98 commit 45730bc
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 34 deletions.
3 changes: 2 additions & 1 deletion forge.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ const config: ForgeConfig = {
icon: path.resolve(__dirname, "resources/logo"),
executableName: "MusicFree",
extraResource: [
path.resolve(__dirname, 'res')
path.resolve(__dirname, 'res'),

],
},
rebuildConfig: {},
Expand Down
20 changes: 3 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"axios": "^1.4.0",
"big-integer": "^1.6.51",
"cheerio": "^1.0.0-rc.12",
"chokidar": "^3.5.3",
"color": "^4.2.3",
"compare-versions": "^6.0.0-rc.1",
"crypto-js": "^4.1.1",
Expand Down
1 change: 1 addition & 0 deletions src/common/app-config/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ async function checkPath() {

export async function setupMainAppConfig() {
await checkPath();
await getAppConfig();
ipcMainHandle('sync-app-config', () => {
return getAppConfig();
})
Expand Down
4 changes: 4 additions & 0 deletions src/common/app-config/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ interface IConfig {
backup: {
test: never;
};
/** 本地音乐配置 */
localMusic: {
watchDir: string[];
}
}

type BasicType = string | number | symbol | null | undefined;
Expand Down
4 changes: 4 additions & 0 deletions src/common/ipc-util/eventType/renderer-events.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,9 @@ declare namespace IpcInvoke {
options: Electron.OpenDialogOptions
) => Electron.OpenDialogReturnValue;
'check-update': () => ICommon.IUpdateInfo;
/** 本地文件 */
'sync-local-file': () => void;
'add-watch-dir': (dirs: string[]) => void;
'remove-watch-dir': (dirs: string[]) => void;
}
}
15 changes: 15 additions & 0 deletions src/main/core/local-music-manager/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// import { Worker } from "worker_threads";
// import path from "path";

export async function setupLocalMusicManager() {

// const worker: Worker = new Worker(new URL(
// /* webpackChunkName: 'scannerWorker' */
// './scanner.worker',
// import.meta.url,
// ))
// worker.on('message', (data) => {
// console.log(data)
// })
}

16 changes: 16 additions & 0 deletions src/main/core/local-music-manager/scanner.worker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// /***** thread ******/
// import { parentPort } from "worker_threads";
// import * as chokidar from 'chokidar';
// import { supportLocalMediaType } from "@/common/constant";

// let watchDirs: string[] = [];
// // const glob = supportLocalMediaType.map()

// // chokidar.watch(watchDirs, {
// // "ignorePermissionErrors": true,
// // }).on('change', )


// parentPort.postMessage({
// hi: "sdds"
// });
12 changes: 7 additions & 5 deletions src/main/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { app, BrowserWindow, screen } from "electron";
import { app, BrowserWindow } from "electron";
import { createMainWindow, getMainWindow, showWindow } from "./window";
import setupIpcMain from "./ipc";
import { setupPluginManager } from "./core/plugin-manager";
import { setupMainAppConfig } from "@/common/app-config/main";
import { setupTray } from "./tray";
import { setupLocalMusicManager } from "./core/local-music-manager";

// Handle creating/removing shortcuts on Windows when installing/uninstalling.
if (require("electron-squirrel-startup")) {
app.quit();
}
// if (require("electron-squirrel-startup")) {
// app.quit();
// }

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
Expand Down Expand Up @@ -47,7 +48,8 @@ app.on('second-instance', () => {
// code. You can also put them in separate files and import them here.
app.whenReady().then(() => {
setupIpcMain();
setupPluginManager();
setupMainAppConfig();
setupPluginManager();
setupTray();
setupLocalMusicManager();
})
12 changes: 2 additions & 10 deletions src/main/tray/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,16 @@ import {
Tray,
app,
} from "electron";
import path from "path";
import { showWindow } from "../window";
import { currentMusicInfoStore } from "../store/current-music";
import { PlayerState, RepeatMode } from "@/renderer/core/track-player/enum";
import { ipcMainSendMainWindow } from "@/common/ipc-util/main";
import { getResPath } from "../util";

let tray: Tray | null = null;

const resourcesPath = app.isPackaged
? path.resolve(process.resourcesPath, "res")
: path.resolve(__dirname, "../../res");

const getResourcePath = (resourceName: string) => {
return path.resolve(resourcesPath, resourceName);
};

export function setupTray() {
const iconPath = getResourcePath("logo.ico");
const iconPath = getResPath("logo.ico");

tray = new Tray(iconPath);

Expand Down
10 changes: 10 additions & 0 deletions src/main/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { app } from "electron";
import path from 'path';

const resPath = app.isPackaged
? path.resolve(process.resourcesPath, "res")
: path.resolve(__dirname, "../../res");

export const getResPath = (resourceName: string) => {
return path.resolve(resPath, resourceName);
};
2 changes: 2 additions & 0 deletions src/main/window/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { localPluginName } from "@/common/constant";
import { BrowserWindow, app } from "electron";
import { getResPath } from "../util";

// This allows TypeScript to pick up the magic constants that's auto-generated by Forge's Webpack
// plugin that tells the Electron app where to look for the Webpack-bundled app code (depending on
Expand All @@ -22,6 +23,7 @@ export const createMainWindow = (): BrowserWindow => {
},
resizable: false,
frame: false,
icon: getResPath("logo.ico")
});

// and load the index.html of the app.
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"jsx": "react-jsx",
"target": "ES6",
"target": "ES2021",
"allowJs": true,
"module": "commonjs",
"skipLibCheck": true,
Expand Down

0 comments on commit 45730bc

Please sign in to comment.