clean cache by type

This commit is contained in:
niuhuan 2021-11-08 13:38:27 +08:00
parent bdf1b12034
commit 7caad393c2
3 changed files with 85 additions and 26 deletions

View File

@ -388,6 +388,28 @@ func setDownloadRunning(status bool) {
downloadRunning = status downloadRunning = status
} }
func cleanNetworkCache() error {
err := network_cache.RemoveAll()
if err != nil {
return err
}
notifyExport("清理结束")
return nil
}
func cleanImageCache() error {
notifyExport("清理图片缓存")
err := comic_center.RemoveAllRemoteImage()
if err != nil {
return err
}
notifyExport("清理图片文件")
os.RemoveAll(remoteDir)
utils.Mkdir(remoteDir)
notifyExport("清理结束")
return nil
}
func clean() error { func clean() error {
var err error var err error
notifyExport("清理网络缓存") notifyExport("清理网络缓存")
@ -571,6 +593,10 @@ func FlatInvoke(method string, params string) (string, error) {
case "deleteViewLog": case "deleteViewLog":
comic_center.DeleteViewLog(params) comic_center.DeleteViewLog(params)
return "", nil return "", nil
case "cleanNetworkCache":
return "", cleanNetworkCache()
case "cleanImageCache":
return "", cleanImageCache()
case "clean": case "clean":
return "", clean() return "", clean()
case "autoClean": case "autoClean":

View File

@ -360,6 +360,16 @@ class Method {
return GameInfo.fromJson(json.decode(data)); return GameInfo.fromJson(json.decode(data));
} }
///
Future cleanNetworkCache() {
return _flatInvoke("cleanNetworkCache", "");
}
///
Future cleanImageCache() {
return _flatInvoke("cleanImageCache", "");
}
/// ///
Future clean() { Future clean() {
return _flatInvoke("clean", ""); return _flatInvoke("clean", "");

View File

@ -3,6 +3,7 @@ import 'dart:async';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:pikapi/basic/Channels.dart'; import 'package:pikapi/basic/Channels.dart';
import 'package:pikapi/basic/Method.dart'; import 'package:pikapi/basic/Method.dart';
import 'package:pikapi/screens/components/FitButton.dart';
import 'components/ContentLoading.dart'; import 'components/ContentLoading.dart';
// //
@ -47,13 +48,48 @@ class _CleanScreenState extends State<CleanScreen> {
), ),
body: ListView( body: ListView(
children: [ children: [
MaterialButton( Container(
onPressed: () async { padding: EdgeInsets.all(8),
child: _cleanResult != "" ? Text(_cleanResult) : Container(),
),
Container(
height: 50,
child: FitButton(
text: '清理网络缓存',
onPressed: () {
processCleanAction(method.cleanNetworkCache);
},
),
),
Container(
height: 50,
child: FitButton(
text: '清理图片缓存',
onPressed: () {
processCleanAction(method.cleanImageCache);
},
),
),
Container(
height: 50,
child: FitButton(
text: '清理全部缓存',
onPressed: () {
processCleanAction(method.clean);
},
),
),
],
),
);
}
Future processCleanAction(Future Function() action) async {
try { try {
setState(() { setState(() {
_cleaning = true; _cleaning = true;
}); });
await method.clean(); await action();
setState(() { setState(() {
_cleanResult = "清理成功"; _cleanResult = "清理成功";
}); });
@ -66,18 +102,5 @@ class _CleanScreenState extends State<CleanScreen> {
_cleaning = false; _cleaning = false;
}); });
} }
},
child: Container(
padding: EdgeInsets.all(20),
child: Text('清理'),
),
),
Container(
padding: EdgeInsets.all(8),
child: _cleanResult != "" ? Text(_cleanResult) : Container(),
)
],
),
);
} }
} }