Skip to content

Commit f5ff0fc

Browse files
committed
titlebar height and transparent mode
1 parent 099c76e commit f5ff0fc

15 files changed

+218
-69
lines changed

public/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<!-- <link href="https://cdn.jsdelivr.net/npm/@mdi/[email protected]/css/materialdesignicons.min.css" rel="stylesheet"> -->
99
<link href="https://fonts.googleapis.com/css2?family=Encode+Sans:wght@500&display=swap" rel="stylesheet">
1010
</head>
11-
<body>
11+
<body style="background:#ffffff00;">
1212
<noscript>
1313
<strong>We're sorry but copytranslator doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
1414
</noscript>

src/common/action.ts

+16
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
dragCopyModes,
2121
categories,
2222
displayTexts,
23+
titlebarModes,
2324
} from "./types";
2425
import { dictionaryTypes } from "./dictionary/types";
2526
import { getLanguageLocales, Language } from "./translate/locale";
@@ -264,6 +265,10 @@ class ActionManager {
264265
1.5,
265266
2.0,
266267
];
268+
const heights = [];
269+
for (let i = 1; i < 41; i++) {
270+
heights.push(i);
271+
}
267272

268273
this.append(listAction("translatorType", translatorTypes, "translation"));
269274
this.append(listAction("dictionaryType", dictionaryTypes, "translation"));
@@ -278,6 +283,17 @@ class ActionManager {
278283
this.append(constantAction("contentFontFamily", "appearance"));
279284
this.append(constantAction("interfaceFontFamily", "appearance"));
280285
this.append(listAction("colorMode", colorModes, "appearance"));
286+
287+
this.append(
288+
listAction(
289+
"transparency",
290+
[0.0, 0.1, 0.2, 0.3, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0],
291+
"appearance"
292+
)
293+
);
294+
this.append(listAction("titlebarMode", titlebarModes, "appearance"));
295+
this.append(listAction("titlebarHeight", heights, "appearance"));
296+
this.append(switchAction("penerate", "appearance"));
281297
this.append(
282298
selectAction(
283299
"localeSetting",

src/common/configParser.ts

+23-13
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class ConfigParser {
1010
rules: Rules = new Map<Identifier, Rule>();
1111
file: string = env.configPath;
1212
lastSave = Date.now();
13+
notSavingKeys: Identifier[] = [];
1314

1415
constructor() {}
1516

@@ -25,11 +26,15 @@ class ConfigParser {
2526
return this.rules.has(key);
2627
}
2728

28-
setRule(key: Identifier, rule: Rule) {
29+
setRule(key: Identifier, rule: Rule, needSave: boolean = true) {
2930
if (this.rules.has(key)) {
3031
throw `duplicate rule ${key}`;
3132
}
33+
rule.needSave = needSave;
3234
this.rules.set(key, rule);
35+
if (!needSave) {
36+
this.notSavingKeys.push(key);
37+
}
3338
}
3439

3540
getRule(key: Identifier): Rule {
@@ -47,17 +52,20 @@ class ConfigParser {
4752
}
4853
const config = { [key]: value };
4954
store.dispatch("updateConfig", config);
50-
const now = Date.now();
51-
if (this.lastSave > now) {
52-
//就说明我们不需要唤起一次新的保存
53-
// console.log("schedule save pass");
54-
} else {
55-
const interval = 2000; //修改后预定一次保存,在此保存之前的所有修改都不会再预定保存
56-
this.lastSave = now + interval;
57-
setTimeout(() => {
58-
// console.log("schedule save");
59-
this.save();
60-
}, interval);
55+
if (this.getRule(key).needSave) {
56+
//需要保存的才及时保存
57+
const now = Date.now();
58+
if (this.lastSave > now) {
59+
//就说明我们不需要唤起一次新的保存
60+
// console.log("schedule save pass");
61+
} else {
62+
const interval = 2000; //修改后预定一次保存,在此保存之前的所有修改都不会再预定保存
63+
this.lastSave = now + interval;
64+
setTimeout(() => {
65+
// console.log("schedule save");
66+
this.save();
67+
}, interval);
68+
}
6169
}
6270
return true;
6371
}
@@ -127,7 +135,9 @@ class ConfigParser {
127135
}
128136

129137
save() {
130-
writeFileSync(this.file, JSON.stringify(store.state.config, null, 4));
138+
let config2Save: { [key: string]: string } = store.state.config;
139+
this.notSavingKeys.map((key) => delete config2Save[key]); //去掉不需要保存的
140+
writeFileSync(this.file, JSON.stringify(config2Save, null, 4));
131141
const now = Date.now();
132142
if (now > this.lastSave) {
133143
this.lastSave = now;

src/common/configuration.ts

+17
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import {
2727
dragCopyModes,
2828
isValidActionButton,
2929
ActionButton,
30+
titlebarModes,
31+
TitlebarMode,
3032
} from "./types";
3133
import { DictionaryType, dictionaryTypes } from "./dictionary/types";
3234
import { version } from "./constant";
@@ -404,6 +406,21 @@ function initConfig(
404406

405407
config.setRule("pasteDelay", new TypeRule<number>(0.0));
406408

409+
config.setRule("titlebarHeight", new TypeRule<number>(32));
410+
411+
config.setRule("ignoreMouseEvents", new TypeRule<boolean>(false), false); //这个玩意儿不需要保存
412+
config.setRule("penerate", new TypeRule<boolean>(false)); //这个玩意儿需要保存
413+
414+
config.setRule(
415+
"titlebarMode",
416+
new UnionRule<TitlebarMode>("default", titlebarModes)
417+
);
418+
419+
config.setRule(
420+
"transparency",
421+
new TypeRule<number>(0.0, (x) => x <= 1.0 && x >= 0.0)
422+
);
423+
407424
config.setRule(
408425
"googleMirror",
409426
new TypeRule<string>("https://gtranslate.cdn.haah.net")

src/common/rule.ts

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ interface Rule {
3737
predefined: any;
3838
check?: CheckFuction; // 检查是否有效的函数
3939
minimalVersion?: string;
40+
needSave?: boolean;
4041
}
4142

4243
class GroupRule<T> implements Rule {

src/common/types.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,12 @@ export const constantActionTypes = [
6969
"primaryColor",
7070
"interfaceFontFamily",
7171
"contentFontFamily",
72+
"titlebarHeight",
73+
"titlebarMode",
74+
"transparency",
7275
] as const;
7376

77+
export const titlebarModes = ["default", "mini"] as const;
7478
export const interceptTranslatorTypes = ["bing", "deepl", "tencent"] as const;
7579

7680
export const normalTranslatorTypes = [
@@ -87,7 +91,7 @@ export const abstractTranslatorTypes = ["copytranslator"] as const;
8791
export type InterceptTranslatorType = typeof interceptTranslatorTypes[number];
8892
export type NormalTranslatorType = typeof normalTranslatorTypes[number];
8993
export type AbstractTranslatorType = typeof abstractTranslatorTypes[number];
90-
94+
export type TitlebarMode = typeof titlebarModes[number];
9195
export type TranslatorType = InterceptTranslatorType | NormalTranslatorType;
9296
export type GeneralTranslatorType =
9397
| InterceptTranslatorType
@@ -145,6 +149,8 @@ export const switchActionTypes = [
145149
"enableDoubleCopyTranslate",
146150
"isNewUser",
147151
"showGoogleMessage",
152+
"ignoreMouseEvents",
153+
"penerate",
148154
] as const;
149155

150156
//Electron 原生 角色
@@ -376,6 +382,14 @@ function rgb(r: number, g: number, b: number) {
376382
return "#" + R + G + B;
377383
}
378384

385+
export function hexToRgb(hex: string) {
386+
return {
387+
r: parseInt("0x" + hex.slice(1, 3)),
388+
g: parseInt("0x" + hex.slice(3, 5)),
389+
b: parseInt("0x" + hex.slice(5, 7)),
390+
};
391+
}
392+
379393
export const colorStatusMap = new Map<ColorStatus, string>([
380394
["None", rgb(190, 190, 190)],
381395
["Listen", rgb(84, 255, 159)],

src/components/ActionButton.vue

+17-15
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
<template>
22
<v-tooltip bottom open-delay="100" :disabled="!tooltipText">
33
<template v-slot:activator="{ on, attrs }">
4-
<div v-bind="attrs" v-on="on">
5-
<v-btn
6-
color="primary"
7-
small
8-
depressed
9-
tile
10-
class="btn"
11-
:height="btnSize.height"
12-
:width="btnSize.width"
13-
@click="handle(left_click, true)"
14-
@contextmenu="handle(right_click, false)"
15-
>
16-
<v-icon>{{ icon }}</v-icon>
17-
</v-btn>
18-
</div>
4+
<v-btn
5+
v-bind="attrs"
6+
v-on="on"
7+
color="primary"
8+
small
9+
depressed
10+
tile
11+
:outlined="config.transparency > 0 && onContrast"
12+
class="btn"
13+
:height="btnSize.height"
14+
:width="btnSize.width"
15+
@click="handle(left_click, true)"
16+
@contextmenu="handle(right_click, false)"
17+
>
18+
<v-icon :size="btnSize.height">{{ icon }}</v-icon>
19+
</v-btn>
1920
</template>
2021
<span>{{ tooltipText }}</span>
2122
</v-tooltip>
@@ -36,6 +37,7 @@ export default class Action extends Mixins(BaseView) {
3637
@Prop({ default: undefined }) readonly right_click!: string;
3738
@Prop({ default: undefined }) readonly tooltip!: string;
3839
@Prop({ default: undefined }) readonly predefined!: PredefinedActionButton;
40+
@Prop({ default: true }) readonly onContrast!: boolean;
3941
4042
get tooltipText(): undefined | string {
4143
if (this.trans[this.tooltip] != undefined) {

src/components/Base.vue

+7-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<script lang="ts">
66
import { Component, Vue } from "vue-property-decorator";
77
import bus from "@/common/event-bus";
8+
import { Identifier } from "../common/types";
89
910
@Component
1011
export default class Base extends Vue {
@@ -20,12 +21,16 @@ export default class Base extends Vue {
2021
return this.$store.getters.locale;
2122
}
2223
24+
set(key: Identifier, val: any) {
25+
this.$controller.set(key, val);
26+
}
27+
2328
get titlebarHeight() {
24-
return `${this.$store.state.titlebarHeight}px`;
29+
return `${this.titlebarHeightVal}px`;
2530
}
2631
2732
get titlebarHeightVal() {
28-
return this.$store.state.titlebarHeight;
33+
return this.config.titlebarHeight;
2934
}
3035
}
3136
</script>

src/components/BaseView.vue

+1-6
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
</template>
44

55
<script lang="ts">
6-
import { Component, Vue } from "vue-property-decorator";
7-
import { Identifier } from "../common/types";
6+
import { Component } from "vue-property-decorator";
87
import { shell } from "electron";
98
import eventBus from "@/common/event-bus";
109
import logger from "@/common/logger";
@@ -60,10 +59,6 @@ export default class BaseView extends Base {
6059
return this.$store.state.dictResult;
6160
}
6261
63-
set(key: Identifier, val: any) {
64-
this.$controller.set(key, val);
65-
}
66-
6762
get sourceSize() {
6863
return this.config[this.layoutType].sourceFontSize;
6964
}

src/components/EngineButton.vue

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<template>
22
<v-tooltip bottom open-delay="100" :disabled="!tooltipText">
33
<template v-slot:activator="{ on, attrs }">
4-
<div v-bind="attrs" v-on="on">
5-
<v-btn
6-
v-bind:class="[engineClass, 'btnBase']"
7-
@click="switchTranslator"
8-
color="white"
9-
x-small
10-
fab
11-
:height="buttonSize"
12-
:width="buttonSize"
13-
></v-btn>
14-
</div>
4+
<v-btn
5+
v-bind:class="[engineClass, 'btnBase']"
6+
v-bind="attrs"
7+
v-on="on"
8+
@click="switchTranslator"
9+
color="white"
10+
x-small
11+
fab
12+
:height="buttonSize"
13+
:width="buttonSize"
14+
></v-btn>
1515
</template>
1616
<span>{{ tooltipText }}</span>
1717
</v-tooltip>

src/main/controller.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { WindowMangaer } from "./views/manager";
1+
import { WindowManager } from "./views/manager";
22
import { eventListener } from "./event-listener";
33
import { MenuManager } from "./menu-manager";
44
import {
@@ -27,7 +27,7 @@ import { constants } from "../common/constant";
2727
import { DragCopyMode } from "@/common/types";
2828

2929
class Controller extends MainController {
30-
win: WindowMangaer = new WindowMangaer(this);
30+
win: WindowManager = new WindowManager(this);
3131
menu: MenuManager = new MenuManager(this);
3232
updater = new UpdateChecker(this);
3333
shortcut: ShortcutManager = new ShortcutManager();
@@ -158,6 +158,9 @@ class Controller extends MainController {
158158

159159
postSet(identifier: Identifier, value: any): boolean {
160160
switch (identifier) {
161+
case "ignoreMouseEvents":
162+
this.win.setIgnoreMouseEvents(value as boolean);
163+
break;
161164
case "localeSetting":
162165
this.l10n.updateLocale(this.get("localeSetting"));
163166
break;

src/main/views/manager.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import eventBus from "@/common/event-bus";
1515
import { LayoutConfig } from "@/common/rule";
1616
const forceFocus = require("@adeperio/forcefocus");
1717

18-
export class WindowMangaer {
18+
export class WindowManager {
1919
windows = new Map<RouteActionType, BrowserWindow>();
2020
controller: MainController;
2121

@@ -28,6 +28,14 @@ export class WindowMangaer {
2828
});
2929
}
3030

31+
setIgnoreMouseEvents(value: boolean) {
32+
if (value) {
33+
this.get("contrast").setIgnoreMouseEvents(true, { forward: true });
34+
} else {
35+
this.get("contrast").setIgnoreMouseEvents(false);
36+
}
37+
}
38+
3139
updateBounds(newLayoutType: LayoutType | null = null) {
3240
const oldLayoutType = config.get<LayoutType>("layoutType");
3341
let windowConfig = config.get<LayoutConfig>(oldLayoutType);
@@ -221,6 +229,7 @@ export class WindowMangaer {
221229
show: false,
222230
frame: false,
223231
title: "CopyTranslator",
232+
transparent: true,
224233
};
225234
const previous_config = config.get<LayoutConfig>(config.get("layoutType"));
226235
window_config = { ...window_config, ...previous_config };

src/store/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ const store = new Vuex.Store({
3030
sharedDiff: emptySharedDiff(),
3131
dictResult: emptyDictResult(),
3232
config: {},
33-
titlebarHeight: 32,
3433
},
3534
mutations: {
3635
setShared(state, sharedResult) {

0 commit comments

Comments
 (0)