mirror of
https://github.com/antebudimir/feishin.git
synced 2026-01-08 05:31:39 +00:00
fix all imports for new structure
This commit is contained in:
parent
249eaf89f8
commit
930165d006
291 changed files with 2056 additions and 1894 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import { ipcMain } from 'electron';
|
||||
|
||||
import { store } from '../settings/index';
|
||||
import { store } from '../settings';
|
||||
import {
|
||||
getLyricsBySongId as getGenius,
|
||||
query as queryGenius,
|
||||
|
|
@ -17,6 +17,8 @@ import {
|
|||
getSearchResults as searchNetease,
|
||||
} from './netease';
|
||||
|
||||
import { Song } from '/@/shared/types/domain-types';
|
||||
|
||||
export enum LyricSource {
|
||||
GENIUS = 'Genius',
|
||||
LRCLIB = 'lrclib.net',
|
||||
|
|
@ -94,10 +96,10 @@ const MAX_CACHED_ITEMS = 10;
|
|||
|
||||
const lyricCache = new Map<string, CachedLyrics>();
|
||||
|
||||
const getRemoteLyrics = async (song: any) => {
|
||||
const getRemoteLyrics = async (song: Song) => {
|
||||
const sources = store.get('lyrics', []) as LyricSource[];
|
||||
|
||||
const cached = lyricCache.get(song.id);
|
||||
const cached = lyricCache.get(song.id.toString());
|
||||
|
||||
if (cached) {
|
||||
for (const source of sources) {
|
||||
|
|
@ -106,16 +108,16 @@ const getRemoteLyrics = async (song: any) => {
|
|||
}
|
||||
}
|
||||
|
||||
let lyricsFromSource = null;
|
||||
let lyricsFromSource: InternetProviderLyricResponse | null = null;
|
||||
|
||||
for (const source of sources) {
|
||||
const params = {
|
||||
album: song.album || song.name,
|
||||
artist: song.artistName,
|
||||
artist: song.artists[0].name,
|
||||
duration: song.duration / 1000.0,
|
||||
name: song.name,
|
||||
};
|
||||
const response = await FETCHERS[source](params);
|
||||
const response = await FETCHERS[source](params as unknown as LyricSearchQuery);
|
||||
|
||||
if (response) {
|
||||
const newResult = cached
|
||||
|
|
@ -127,10 +129,12 @@ const getRemoteLyrics = async (song: any) => {
|
|||
|
||||
if (lyricCache.size === MAX_CACHED_ITEMS && cached === undefined) {
|
||||
const toRemove = lyricCache.keys().next().value;
|
||||
lyricCache.delete(toRemove);
|
||||
if (toRemove) {
|
||||
lyricCache.delete(toRemove);
|
||||
}
|
||||
}
|
||||
|
||||
lyricCache.set(song.id, newResult);
|
||||
lyricCache.set(song.id.toString(), newResult);
|
||||
|
||||
lyricsFromSource = response;
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -13,37 +13,6 @@ const LYRICS_URL = 'https://music.163.com/api/song/lyric';
|
|||
|
||||
// Adapted from https://github.com/NyaomiDEV/Sunamu/blob/master/src/main/lyricproviders/netease.ts
|
||||
|
||||
export interface Album {
|
||||
artist: Artist;
|
||||
copyrightId: number;
|
||||
id: number;
|
||||
mark: number;
|
||||
name: string;
|
||||
picId: number;
|
||||
publishTime: number;
|
||||
size: number;
|
||||
status: number;
|
||||
transNames?: string[];
|
||||
}
|
||||
|
||||
export interface Artist {
|
||||
albumSize: number;
|
||||
alias: any[];
|
||||
fansGroup: null;
|
||||
id: number;
|
||||
img1v1: number;
|
||||
img1v1Url: string;
|
||||
name: string;
|
||||
picId: number;
|
||||
picUrl: null;
|
||||
trans: null;
|
||||
}
|
||||
|
||||
export interface NetEaseResponse {
|
||||
code: number;
|
||||
result: Result;
|
||||
}
|
||||
|
||||
export interface Result {
|
||||
hasMore: boolean;
|
||||
songCount: number;
|
||||
|
|
@ -68,6 +37,37 @@ export interface Song {
|
|||
transNames?: string[];
|
||||
}
|
||||
|
||||
interface Album {
|
||||
artist: Artist;
|
||||
copyrightId: number;
|
||||
id: number;
|
||||
mark: number;
|
||||
name: string;
|
||||
picId: number;
|
||||
publishTime: number;
|
||||
size: number;
|
||||
status: number;
|
||||
transNames?: string[];
|
||||
}
|
||||
|
||||
interface Artist {
|
||||
albumSize: number;
|
||||
alias: any[];
|
||||
fansGroup: null;
|
||||
id: number;
|
||||
img1v1: number;
|
||||
img1v1Url: string;
|
||||
name: string;
|
||||
picId: number;
|
||||
picUrl: null;
|
||||
trans: null;
|
||||
}
|
||||
|
||||
interface NetEaseResponse {
|
||||
code: number;
|
||||
result: Result;
|
||||
}
|
||||
|
||||
export async function getLyricsBySongId(songId: string): Promise<null | string> {
|
||||
let result: AxiosResponse<any, any>;
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import Fuse from 'fuse.js';
|
|||
import {
|
||||
InternetProviderLyricSearchResponse,
|
||||
LyricSearchQuery,
|
||||
} from '../../../../renderer/api/types';
|
||||
} from '/@/shared/types/domain-types';
|
||||
|
||||
export const orderSearchResults = (args: {
|
||||
params: LyricSearchQuery;
|
||||
|
|
|
|||
|
|
@ -330,7 +330,8 @@ ipcMain.on('player-set-queue', async (_event, current?: string, next?: string, p
|
|||
if (current) {
|
||||
try {
|
||||
await getMpvInstance()?.load(current, 'replace');
|
||||
} catch (error) {
|
||||
} catch (error: any | NodeMpvError) {
|
||||
mpvLog({ action: `Failed to load current song` }, error);
|
||||
await getMpvInstance()?.play();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
/* eslint-disable promise/always-return */
|
||||
import { BrowserWindow, globalShortcut, systemPreferences } from 'electron';
|
||||
|
||||
import { isMacOS } from '../../../utils';
|
||||
|
|
|
|||
|
|
@ -7,16 +7,25 @@ import { join } from 'path';
|
|||
import { WebSocket, WebSocketServer, Server as WsServer } from 'ws';
|
||||
import { deflate, gzip } from 'zlib';
|
||||
|
||||
import { getMainWindow } from '../../..';
|
||||
import { isLinux } from '../../../utils';
|
||||
import manifest from './manifest.json';
|
||||
|
||||
import { getMainWindow } from '/@/main/index';
|
||||
import { isLinux } from '/@/main/utils';
|
||||
import { QueueSong } from '/@/shared/types/domain-types';
|
||||
import { ClientEvent, ServerEvent } from '/@/shared/types/remote-types';
|
||||
import { PlayerRepeat, PlayerStatus, SongState } from '/@/shared/types/types';
|
||||
|
||||
let mprisPlayer: any | undefined;
|
||||
|
||||
if (isLinux()) {
|
||||
mprisPlayer = require('../../linux/mpris').mprisPlayer;
|
||||
async function initMpris() {
|
||||
if (isLinux()) {
|
||||
const mpris = await import('../../linux/mpris');
|
||||
mprisPlayer = mpris.mprisPlayer;
|
||||
}
|
||||
}
|
||||
|
||||
initMpris();
|
||||
|
||||
interface MimeType {
|
||||
css: string;
|
||||
html: string;
|
||||
|
|
@ -630,8 +639,8 @@ if (mprisPlayer) {
|
|||
mprisPlayer.on('loopStatus', (event: string) => {
|
||||
const repeat = event === 'Playlist' ? 'all' : event === 'Track' ? 'one' : 'none';
|
||||
|
||||
currentState.repeat = repeat;
|
||||
broadcast({ data: repeat, event: 'repeat' });
|
||||
currentState.repeat = repeat as PlayerRepeat;
|
||||
broadcast({ data: repeat, event: 'repeat' } as ServerEvent);
|
||||
});
|
||||
|
||||
mprisPlayer.on('shuffle', (shuffle: boolean) => {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import type { TitleTheme } from '/@/renderer/types';
|
||||
import type { TitleTheme } from '/@/shared/types/types';
|
||||
|
||||
import { ipcMain, nativeTheme, safeStorage } from 'electron';
|
||||
import Store from 'electron-store';
|
||||
|
|
|
|||
|
|
@ -1,3 +1,2 @@
|
|||
import './core';
|
||||
|
||||
// require(`./${process.platform}`)
|
||||
import(`./${process.platform}`);
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
import { ipcMain } from 'electron';
|
||||
import Player from 'mpris-service';
|
||||
|
||||
import { PlayerRepeat, PlayerStatus } from '../../../renderer/types';
|
||||
import { getMainWindow } from '../../main';
|
||||
|
||||
import { QueueSong } from '/@/renderer/api/types';
|
||||
import { getMainWindow } from '/@/main/index';
|
||||
import { QueueSong } from '/@/shared/types/domain-types';
|
||||
import { PlayerRepeat, PlayerStatus } from '/@/shared/types/types';
|
||||
|
||||
const mprisPlayer = Player({
|
||||
identity: 'Feishin',
|
||||
|
|
|
|||
|
|
@ -1,3 +0,0 @@
|
|||
// Dummy file to satisfy the build system
|
||||
|
||||
export {};
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
import { electronApp, is, optimizer } from '@electron-toolkit/utils';
|
||||
import { constants } from 'buffer';
|
||||
import { is } from '@electron-toolkit/utils';
|
||||
import {
|
||||
app,
|
||||
BrowserWindow,
|
||||
|
|
@ -19,7 +18,7 @@ import {
|
|||
import electronLocalShortcut from 'electron-localshortcut';
|
||||
import log from 'electron-log/main';
|
||||
import { autoUpdater } from 'electron-updater';
|
||||
import { access, readFile, writeFile } from 'fs';
|
||||
import { access, constants, readFile, writeFile } from 'fs';
|
||||
import path, { join } from 'path';
|
||||
import { deflate, inflate } from 'zlib';
|
||||
|
||||
|
|
@ -36,6 +35,8 @@ import {
|
|||
} from './utils';
|
||||
import './features';
|
||||
|
||||
import { TitleTheme } from '/@/shared/types/types';
|
||||
|
||||
export default class AppUpdater {
|
||||
constructor() {
|
||||
log.transports.file.level = 'info';
|
||||
|
|
@ -66,27 +67,31 @@ let exitFromTray = false;
|
|||
let forceQuit = false;
|
||||
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
const sourceMapSupport = require('source-map-support');
|
||||
sourceMapSupport.install();
|
||||
import('source-map-support').then((sourceMapSupport) => {
|
||||
sourceMapSupport.install();
|
||||
});
|
||||
}
|
||||
|
||||
const isDevelopment = process.env.NODE_ENV === 'development' || process.env.DEBUG_PROD === 'true';
|
||||
|
||||
if (isDevelopment) {
|
||||
require('electron-debug')();
|
||||
import('electron-debug').then((electronDebug) => {
|
||||
electronDebug.default();
|
||||
});
|
||||
}
|
||||
|
||||
const installExtensions = async () => {
|
||||
const installer = require('electron-devtools-installer');
|
||||
const forceDownload = !!process.env.UPGRADE_EXTENSIONS;
|
||||
const extensions = ['REACT_DEVELOPER_TOOLS', 'REDUX_DEVTOOLS'];
|
||||
import('electron-devtools-installer').then((installer) => {
|
||||
const forceDownload = !!process.env.UPGRADE_EXTENSIONS;
|
||||
const extensions = ['REACT_DEVELOPER_TOOLS', 'REDUX_DEVTOOLS'];
|
||||
|
||||
return installer
|
||||
.default(
|
||||
extensions.map((name) => installer[name]),
|
||||
forceDownload,
|
||||
)
|
||||
.catch(console.log);
|
||||
return installer
|
||||
.default(
|
||||
extensions.map((name) => installer[name]),
|
||||
forceDownload,
|
||||
)
|
||||
.catch(console.log);
|
||||
});
|
||||
};
|
||||
|
||||
const RESOURCES_PATH = app.isPackaged
|
||||
|
|
@ -393,7 +398,7 @@ async function createWindow(first = true): Promise<void> {
|
|||
mainWindow = null;
|
||||
});
|
||||
|
||||
const saved = false;
|
||||
let saved = false;
|
||||
|
||||
mainWindow.on('close', (event) => {
|
||||
store.set('bounds', mainWindow?.getNormalBounds());
|
||||
|
|
@ -446,7 +451,7 @@ async function createWindow(first = true): Promise<void> {
|
|||
}
|
||||
});
|
||||
|
||||
mainWindow.on('minimize', (event: any) => {
|
||||
(mainWindow as any).on('minimize', (event: any) => {
|
||||
if (store.get('window_minimize_to_tray') === true) {
|
||||
event.preventDefault();
|
||||
mainWindow?.hide();
|
||||
|
|
@ -632,22 +637,22 @@ if (!singleInstance) {
|
|||
|
||||
app.whenReady()
|
||||
.then(() => {
|
||||
// protocol.handle('feishin', async (request) => {
|
||||
// const filePath = `file://${request.url.slice('feishin://'.length)}`
|
||||
// const response = await net.fetch(filePath)
|
||||
// const contentType = response.headers.get('content-type')
|
||||
protocol.handle('feishin', async (request) => {
|
||||
const filePath = `file://${request.url.slice('feishin://'.length)}`;
|
||||
const response = await net.fetch(filePath);
|
||||
const contentType = response.headers.get('content-type');
|
||||
|
||||
// if (!contentType || !FONT_HEADERS.includes(contentType)) {
|
||||
// getMainWindow()?.webContents.send('custom-font-error', filePath)
|
||||
if (!contentType || !FONT_HEADERS.includes(contentType)) {
|
||||
getMainWindow()?.webContents.send('custom-font-error', filePath);
|
||||
|
||||
// return new Response(null, {
|
||||
// status: 403,
|
||||
// statusText: 'Forbidden'
|
||||
// })
|
||||
// }
|
||||
return new Response(null, {
|
||||
status: 403,
|
||||
statusText: 'Forbidden',
|
||||
});
|
||||
}
|
||||
|
||||
// return response
|
||||
// })
|
||||
return response;
|
||||
});
|
||||
|
||||
createWindow();
|
||||
if (store.get('window_enable_tray', true)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue