Skip to content

Commit

Permalink
buffer/2024-03-24:上流に合わせる (#47)
Browse files Browse the repository at this point in the history
* Fix: UNDOの引数を追従

* Change: ブラウザ版っぽく

* Change: コメントを合わせる

* Fix: 細かいところを修正

* Change: on Browser versionを消す

* Fix: 型エラーを修正

* Delete: 使われてない定数を削除
  • Loading branch information
sevenc-nanashi authored Mar 28, 2024
1 parent 55e6f09 commit 7d94c31
Show file tree
Hide file tree
Showing 14 changed files with 395 additions and 314 deletions.
6 changes: 3 additions & 3 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ dependencies {

// TODO: ちゃんと公開されたらそれに置き換える
implementation urlZipFile(
"voicevoxcore-android_0.15.0-preview.15",
"jp/hiroshiba/voicevoxcore/voicevoxcore-android/0.15.0-preview.15/voicevoxcore-android-0.15.0-preview.15.aar",
"https://github.com/VOICEVOX/voicevox_core/releases/download/0.15.0-preview.15/java_packages.zip"
"voicevoxcore-android_0.15.0-preview.16",
"jp/hiroshiba/voicevoxcore/voicevoxcore-android/0.15.0-preview.16/voicevoxcore-android-0.15.0-preview.16.aar",
"https://github.com/VOICEVOX/voicevox_core/releases/download/0.15.0-preview.16/java_packages.zip"
)

// https://mvnrepository.com/artifact/com.google.code.gson/gson
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class CorePlugin : Plugin() {
return
}
vvms.sortWith(compareBy {
it.name.split(".")[0].length
it.name.split(".")[0].toInt()
})
voiceModels = vvms.map {
VoiceModel(it.absolutePath)
Expand All @@ -102,6 +102,7 @@ class CorePlugin : Plugin() {
tempDir.mkdirs()
Os.setenv("TMPDIR", tempDir.absolutePath, true)

Log.i("CorePlugin", "Ready")
call.resolve()
} catch (e: Exception) {
call.reject(e.message)
Expand Down Expand Up @@ -287,6 +288,10 @@ class CorePlugin : Plugin() {

try {
val words = gson.fromJson(wordsJson, Array<UserDict.Word>::class.java).asList()
if (words.isEmpty()) {
call.resolve()
return
}
val userDict = UserDict()
words.forEach { word ->
userDict.addWord(word)
Expand Down
52 changes: 52 additions & 0 deletions src/backend/mobile/capacitorConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import AsyncLock from "async-lock";
import { Preferences } from "@capacitor/preferences";
import { defaultEngine } from "@/backend/browser/contract";

import { BaseConfigManager, Metadata } from "@/backend/common/ConfigManager";
import { ConfigType, EngineId, engineSettingSchema } from "@/type/preload";

let configManager: MobileConfigManager | undefined;
const entryKey = `${import.meta.env.VITE_APP_NAME}-config`;

const configManagerLock = new AsyncLock();
const defaultEngineId = EngineId(defaultEngine.uuid);

export async function getConfigManager() {
await configManagerLock.acquire("configManager", async () => {
if (!configManager) {
configManager = new MobileConfigManager();
await configManager.initialize();
}
});

if (!configManager) {
throw new Error("configManager is undefined");
}

return configManager;
}

class MobileConfigManager extends BaseConfigManager {
protected getAppVersion() {
return import.meta.env.VITE_APP_VERSION;
}
protected async exists() {
return !!(await Preferences.get({ key: entryKey }).then((v) => v.value));
}
protected async load(): Promise<Record<string, unknown> & Metadata> {
const db = await Preferences.get({ key: entryKey });
return JSON.parse(db.value || "{}");
}

protected async save(data: ConfigType & Metadata) {
await Preferences.set({ key: entryKey, value: JSON.stringify(data) });
}

protected getDefaultConfig() {
const baseConfig = super.getDefaultConfig();
baseConfig.engineSettings[defaultEngineId] ??= engineSettingSchema.parse(
{}
);
return baseConfig;
}
}
255 changes: 0 additions & 255 deletions src/backend/mobile/electronMock.ts

This file was deleted.

8 changes: 2 additions & 6 deletions src/backend/mobile/engine/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { VoicevoxCorePlugin } from "../plugin";
import { VoicevoxCorePlugin, corePlugin } from "../plugin";
import queryProvider from "./query";
import infoProvider from "./info";
import speakerProvider from "./speaker";
Expand All @@ -11,10 +11,8 @@ export type ApiProvider = (deps: {
corePlugin: VoicevoxCorePlugin;
}) => Partial<DefaultApiInterface>;

const loadApi = () => {
export const loadApi = () => {
api = new DefaultApi();
const corePlugin = window.plugins?.voicevoxCore;
if (!corePlugin) throw new Error("assert: corePlugin != null");
let isCoreInitialized = false;
(async () => {
await corePlugin.initialize();
Expand Down Expand Up @@ -47,5 +45,3 @@ const loadApi = () => {
}
) as DefaultApiInterface;
};

export default loadApi;
3 changes: 0 additions & 3 deletions src/backend/mobile/index.ts

This file was deleted.

11 changes: 1 addition & 10 deletions src/backend/mobile/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,4 @@ export type VoicevoxCorePlugin = {
useUserDict: (obj: { wordsJson: string }) => Promise<void>;
};

const loadPlugin = () => {
const corePlugin = registerPlugin<VoicevoxCorePlugin>("VoicevoxCore");

// @ts-expect-error 定義時だけは無視する
window.plugins = {
voicevoxCore: corePlugin,
};
};

export default loadPlugin;
export const corePlugin = registerPlugin<VoicevoxCorePlugin>("VoicevoxCore");
Loading

0 comments on commit 7d94c31

Please sign in to comment.