Skip to content

Commit

Permalink
Change cache policy, self build lightspeed js
Browse files Browse the repository at this point in the history
  • Loading branch information
nnnlog committed Mar 10, 2024
1 parent cdb7d3b commit a57450f
Show file tree
Hide file tree
Showing 10 changed files with 1,738 additions and 84,759 deletions.
83,106 changes: 0 additions & 83,106 deletions assets/js/lightspeed.js

This file was deleted.

246 changes: 122 additions & 124 deletions lib/components/grade_view/subject_widget.dart
Original file line number Diff line number Diff line change
@@ -1,124 +1,122 @@
import 'package:flutter/material.dart';
import 'package:ssurade/components/grade_view/grade_logo.dart';
import 'package:ssurade/globals.dart' as globals;
import 'package:ssurade/types/subject/subject.dart';

class SubjectWidget extends StatefulWidget {
final Subject _subjectData;
final bool _exportImage, _showSubject;

const SubjectWidget(this._subjectData, this._exportImage, this._showSubject, {super.key});

@override
State<StatefulWidget> createState() => _SubjectWidgetState();
}

class _SubjectWidgetState extends State<SubjectWidget> {
final Map<Subject, ExpansionTileController> _expansionTileController = {};

@override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.symmetric(vertical: 10, horizontal: 20),
child: Container(
decoration: BoxDecoration(
color: globals.isLightMode ? Colors.white : Colors.black.withOpacity(0.45),
boxShadow: [
BoxShadow(
blurRadius: 6,
spreadRadius: 1,
offset: const Offset(0, 2),
color: Colors.black.withOpacity(0.1),
),
],
borderRadius: const BorderRadius.all(Radius.circular(10)),
),
child: ExpansionTile(
iconColor: widget._exportImage ? Colors.transparent : null,
collapsedIconColor: widget._exportImage ? Colors.transparent : null,
controller: _expansionTileController[widget._subjectData] ??= ExpansionTileController(),
tilePadding: const EdgeInsets.symmetric(vertical: 10, horizontal: 20),
childrenPadding: const EdgeInsets.symmetric(horizontal: 40),
shape: Border.all(width: 0, color: Colors.transparent),
title: IntrinsicHeight(
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
GradeLogo.parse(widget._subjectData.grade),
Container(
width: 13,
),
Flexible(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
(!widget._exportImage || widget._showSubject) ? widget._subjectData.name : "",
textAlign: TextAlign.left,
style: const TextStyle(
fontWeight: FontWeight.w800,
fontSize: 17,
color: Colors.black,
),
softWrap: true,
),
Text(
"${widget._subjectData.professor.isNotEmpty && (!widget._exportImage || widget._showSubject) ? "${widget._subjectData.professor} · " : ""}${widget._subjectData.credit.toStringAsPrecision(1)}학점",
textAlign: TextAlign.center,
style: TextStyle(
color: globals.isLightMode ? Colors.black.withOpacity(0.4) : Colors.white.withOpacity(0.8),
fontWeight: FontWeight.w600,
fontSize: 14,
),
),
],
),
),
],
),
),
children: [
{
"이수 구분": widget._subjectData.category,
"성적 산출 방식": widget._subjectData.isPassFail || widget._subjectData.grade == "P" ? "P/F" : "100점 기준",
"최종 성적": widget._subjectData.score,
"성적 기호": widget._subjectData.grade,
},
widget._subjectData.detail.isEmpty ? {
"-": "성적 상세 정보가 없어요. 현재 학기 정보를 다시 불러오세요."
} : widget._subjectData.detail
]
.map((e) => Column(
children: [
...e.entries.map<Row>((entry) => Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
textBaseline: TextBaseline.alphabetic,
children: [
Flexible(
child: SelectableText(
entry.key,
textAlign: TextAlign.left,
style: const TextStyle(color: Colors.black54),
),
),
const SizedBox(width: 10),
Flexible(
child: SelectableText(
entry.value,
textAlign: TextAlign.right,
style: const TextStyle(fontWeight: FontWeight.w500),
),
),
],
)),
const SizedBox(height: 20),
],
))
.toList(),
),
),
);
}
}
import 'package:flutter/material.dart';
import 'package:ssurade/components/grade_view/grade_logo.dart';
import 'package:ssurade/globals.dart' as globals;
import 'package:ssurade/types/subject/subject.dart';

class SubjectWidget extends StatefulWidget {
final Subject _subjectData;
final bool _exportImage, _showSubject;

const SubjectWidget(this._subjectData, this._exportImage, this._showSubject, {super.key});

@override
State<StatefulWidget> createState() => _SubjectWidgetState();
}

class _SubjectWidgetState extends State<SubjectWidget> {
final Map<Subject, ExpansionTileController> _expansionTileController = {};

@override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.symmetric(vertical: 10, horizontal: 20),
child: Container(
decoration: BoxDecoration(
color: globals.isLightMode ? Colors.white : Colors.black.withOpacity(0.45),
boxShadow: [
BoxShadow(
blurRadius: 6,
spreadRadius: 1,
offset: const Offset(0, 2),
color: Colors.black.withOpacity(0.1),
),
],
borderRadius: const BorderRadius.all(Radius.circular(10)),
),
child: ExpansionTile(
iconColor: widget._exportImage ? Colors.transparent : null,
collapsedIconColor: widget._exportImage ? Colors.transparent : null,
controller: _expansionTileController[widget._subjectData] ??= ExpansionTileController(),
tilePadding: const EdgeInsets.symmetric(vertical: 10, horizontal: 20),
childrenPadding: const EdgeInsets.symmetric(horizontal: 40),
shape: Border.all(width: 0, color: Colors.transparent),
title: IntrinsicHeight(
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
GradeLogo.parse(widget._subjectData.grade),
Container(
width: 13,
),
Flexible(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
(!widget._exportImage || widget._showSubject) ? widget._subjectData.name : "",
textAlign: TextAlign.left,
style: const TextStyle(
fontWeight: FontWeight.w800,
fontSize: 17,
color: Colors.black,
),
softWrap: true,
),
Text(
"${widget._subjectData.professor.isNotEmpty && (!widget._exportImage || widget._showSubject) ? "${widget._subjectData.professor} · " : ""}${widget._subjectData.credit.toStringAsPrecision(1)}학점",
textAlign: TextAlign.center,
style: TextStyle(
color: globals.isLightMode ? Colors.black.withOpacity(0.4) : Colors.white.withOpacity(0.8),
fontWeight: FontWeight.w600,
fontSize: 14,
),
),
],
),
),
],
),
),
children: [
{
"이수 구분": widget._subjectData.category,
"성적 산출 방식": widget._subjectData.isPassFail || widget._subjectData.grade == "P" ? "P/F" : "100점 기준",
"최종 성적": widget._subjectData.score,
"성적 기호": widget._subjectData.grade,
},
widget._subjectData.detail.isEmpty ? {"-": "성적 상세 정보가 없어요. 현재 학기 정보를 다시 불러오세요."} : widget._subjectData.detail
]
.map((e) => Column(
children: [
...e.entries.map<Row>((entry) => Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
textBaseline: TextBaseline.alphabetic,
children: [
Flexible(
child: SelectableText(
entry.key,
textAlign: TextAlign.left,
style: const TextStyle(color: Colors.black54),
),
),
const SizedBox(width: 10),
Flexible(
child: SelectableText(
entry.value,
textAlign: TextAlign.right,
style: const TextStyle(fontWeight: FontWeight.w500),
),
),
],
)),
const SizedBox(height: 20),
],
))
.toList(),
),
),
);
}
}
3 changes: 0 additions & 3 deletions lib/crawling/background/background_service.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import 'package:disable_battery_optimization/disable_battery_optimization.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:logger/logger.dart';
import 'package:ssurade/crawling/common/crawler.dart';
import 'package:ssurade/globals.dart' as globals;
Expand All @@ -9,7 +7,6 @@ import 'package:ssurade/types/semester/semester.dart';
import 'package:ssurade/types/semester/year_semester.dart';
import 'package:ssurade/utils/notification.dart';
import 'package:ssurade/utils/set.dart';
import 'package:ssurade/utils/toast.dart';
import 'package:workmanager/workmanager.dart';

Future<void> disableBatteryOptimize({bool show = false}) async {
Expand Down
11 changes: 3 additions & 8 deletions lib/crawling/common/webview_worker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import 'package:ssurade/crawling/common/crawling_task.dart';
import 'package:ssurade/crawling/common/webview_controller_extension.dart';
import 'package:ssurade/crawling/error/unauthenticated_exception.dart';
import 'package:ssurade/filesystem/filesystem.dart';
import 'package:ssurade/globals.dart' as globals;

/// Execute task with headless webview.
class WebViewWorker {
static List<String> webViewScript = [];
static WebViewWorker instance = WebViewWorker._();
static String _lightspeedCache = "";

WebViewWorker._();

Expand Down Expand Up @@ -124,12 +124,7 @@ class WebViewWorker {
},
shouldInterceptRequest: (InAppWebViewController controller, WebResourceRequest request) async {
if (request.url.toString().startsWith("https://ecc.ssu.ac.kr/sap/public/bc/ur/nw7/js/lightspeed.js")) {
if (_lightspeedCache.isEmpty) {
// _lightspeedCache =
// (await http.get(Uri.parse("https://gist.githubusercontent.com/nnnlog/7f2420106e0fdf9260ee7e736c3b3c70/raw/ec02c5a98485fdd297485a585ac2b3c25f0d9bda/lightspeed.js"))).body;
_lightspeedCache = await rootBundle.loadString("assets/js/lightspeed.js");
}
return WebResourceResponse(contentType: "application/x-javascript", data: Uint8List.fromList(_lightspeedCache.codeUnits));
return WebResourceResponse(contentType: "application/x-javascript", data: Uint8List.fromList((await globals.lightspeedManager.get(request.url.query)).codeUnits));
}
if ((request.url.path.endsWith(".css") && !request.url.toString().contains("ecc.ssu.ac.kr")) || request.url.toString().startsWith("https://fonts.googleapis.com/css")) {
return WebResourceResponse(contentType: "text/css", data: Uint8List.fromList([]));
Expand All @@ -151,7 +146,7 @@ class WebViewWorker {
initialSettings: InAppWebViewSettings(
useShouldInterceptRequest: true,
appCachePath: getPath("webview_cache"),
cacheMode: CacheMode.LOAD_CACHE_ELSE_NETWORK,
// cacheMode: CacheMode.LOAD_CACHE_ELSE_NETWORK,
cacheEnabled: true,
userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
),
Expand Down
Loading

0 comments on commit a57450f

Please sign in to comment.