Skip to content

Commit

Permalink
feat(synced-lyrics): init romanization!
Browse files Browse the repository at this point in the history
  • Loading branch information
ArjixWasTaken committed Dec 28, 2024
1 parent fa3e146 commit cb97f70
Show file tree
Hide file tree
Showing 11 changed files with 337 additions and 119 deletions.
105 changes: 56 additions & 49 deletions electron.vite.config.mts
Original file line number Diff line number Diff line change
@@ -1,61 +1,68 @@
import { resolve, dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { dirname, join, resolve } from "node:path";
import { fileURLToPath } from "node:url";

import { UserConfig } from 'vite';
import { defineConfig, defineViteConfig } from 'electron-vite';
import builtinModules from 'builtin-modules';
import viteResolve from 'vite-plugin-resolve';
import Inspect from 'vite-plugin-inspect';
import solidPlugin from 'vite-plugin-solid';
import { UserConfig } from "vite";
import { defineConfig, defineViteConfig } from "electron-vite";
import builtinModules from "builtin-modules";
import viteResolve from "vite-plugin-resolve";
import Inspect from "vite-plugin-inspect";
import solidPlugin from "vite-plugin-solid";

import { pluginVirtualModuleGenerator } from './vite-plugins/plugin-importer.mjs';
import pluginLoader from './vite-plugins/plugin-loader.mjs';
import { pluginVirtualModuleGenerator } from "./vite-plugins/plugin-importer.mjs";
import pluginLoader from "./vite-plugins/plugin-loader.mjs";

import { i18nImporter } from './vite-plugins/i18n-importer.mjs';
import { i18nImporter } from "./vite-plugins/i18n-importer.mjs";

const __dirname = dirname(fileURLToPath(import.meta.url));

const resolveAlias = {
'@': resolve(__dirname, './src'),
'@assets': resolve(__dirname, './assets'),
"@": resolve(__dirname, "./src"),
"@assets": resolve(__dirname, "./assets"),
};

export default defineConfig({
main: defineViteConfig(({ mode }) => {
const commonConfig: UserConfig = {
plugins: [
pluginLoader('backend'),
pluginLoader("backend"),
viteResolve({
'virtual:i18n': i18nImporter(),
'virtual:plugins': pluginVirtualModuleGenerator('main'),
"virtual:i18n": i18nImporter(),
"virtual:plugins": pluginVirtualModuleGenerator("main"),
}),
],
publicDir: 'assets',
publicDir: "assets",
build: {
lib: {
entry: 'src/index.ts',
formats: ['cjs'],
entry: "src/index.ts",
formats: ["cjs"],
},
outDir: 'dist/main',
outDir: "dist/main",
commonjsOptions: {
ignoreDynamicRequires: true,
},
rollupOptions: {
external: ['electron', 'custom-electron-prompt', ...builtinModules],
input: './src/index.ts',
external: [
"electron",
"custom-electron-prompt",
"kuromoji",
"kuroshiro",
"kuroshiro-analyzer-kuromoji",
...builtinModules,
],
input: "./src/index.ts",
},
},
resolve: {
alias: resolveAlias,
},
};

if (mode === 'development') {
commonConfig.build!.sourcemap = 'inline';
if (mode === "development") {
commonConfig.build!.sourcemap = "inline";
commonConfig.plugins?.push(
Inspect({
build: true,
outputDir: join(__dirname, '.vite-inspect/backend'),
outputDir: join(__dirname, ".vite-inspect/backend"),
}),
);
return commonConfig;
Expand All @@ -73,37 +80,37 @@ export default defineConfig({
preload: defineViteConfig(({ mode }) => {
const commonConfig: UserConfig = {
plugins: [
pluginLoader('preload'),
pluginLoader("preload"),
viteResolve({
'virtual:i18n': i18nImporter(),
'virtual:plugins': pluginVirtualModuleGenerator('preload'),
"virtual:i18n": i18nImporter(),
"virtual:plugins": pluginVirtualModuleGenerator("preload"),
}),
],
build: {
lib: {
entry: 'src/preload.ts',
formats: ['cjs'],
entry: "src/preload.ts",
formats: ["cjs"],
},
outDir: 'dist/preload',
outDir: "dist/preload",
commonjsOptions: {
ignoreDynamicRequires: true,
},
rollupOptions: {
external: ['electron', 'custom-electron-prompt', ...builtinModules],
input: './src/preload.ts',
external: ["electron", "custom-electron-prompt", ...builtinModules],
input: "./src/preload.ts",
},
},
resolve: {
alias: resolveAlias,
},
};

if (mode === 'development') {
commonConfig.build!.sourcemap = 'inline';
if (mode === "development") {
commonConfig.build!.sourcemap = "inline";
commonConfig.plugins?.push(
Inspect({
build: true,
outputDir: join(__dirname, '.vite-inspect/preload'),
outputDir: join(__dirname, ".vite-inspect/preload"),
}),
);
return commonConfig;
Expand All @@ -121,40 +128,40 @@ export default defineConfig({
renderer: defineViteConfig(({ mode }) => {
const commonConfig: UserConfig = {
plugins: [
pluginLoader('renderer'),
pluginLoader("renderer"),
viteResolve({
'virtual:i18n': i18nImporter(),
'virtual:plugins': pluginVirtualModuleGenerator('renderer'),
"virtual:i18n": i18nImporter(),
"virtual:plugins": pluginVirtualModuleGenerator("renderer"),
}),
solidPlugin(),
],
root: './src/',
root: "./src/",
build: {
lib: {
entry: 'src/index.html',
formats: ['iife'],
name: 'renderer',
entry: "src/index.html",
formats: ["iife"],
name: "renderer",
},
outDir: 'dist/renderer',
outDir: "dist/renderer",
commonjsOptions: {
ignoreDynamicRequires: true,
},
rollupOptions: {
external: ['electron', ...builtinModules],
input: './src/index.html',
external: ["electron", ...builtinModules],
input: "./src/index.html",
},
},
resolve: {
alias: resolveAlias,
},
};

if (mode === 'development') {
commonConfig.build!.sourcemap = 'inline';
if (mode === "development") {
commonConfig.build!.sourcemap = "inline";
commonConfig.plugins?.push(
Inspect({
build: true,
outputDir: join(__dirname, '.vite-inspect/renderer'),
outputDir: join(__dirname, ".vite-inspect/renderer"),
}),
);
return commonConfig;
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@
"jimp": "1.6.0",
"keyboardevent-from-electron-accelerator": "2.0.0",
"keyboardevents-areequal": "0.2.2",
"kuromoji": "^0.1.2",
"kuroshiro": "^1.2.0",
"kuroshiro-analyzer-kuromoji": "^1.1.0",
"node-html-parser": "7.0.1",
"node-id3": "0.2.6",
"peerjs": "1.5.4",
Expand Down
50 changes: 50 additions & 0 deletions pnpm-lock.yaml

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

28 changes: 28 additions & 0 deletions src/plugins/synced-lyrics/backend.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { createBackend } from "@/utils";

import Kuroshiro from "kuroshiro";
import KuromojiAnalyzer from "kuroshiro-analyzer-kuromoji";

export const backend = createBackend({
async start({ ipc }) {
console.log(Kuroshiro);

const kuroshiro = new Kuroshiro.default();
{
await kuroshiro.init(new KuromojiAnalyzer());
}

ipc.handle("synced-lyrics:romanize-line", async (line: string) => {
let out = line;

if (Kuroshiro.default.Util.hasJapanese(line)) {
out = await kuroshiro.convert(line, {
to: "romaji",
mode: "spaced",
});
}

return out;
});
},
});
26 changes: 14 additions & 12 deletions src/plugins/synced-lyrics/index.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
import style from './style.css?inline';
import { createPlugin } from '@/utils';
import { t } from '@/i18n';
import style from "./style.css?inline";
import { createPlugin } from "@/utils";
import { t } from "@/i18n";

import { menu } from './menu';
import { renderer } from './renderer';
import { menu } from "./menu";
import { renderer } from "./renderer";

import type { SyncedLyricsPluginConfig } from './types';
import type { SyncedLyricsPluginConfig } from "./types";
import { backend } from "./backend";

export default createPlugin({
name: () => t('plugins.synced-lyrics.name'),
description: () => t('plugins.synced-lyrics.description'),
authors: ['Non0reo', 'ArjixWasTaken', 'KimJammer'],
name: () => t("plugins.synced-lyrics.name"),
description: () => t("plugins.synced-lyrics.description"),
authors: ["Non0reo", "ArjixWasTaken", "KimJammer"],
restartNeeded: true,
addedVersion: '3.5.X',
addedVersion: "3.5.X",
config: {
enabled: false,
preciseTiming: true,
showLyricsEvenIfInexact: true,
showTimeCodes: false,
defaultTextString: '♪',
lineEffect: 'fancy',
defaultTextString: "♪",
lineEffect: "fancy",
} satisfies SyncedLyricsPluginConfig,

backend,
menu,
renderer,
stylesheets: [style],
Expand Down
Loading

0 comments on commit cb97f70

Please sign in to comment.