Skip to content

Commit cfbcf84

Browse files
committed
汉化
1 parent 94816b7 commit cfbcf84

File tree

19 files changed

+235
-133
lines changed

19 files changed

+235
-133
lines changed

devtools_options.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
description: This file stores settings for Dart & Flutter DevTools.
2+
documentation: https://docs.flutter.dev/tools/devtools/extensions#configure-extension-enablement-states
3+
extensions:
4+
- provider: true

lib/app.dart

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,19 @@ class KeyvizApp extends StatelessWidget {
2626
ChangeNotifierProvider(create: (_) => KeyEventProvider()),
2727
ChangeNotifierProvider(create: (_) => KeyStyleProvider()),
2828
],
29-
child: const Material(
29+
child: Material(
3030
type: MaterialType.transparency,
31-
child: Stack(
32-
fit: StackFit.expand,
33-
children: [
34-
ErrorView(),
35-
KeyVisualizer(),
36-
SettingsWindow(),
37-
MouseVisualizer(),
38-
],
31+
child: Consumer<KeyEventProvider>(
32+
builder: (context, keyEvent, _) {
33+
return Stack(
34+
children: [
35+
const ErrorView(),
36+
const KeyVisualizer(),
37+
if (keyEvent.styling) const SettingsWindow(),
38+
const MouseVisualizer(),
39+
],
40+
);
41+
},
3942
),
4043
),
4144
),

lib/providers/key_event.dart

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ enum ModifierKey {
2626
function("Fn");
2727

2828
const ModifierKey(this.label);
29+
2930
final String label;
3031

3132
String get keyLabel {
@@ -54,8 +55,10 @@ enum VisualizationHistoryMode {
5455
@override
5556
String toString() {
5657
return this == VisualizationHistoryMode.none
57-
? "None"
58-
: "${name.capitalize()}ly";
58+
? "无"
59+
: this == VisualizationHistoryMode.vertical
60+
? "垂直排列"
61+
: "水平排列";
5962
}
6063
}
6164

@@ -68,7 +71,20 @@ enum KeyCapAnimationType {
6871
slide;
6972

7073
@override
71-
String toString() => name.capitalize();
74+
String toString() {
75+
switch (this) {
76+
case KeyCapAnimationType.none:
77+
return "无动画";
78+
case KeyCapAnimationType.fade:
79+
return "淡入淡出";
80+
case KeyCapAnimationType.wham:
81+
return "冲击效果";
82+
case KeyCapAnimationType.grow:
83+
return "放大效果";
84+
case KeyCapAnimationType.slide:
85+
return "滑动效果";
86+
}
87+
}
7288
}
7389

7490
extension on MouseEvent {
@@ -190,15 +206,23 @@ class KeyEventProvider extends ChangeNotifier with TrayListener {
190206
Screen get _currentScreen => _screens[_screenIndex];
191207

192208
Map<String, Map<int, KeyEventData>> get keyboardEvents => _keyboardEvents;
209+
193210
int get screenIndex => _screenIndex;
211+
194212
List<Screen> get screens => _screens;
213+
195214
bool get styling => _styling;
215+
196216
bool get visualizeEvents => _visualizeEvents;
217+
197218
bool get hasError => _hasError;
198219

199220
bool get filterHotkeys => _filterHotkeys;
221+
200222
Map<ModifierKey, bool> get ignoreKeys => _ignoreKeys;
223+
201224
VisualizationHistoryMode get historyMode => _historyMode;
225+
202226
Axis? get historyDirection {
203227
switch (_historyMode) {
204228
case VisualizationHistoryMode.none:
@@ -213,16 +237,27 @@ class KeyEventProvider extends ChangeNotifier with TrayListener {
213237
}
214238

215239
int get lingerDurationInSeconds => _lingerDurationInSeconds;
240+
216241
Duration get lingerDuration => Duration(seconds: _lingerDurationInSeconds);
242+
217243
int get animationSpeed => _animationSpeed;
244+
218245
Duration get animationDuration => Duration(milliseconds: _animationSpeed);
246+
219247
KeyCapAnimationType get keyCapAnimation => _keyCapAnimation;
248+
220249
bool get noKeyCapAnimation => _keyCapAnimation == KeyCapAnimationType.none;
250+
221251
bool get showMouseClicks => _visualizeEvents ? _showMouseClicks : false;
252+
222253
bool get highlightCursor => _highlightCursor;
254+
223255
bool get showMouseEvents => _showMouseEvents;
256+
224257
double get dragThreshold => _dragThreshold;
258+
225259
Offset get cursorOffset => _cursorOffset;
260+
226261
bool get mouseButtonDown => _mouseButtonDown;
227262

228263
bool get _ignoreHistory =>
@@ -846,18 +881,18 @@ class KeyEventProvider extends ChangeNotifier with TrayListener {
846881
items: [
847882
MenuItem(
848883
key: "toggle",
849-
label: _visualizeEvents ? "✗ Turn Off" : "✓ Turn On",
884+
label: _visualizeEvents ? "✗ 关闭" : "✓ 打开",
850885
),
851886
MenuItem(
852887
key: "settings",
853-
label: "Settings",
854-
toolTip: "Open settings window",
888+
label: "设置",
889+
toolTip: "打开设置窗口",
855890
),
856891
MenuItem.separator(),
857892
MenuItem(
858893
key: "quit",
859-
label: "Quit",
860-
toolTip: "Close Keyviz",
894+
label: "退出",
895+
toolTip: "关闭Keyviz",
861896
),
862897
],
863898
),

lib/providers/key_style.dart

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,19 @@ import 'package:keyviz/domain/vault/vault.dart';
55

66
// base preset of the keycap
77
enum KeyCapStyle {
8-
minimal,
9-
flat,
10-
elevated,
11-
plastic,
12-
mechanical;
8+
minimal("最小"),
9+
flat("平铺按压"),
10+
elevated("平铺升高"),
11+
plastic("塑料键帽"),
12+
mechanical("机械键帽");
1313
// retro;
1414

15+
const KeyCapStyle(this.label);
16+
17+
final String label;
18+
1519
@override
16-
String toString() => name.capitalize();
20+
String toString() => label;
1721
}
1822

1923
// text capitalization
@@ -23,6 +27,7 @@ enum TextCap {
2327
lower("tt");
2428

2529
const TextCap(this.symbol);
30+
2631
final String symbol;
2732

2833
@override
@@ -31,11 +36,12 @@ enum TextCap {
3136

3237
// modifier text length
3338
enum ModifierTextLength {
34-
iconOnly("Icon Only"),
35-
shortLength("Short Text"),
36-
fullLength("Full Text");
39+
iconOnly("仅图标"),
40+
shortLength("简略信息"),
41+
fullLength("全部信息");
3742

3843
const ModifierTextLength(this.label);
44+
3945
final String label;
4046

4147
@override
@@ -49,6 +55,7 @@ enum VerticalAlignment {
4955
bottom(VuesaxIcons.alignBottom);
5056

5157
const VerticalAlignment(this.iconName);
58+
5259
final String iconName;
5360
}
5461

@@ -59,17 +66,22 @@ enum HorizontalAlignment {
5966
right(VuesaxIcons.alignRight);
6067

6168
const HorizontalAlignment(this.iconName);
69+
6270
final String iconName;
6371
}
6472

6573
// mouse animation type
6674
enum MouseClickAnimation {
67-
static,
68-
focus,
69-
filled;
75+
static("静态"),
76+
focus("焦点"),
77+
filled("填充");
78+
79+
const MouseClickAnimation(this.label);
80+
81+
final String label;
7082

7183
@override
72-
String toString() => name.capitalize();
84+
String toString() => label;
7385
}
7486

7587
// style provider of the keycap visualization
@@ -126,23 +138,27 @@ class KeyStyleProvider extends ChangeNotifier {
126138
// primary color to be used on flat keycap container
127139
// and elevated/isometric keycap's upper container
128140
Color _primaryColor1 = Colors.white;
141+
129142
// second color for gradient
130143
Color _primaryColor2 = Colors.white;
131144

132145
// secondary color to be used on
133146
// elevated/isometric keycap's bottom container
134147
Color _secondaryColor1 = Colors.black;
148+
135149
// second color for gradient
136150
Color _secondaryColor2 = Colors.grey[600]!;
137151

138152
// primary color to be used on modifiers keys
139153
Color _mPrimaryColor1 = const Color(0xffb8b8b8);
154+
140155
// second color for gradient
141156
Color _mPrimaryColor2 = const Color(0xff545454);
142157

143158
// secondary color to be used on
144159
// elevated/isometric keycap's bottom container
145160
Color _mSecondaryColor1 = Colors.deepPurple;
161+
146162
// second color for gradient
147163
Color _mSecondaryColor2 = Colors.deepPurple;
148164

@@ -192,13 +208,19 @@ class KeyStyleProvider extends ChangeNotifier {
192208
bool get differentColorForModifiers => _differentColorForModifiers;
193209

194210
double get fontSize => _fontSize;
211+
195212
Color get fontColor => _fontColor;
213+
196214
Color get mFontColor => _mFontColor;
215+
197216
TextCap get textCap => _textCap;
217+
198218
ModifierTextLength get modifierTextLength => _modifierTextLength;
199219

200220
VerticalAlignment get verticalAlignment => _verticalAlignment;
221+
201222
HorizontalAlignment get horizontalAlignment => _horizontalAlignment;
223+
202224
Alignment get childrenAlignment {
203225
switch (_verticalAlignment) {
204226
case VerticalAlignment.top:
@@ -240,8 +262,11 @@ class KeyStyleProvider extends ChangeNotifier {
240262
}
241263

242264
bool get showIcon => _showIcon;
265+
243266
bool get showSymbol => _showSymbol;
267+
244268
bool get addPlusSeparator => _addPlusSeparator;
269+
245270
Widget? get separator {
246271
return _addPlusSeparator
247272
? Text(
@@ -256,33 +281,52 @@ class KeyStyleProvider extends ChangeNotifier {
256281
}
257282

258283
bool get isGradient => _isGradient;
284+
259285
Color get primaryColor1 => _primaryColor1;
286+
260287
Color get primaryColor2 => _primaryColor2;
288+
261289
Color get secondaryColor1 => _secondaryColor1;
290+
262291
Color get secondaryColor2 => _secondaryColor2;
292+
263293
Color get mPrimaryColor1 => _mPrimaryColor1;
294+
264295
Color get mPrimaryColor2 => _mPrimaryColor2;
296+
265297
Color get mSecondaryColor1 => _mSecondaryColor1;
298+
266299
Color get mSecondaryColor2 => _mSecondaryColor2;
267300

268301
bool get borderEnabled => _borderEnabled;
302+
269303
Color get borderColor => _borderColor;
304+
270305
Color get mBorderColor => _mBorderColor;
306+
271307
double get borderWidth => _borderWidth;
308+
272309
double get cornerSmoothing => _cornerSmoothing;
273310

274311
bool get backgroundEnabled => _backgroundEnabled;
312+
275313
Color get backgroundColor => _backgroundColor;
314+
276315
Color get backgroundColorWithOpacity =>
277316
_backgroundColor.withOpacity(_backgroundOpacity);
317+
278318
double get backgroundOpacity => _backgroundOpacity;
319+
279320
double get backgroundSpacing => _fontSize * .5;
280321

281322
Alignment get alignment => _alignment;
323+
282324
double get margin => _margin;
283325

284326
MouseClickAnimation get clickAnimation => _clickAnimation;
327+
285328
double get cursorHighlightSize => _fontSize * 4;
329+
286330
Color get clickColor => _clickColor;
287331

288332
// key cap properties

lib/windows/error/error.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ class ErrorView extends StatelessWidget {
4343
),
4444
const ColumnGap(),
4545
Text(
46-
"Cannot register keyboard/mouse listener! "
47-
"Please quit the app from the system tray.",
46+
"无法注册键盘/鼠标监听器!"
47+
"请从系统托盘中退出应用程序。",
4848
style: context.textTheme.labelLarge?.copyWith(
4949
color: context.colorScheme.error,
5050
),

lib/windows/settings/settings.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class SettingsWindow extends StatelessWidget {
1919
return Selector<KeyEventProvider, bool>(
2020
selector: (_, keyEvent) => keyEvent.styling,
2121
builder: (_, show, __) {
22-
return show ? const _SettingsWindow() : const SizedBox();
22+
return show ? const _SettingsWindow() : const SizedBox.shrink();
2323
},
2424
);
2525
}

0 commit comments

Comments
 (0)