Skip to content

Commit 6100756

Browse files
committed
✨: add kancolle resource hack script and enhance webview with Fluent UI components
1 parent 3794d7b commit 6100756

File tree

3 files changed

+92
-45
lines changed

3 files changed

+92
-45
lines changed

lib/assets.dart

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@ class Assets {
77
Assets._internal();
88

99
static late String kancolleInjectJS;
10-
10+
static late String kancolleResourceHackJS;
11+
1112
static Future<void> init() async {
12-
kancolleInjectJS = await rootBundle.loadString('assets/js/kancolle_inject.js');
13+
kancolleInjectJS =
14+
await rootBundle.loadString('assets/js/kancolle_inject.js');
15+
16+
kancolleResourceHackJS =
17+
await rootBundle.loadString('assets/js/resource-hack.js');
1318
}
1419
}
1520

@@ -18,3 +23,10 @@ UserScript get kancolleUserScript => UserScript(
1823
injectionTime: UserScriptInjectionTime.AT_DOCUMENT_START,
1924
forMainFrameOnly: false,
2025
groupName: "kancolle");
26+
27+
UserScript get kancolleResourceHackScript => UserScript(
28+
source: Assets.kancolleInjectJS,
29+
injectionTime: UserScriptInjectionTime.AT_DOCUMENT_START,
30+
forMainFrameOnly: false,
31+
groupName: "kancolle");
32+

lib/components/webview.dart

Lines changed: 57 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import 'dart:collection';
22
import 'dart:convert';
33

4-
import 'package:flutter/material.dart';
4+
import 'package:fluent_ui/fluent_ui.dart';
55
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
66
import 'package:squadron_en_route/assets.dart';
77
import 'package:squadron_en_route/components/kancolle_model/kancolle_parse.dart';
88
import 'package:squadron_en_route/constant.dart';
9+
import 'package:squadron_en_route/helper/mod.dart';
910
import 'package:uuid/uuid.dart';
1011
import '../main.dart';
1112

@@ -51,9 +52,8 @@ class AppWebViewState extends State<AppWebView> {
5152

5253
@override
5354
Widget build(BuildContext context) {
54-
return Stack(
55-
alignment: Alignment.center,
56-
children: [
55+
return ScaffoldPage(
56+
content: Stack(alignment: Alignment.center, children: [
5757
AspectRatio(
5858
aspectRatio: 5 / 3,
5959
child: InAppWebView(
@@ -93,48 +93,62 @@ class AppWebViewState extends State<AppWebView> {
9393
onConsoleMessage: (controller, consoleMessage) =>
9494
print(consoleMessage),
9595
)),
96-
97-
Positioned(
98-
bottom: 16.0,
99-
right: 16.0,
100-
child: FloatingActionButton(
101-
onPressed: () {
102-
controller.reload();
103-
},
104-
child: Icon(Icons.refresh),
96+
]),
97+
bottomBar: CommandBar(
98+
primaryItems: [
99+
CommandBarBuilderItem(
100+
builder: (context, mode, w) => Tooltip(
101+
message: context.L.webviewCameraTakePic,
102+
child: w,
103+
),
104+
wrappedItem: CommandBarButton(
105+
icon: const Icon(FluentIcons.camera),
106+
onPressed: () {},
107+
),
105108
),
106-
),
107-
Positioned(
108-
bottom: 16.0,
109-
left: 16.0,
110-
child: FloatingActionButton(
111-
onPressed: () {
112-
print("clear cache");
113-
InAppWebViewController.clearAllCache();
114-
controller.clearCache();
115-
},
116-
child: Icon(Icons.refresh),
109+
CommandBarBuilderItem(
110+
builder: (context, mode, w) => Tooltip(
111+
message: context.L.webviewScale,
112+
child: w,
113+
),
114+
wrappedItem: CommandBarButton(
115+
icon: const Icon(FluentIcons.back_to_window),
116+
onPressed: () {
117+
controller.injectJavascriptFileFromAsset(
118+
assetFilePath: 'assets/js/autoScaleIOS.js');
119+
},
120+
),
121+
),
122+
CommandBarBuilderItem(
123+
builder: (context, mode, w) => Tooltip(
124+
message: context.L.webviewRefresh,
125+
child: w,
126+
),
127+
wrappedItem: CommandBarButton(
128+
icon: const Icon(FluentIcons.refresh),
129+
onPressed: () {
130+
controller.reload();
131+
},
132+
),
117133
),
118-
),
119-
Positioned(
120-
bottom: 80,
121-
right: 16,
122-
child: FloatingActionButton(
123-
onPressed: () async {
124-
controller.injectJavascriptFileFromAsset(
125-
assetFilePath: 'assets/js/autoScaleIOS.js');
126-
},
127-
child: Icon(Icons.zoom_in),
134+
],
135+
secondaryItems: [
136+
CommandBarBuilderItem(
137+
builder: (context, mode, w) => Tooltip(
138+
message: context.L.webviewForceRefresh,
139+
child: w,
140+
),
141+
wrappedItem: CommandBarButton(
142+
icon: const Icon(FluentIcons.refresh),
143+
onPressed: () {
144+
InAppWebViewController.clearAllCache();
145+
controller.clearCache();
146+
},
147+
),
128148
),
129-
),
130-
progress < 1.0
131-
? LinearProgressIndicator(
132-
value: progress,
133-
color: Colors.amber,
134-
backgroundColor: Colors.transparent,
135-
)
136-
: Container(),
137-
],
149+
],
150+
isCompact: true,
151+
),
138152
);
139153
}
140154
}

lib/l10n/app_en.arb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,26 @@
3737
"dashboardConsole": "Console",
3838
"@dashboardConsole": {
3939
"description": "Dashboard Console"
40+
},
41+
42+
"webview": "Webview",
43+
"@webview": {
44+
"description": "Webview"
45+
},
46+
"webviewCameraTakePic": "take picture",
47+
"@webviewCameraTakePic": {
48+
"description": "Camera"
49+
},
50+
"webviewScale": "scale",
51+
"@webviewScale": {
52+
"description": "Scale"
53+
},
54+
"webviewRefresh": "refresh",
55+
"@webviewRefresh": {
56+
"description": "Refresh"
57+
},
58+
"webviewForceRefresh": "Force Refresh",
59+
"@webviewForceRefresh": {
60+
"description": "Force Refresh"
4061
}
4162
}

0 commit comments

Comments
 (0)