Skip to content

Commit

Permalink
Fix: custom css (#602)
Browse files Browse the repository at this point in the history
1. remove custom css UI
2. put css files in the config dir to setup custom css.
  • Loading branch information
GeoffreyChen777 authored Aug 23, 2024
1 parent 654a36c commit 03ae96a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 41 deletions.
15 changes: 14 additions & 1 deletion app/main/services/window-process-management-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from "electron";
import os from "os";
import path, { join, posix } from "path";
import fs from "fs";

import { errorcatching } from "@/base/error";
import { Eventable } from "@/base/event";
Expand All @@ -20,6 +21,7 @@ import {
PreferenceService,
} from "@/common/services/preference-service";
import { WindowStorage } from "@/main/window-storage";
import { FileSystemService, IFileSystemService } from "./filesystem-service";

interface WindowOptions extends BrowserWindowConstructorOptions {
entry: string;
Expand Down Expand Up @@ -47,7 +49,8 @@ export class WindowProcessManagementService extends Eventable<IWindowProcessMana
public browserWindows: WindowStorage;

constructor(
@IPreferenceService private readonly _preferenceService: PreferenceService
@IPreferenceService private readonly _preferenceService: PreferenceService,
@IFileSystemService private readonly _fileSystemService: FileSystemService
) {
super("windowProcessManagementService", {
serviceReady: "",
Expand Down Expand Up @@ -162,6 +165,16 @@ export class WindowProcessManagementService extends Eventable<IWindowProcessMana
});
}

// Insert custom CSS
const configDir = this._fileSystemService.getSystemPath(
"userData",
Process.main
);
if (fs.existsSync(path.join(configDir, `${id}.css`))) {
const css = fs.readFileSync(path.join(configDir, `${id}.css`), "utf-8");
this.insertCustomCSS(id, css);
}

this.fire({ [id]: "created" });
}

Expand Down
40 changes: 0 additions & 40 deletions app/renderer/ui/preference-view/mainview-view.vue
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,6 @@ onMounted(() => {
const updatePref = (key: keyof IPreferenceStore, value: unknown) => {
preferenceService.set({ [key]: value });
};
const onInsertMainCssCliecked = async () => {
await PLMainAPI.windowProcessManagementService.insertCustomCSS(Process.renderer, prefState.customMainWindowCSS);
};
const onInsertQuickPasteCssCliecked = async () => {
await PLMainAPI.windowProcessManagementService.insertCustomCSS(Process.quickpaste, prefState.customQuickPasteCSS);
};
</script>

<template>
Expand Down Expand Up @@ -241,37 +233,5 @@ const onInsertQuickPasteCssCliecked = async () => {
@event:next-click="onMoveNextClicked(index, false)"
/>
</div>

<div class="text-base font-semibold mt-4">
{{ $t("preference.custom") + " Main CSS" }}
</div>
<div class="flex justify-between flex-col gap-3">
<textarea
class="w-full h-32 p-2 mt-2 bg-neutral-200 dark:bg-neutral-700 text-neutral-800 dark:text-neutral-300"
v-model="prefState.customMainWindowCSS"
></textarea>
<button
class="flex h-8 w-[5.5rem] text-center rounded-md bg-neutral-200 dark:bg-neutral-600 hover:bg-neutral-300 hover:dark:bg-neutral-600"
@click="onInsertMainCssCliecked"
>
{{ $t("menu.save") }}
</button>
</div>

<div class="text-base font-semibold mt-4">
{{ $t("preference.custom") + $t("preference.mainview") + " Quick Paste CSS" }}
</div>
<div class="flex justify-between flex-col gap-3">
<textarea
class="w-full h-32 p-2 mt-2 bg-neutral-200 dark:bg-neutral-700 text-neutral-800 dark:text-neutral-300"
v-model="prefState.customQuickPasteCSS"
></textarea>
<button
class="flex h-8 w-[5.5rem] text-center rounded-md bg-neutral-200 dark:bg-neutral-600 hover:bg-neutral-300 hover:dark:bg-neutral-600"
@click="onInsertQuickPasteCssCliecked"
>
{{ $t("menu.save") }}
</button>
</div>
</div>
</template>

0 comments on commit 03ae96a

Please sign in to comment.