Skip to content

Commit 4034d9c

Browse files
committed
feat:新增版本检查、更新功能
1 parent 300ac72 commit 4034d9c

File tree

17 files changed

+502
-56
lines changed

17 files changed

+502
-56
lines changed

android/app/src/main/AndroidManifest.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
<uses-permission android:name="android.permission.WAKE_LOCK" />
88
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
99

10+
<queries>
11+
<package android:name="com.android.vending" />
12+
</queries>
13+
1014
<application
1115
android:name="com.github.alist.App"
1216
android:icon="@mipmap/ic_launcher"
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
package com.github.alist
22

3+
import com.github.alist.plugin.AlistPlugin
34
import com.ryanheise.audioservice.AudioServiceActivity
5+
import io.flutter.embedding.engine.FlutterEngine
46

5-
class MainActivity: AudioServiceActivity()
7+
class MainActivity : AudioServiceActivity() {
8+
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
9+
super.configureFlutterEngine(flutterEngine)
10+
flutterEngine.plugins.add(AlistPlugin())
11+
}
12+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package com.github.alist.plugin
2+
3+
import android.content.Context
4+
import android.content.Intent
5+
import android.content.pm.PackageManager
6+
import android.net.Uri
7+
import io.flutter.embedding.engine.plugins.FlutterPlugin
8+
import io.flutter.plugin.common.MethodCall
9+
import io.flutter.plugin.common.MethodChannel
10+
11+
class AlistPlugin : FlutterPlugin, MethodChannel.MethodCallHandler {
12+
13+
private lateinit var channel: MethodChannel
14+
private lateinit var context: Context
15+
16+
override fun onAttachedToEngine(binding: FlutterPlugin.FlutterPluginBinding) {
17+
channel = MethodChannel(binding.binaryMessenger, "com.github.alist.client.plugin")
18+
context = binding.applicationContext
19+
channel.setMethodCallHandler(this)
20+
}
21+
22+
override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
23+
channel.setMethodCallHandler(null)
24+
}
25+
26+
override fun onMethodCall(call: MethodCall, result: MethodChannel.Result) {
27+
when (call.method) {
28+
"isAppInstalled" -> {
29+
val packageName: String? = call.argument("packageName")
30+
if (packageName.isNullOrEmpty()) {
31+
result.error("INVALID_PACKAGE_NAME", "The package name is invalid", null)
32+
return
33+
}
34+
35+
try {
36+
val packageInfo = context.packageManager.getPackageInfo(packageName, 0)
37+
val isInstalled = packageInfo.applicationInfo.enabled
38+
result.success(isInstalled)
39+
} catch (exc: PackageManager.NameNotFoundException) {
40+
result.success(false)
41+
}
42+
}
43+
44+
"launchApp" -> {
45+
val packageName: String? = call.argument("packageName")
46+
val uri: String? = call.argument("uri")
47+
if (packageName.isNullOrEmpty()) {
48+
result.error("INVALID_PACKAGE_NAME", "The package name is invalid", null)
49+
return
50+
}
51+
if (uri.isNullOrEmpty()) {
52+
try {
53+
val intent = context.packageManager.getLaunchIntentForPackage(packageName)
54+
context.startActivity(intent)
55+
result.success(true)
56+
} catch (exc: PackageManager.NameNotFoundException) {
57+
result.success(false)
58+
}
59+
} else {
60+
try {
61+
val intent = Intent(Intent.ACTION_VIEW).apply {
62+
data = Uri.parse(uri)
63+
setPackage(packageName)
64+
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
65+
}
66+
context.startActivity(intent)
67+
result.success(true)
68+
} catch (exc: PackageManager.NameNotFoundException) {
69+
result.success(false)
70+
}
71+
}
72+
}
73+
74+
else -> {
75+
result.notImplemented()
76+
}
77+
}
78+
}
79+
}

ios/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ SPEC CHECKSUMS:
136136
MJExtension: 21c5f6f8c4d5d8844b7ae8fbae08fed0b501f961
137137
open_file: 02eb5cb6b21264bd3a696876f5afbfb7ca4f4b7d
138138
package_info_plus: 6c92f08e1f853dc01228d6f553146438dafcd14e
139-
path_provider_foundation: eaf5b3e458fc0e5fbb9940fb09980e853fe058b8
139+
path_provider_foundation: 29f094ae23ebbca9d3d0cec13889cd9060c0e943
140140
permission_handler_apple: e76247795d700c14ea09e3a2d8855d41ee80a2e6
141141
screen_brightness_ios: 715ca807df953bf676d339f11464e438143ee625
142142
shared_preferences_foundation: 5b919d13b803cadd15ed2dc053125c68730e5126

lib/entity/app_version_resp.dart

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import 'package:alist/generated/json/base/json_field.dart';
2+
import 'package:alist/generated/json/app_version_resp.g.dart';
3+
import 'dart:convert';
4+
5+
@JsonSerializable()
6+
class AppVersionResp {
7+
late String updates;
8+
late AppVersionRespAndroid android;
9+
late AppVersionRespIos ios;
10+
11+
AppVersionResp();
12+
13+
factory AppVersionResp.fromJson(Map<String, dynamic> json) => $AppVersionRespFromJson(json);
14+
15+
Map<String, dynamic> toJson() => $AppVersionRespToJson(this);
16+
17+
@override
18+
String toString() {
19+
return jsonEncode(this);
20+
}
21+
}
22+
23+
@JsonSerializable()
24+
class AppVersionRespAndroid {
25+
late String version;
26+
late String githubUrl;
27+
late String googlePlayUrl;
28+
29+
AppVersionRespAndroid();
30+
31+
factory AppVersionRespAndroid.fromJson(Map<String, dynamic> json) => $AppVersionRespAndroidFromJson(json);
32+
33+
Map<String, dynamic> toJson() => $AppVersionRespAndroidToJson(this);
34+
35+
@override
36+
String toString() {
37+
return jsonEncode(this);
38+
}
39+
}
40+
41+
@JsonSerializable()
42+
class AppVersionRespIos {
43+
late String version;
44+
late String appStoreUrl;
45+
46+
AppVersionRespIos();
47+
48+
factory AppVersionRespIos.fromJson(Map<String, dynamic> json) => $AppVersionRespIosFromJson(json);
49+
50+
Map<String, dynamic> toJson() => $AppVersionRespIosToJson(this);
51+
52+
@override
53+
String toString() {
54+
return jsonEncode(this);
55+
}
56+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import 'package:alist/generated/json/base/json_convert_content.dart';
2+
import 'package:alist/entity/app_version_resp.dart';
3+
4+
AppVersionResp $AppVersionRespFromJson(Map<String, dynamic> json) {
5+
final AppVersionResp appVersionResp = AppVersionResp();
6+
final String? updates = jsonConvert.convert<String>(json['updates']);
7+
if (updates != null) {
8+
appVersionResp.updates = updates;
9+
}
10+
final AppVersionRespAndroid? android = jsonConvert.convert<AppVersionRespAndroid>(json['android']);
11+
if (android != null) {
12+
appVersionResp.android = android;
13+
}
14+
final AppVersionRespIos? ios = jsonConvert.convert<AppVersionRespIos>(json['ios']);
15+
if (ios != null) {
16+
appVersionResp.ios = ios;
17+
}
18+
return appVersionResp;
19+
}
20+
21+
Map<String, dynamic> $AppVersionRespToJson(AppVersionResp entity) {
22+
final Map<String, dynamic> data = <String, dynamic>{};
23+
data['updates'] = entity.updates;
24+
data['android'] = entity.android.toJson();
25+
data['ios'] = entity.ios.toJson();
26+
return data;
27+
}
28+
29+
AppVersionRespAndroid $AppVersionRespAndroidFromJson(Map<String, dynamic> json) {
30+
final AppVersionRespAndroid appVersionRespAndroid = AppVersionRespAndroid();
31+
final String? version = jsonConvert.convert<String>(json['version']);
32+
if (version != null) {
33+
appVersionRespAndroid.version = version;
34+
}
35+
final String? githubUrl = jsonConvert.convert<String>(json['githubUrl']);
36+
if (githubUrl != null) {
37+
appVersionRespAndroid.githubUrl = githubUrl;
38+
}
39+
final String? googlePlayUrl = jsonConvert.convert<String>(json['googlePlayUrl']);
40+
if (googlePlayUrl != null) {
41+
appVersionRespAndroid.googlePlayUrl = googlePlayUrl;
42+
}
43+
return appVersionRespAndroid;
44+
}
45+
46+
Map<String, dynamic> $AppVersionRespAndroidToJson(AppVersionRespAndroid entity) {
47+
final Map<String, dynamic> data = <String, dynamic>{};
48+
data['version'] = entity.version;
49+
data['githubUrl'] = entity.githubUrl;
50+
data['googlePlayUrl'] = entity.googlePlayUrl;
51+
return data;
52+
}
53+
54+
AppVersionRespIos $AppVersionRespIosFromJson(Map<String, dynamic> json) {
55+
final AppVersionRespIos appVersionRespIos = AppVersionRespIos();
56+
final String? version = jsonConvert.convert<String>(json['version']);
57+
if (version != null) {
58+
appVersionRespIos.version = version;
59+
}
60+
final String? appStoreUrl = jsonConvert.convert<String>(json['appStoreUrl']);
61+
if (appStoreUrl != null) {
62+
appVersionRespIos.appStoreUrl = appStoreUrl;
63+
}
64+
return appVersionRespIos;
65+
}
66+
67+
Map<String, dynamic> $AppVersionRespIosToJson(AppVersionRespIos entity) {
68+
final Map<String, dynamic> data = <String, dynamic>{};
69+
data['version'] = entity.version;
70+
data['appStoreUrl'] = entity.appStoreUrl;
71+
return data;
72+
}

lib/generated/json/base/json_convert_content.dart

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44

55
// This file is automatically generated. DO NOT EDIT, all your changes would be lost.
66
import 'package:flutter/material.dart' show debugPrint;
7+
import 'package:alist/entity/app_version_resp.dart';
8+
import 'package:alist/entity/copy_move_req.dart';
79
import 'package:alist/entity/donate_config_entity.dart';
810
import 'package:alist/entity/file_info_resp_entity.dart';
911
import 'package:alist/entity/file_list_resp_entity.dart';
1012
import 'package:alist/entity/file_remove_req.dart';
1113
import 'package:alist/entity/file_rename_req.dart';
1214
import 'package:alist/entity/login_resp_entity.dart';
1315
import 'package:alist/entity/my_info_resp.dart';
14-
import 'package:alist/entity/copy_move_req.dart';
1516
import 'package:alist/generated/mkdir_req.dart';
1617

1718
JsonConvert jsonConvert = JsonConvert();
@@ -20,6 +21,10 @@ typedef EnumConvertFunction<T> = T Function(String value);
2021

2122
class JsonConvert {
2223
static final Map<String, JsonConvertFunction> convertFuncMap = {
24+
(AppVersionResp).toString(): AppVersionResp.fromJson,
25+
(AppVersionRespAndroid).toString(): AppVersionRespAndroid.fromJson,
26+
(AppVersionRespIos).toString(): AppVersionRespIos.fromJson,
27+
(CopyMoveReq).toString(): CopyMoveReq.fromJson,
2328
(DonateConfigEntity).toString(): DonateConfigEntity.fromJson,
2429
(FileInfoRespEntity).toString(): FileInfoRespEntity.fromJson,
2530
(FileListRespEntity).toString(): FileListRespEntity.fromJson,
@@ -28,7 +33,6 @@ class JsonConvert {
2833
(FileRenameReq).toString(): FileRenameReq.fromJson,
2934
(LoginRespEntity).toString(): LoginRespEntity.fromJson,
3035
(MyInfoResp).toString(): MyInfoResp.fromJson,
31-
(CopyMoveReq).toString(): CopyMoveReq.fromJson,
3236
(MkdirReq).toString(): MkdirReq.fromJson,
3337
};
3438

@@ -99,6 +103,9 @@ List<T>? convertListNotNull<T>(dynamic value, {EnumConvertFunction? enumConvert}
99103
return value as T;
100104
} else {
101105
if (convertFuncMap.containsKey(type)) {
106+
if (value == null) {
107+
return null;
108+
}
102109
return convertFuncMap[type]!(Map<String, dynamic>.from(value)) as T;
103110
} else {
104111
throw UnimplementedError('$type unimplemented');
@@ -108,6 +115,18 @@ List<T>? convertListNotNull<T>(dynamic value, {EnumConvertFunction? enumConvert}
108115

109116
//list is returned by type
110117
static M? _getListChildType<M>(List<Map<String, dynamic>> data) {
118+
if(<AppVersionResp>[] is M){
119+
return data.map<AppVersionResp>((Map<String, dynamic> e) => AppVersionResp.fromJson(e)).toList() as M;
120+
}
121+
if(<AppVersionRespAndroid>[] is M){
122+
return data.map<AppVersionRespAndroid>((Map<String, dynamic> e) => AppVersionRespAndroid.fromJson(e)).toList() as M;
123+
}
124+
if(<AppVersionRespIos>[] is M){
125+
return data.map<AppVersionRespIos>((Map<String, dynamic> e) => AppVersionRespIos.fromJson(e)).toList() as M;
126+
}
127+
if(<CopyMoveReq>[] is M){
128+
return data.map<CopyMoveReq>((Map<String, dynamic> e) => CopyMoveReq.fromJson(e)).toList() as M;
129+
}
111130
if(<DonateConfigEntity>[] is M){
112131
return data.map<DonateConfigEntity>((Map<String, dynamic> e) => DonateConfigEntity.fromJson(e)).toList() as M;
113132
}
@@ -132,19 +151,19 @@ List<T>? convertListNotNull<T>(dynamic value, {EnumConvertFunction? enumConvert}
132151
if(<MyInfoResp>[] is M){
133152
return data.map<MyInfoResp>((Map<String, dynamic> e) => MyInfoResp.fromJson(e)).toList() as M;
134153
}
135-
if(<CopyMoveReq>[] is M){
136-
return data.map<CopyMoveReq>((Map<String, dynamic> e) => CopyMoveReq.fromJson(e)).toList() as M;
137-
}
138154
if(<MkdirReq>[] is M){
139155
return data.map<MkdirReq>((Map<String, dynamic> e) => MkdirReq.fromJson(e)).toList() as M;
140156
}
141157

142158
debugPrint("${M.toString()} not found");
143159

144160
return null;
145-
}
161+
}
146162

147163
static M? fromJsonAsT<M>(dynamic json) {
164+
if (json is M) {
165+
return json;
166+
}
148167
if (json is List) {
149168
return _getListChildType<M>(json.map((e) => e as Map<String, dynamic>).toList());
150169
} else {

lib/l10n/intl_en_us.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,8 @@ const translationsEnUS = {
143143
"deleteAccountDialog_content":"Are you sure you want to delete your account '%s' ?",
144144
"deleteAccountDialog_btn_ok":"Confirm",
145145
"deleteAccountDialog_btn_cancel":"Cancel",
146+
"updateDialog_title": "Update Tips",
147+
"updateDialog_btn_ok": "Update",
148+
"updateDialog_btn_cancel": "Cancel",
149+
"updateDialog_tips_ignore": "Ignore this version",
146150
};

lib/l10n/intl_keys.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,8 @@ class Intl {
137137
static const String deleteAccountDialog_content = "deleteAccountDialog_content";
138138
static const String deleteAccountDialog_btn_ok = "deleteAccountDialog_btn_ok";
139139
static const String deleteAccountDialog_btn_cancel = "deleteAccountDialog_btn_cancel";
140+
static const String updateDialog_title = "updateDialog_title";
141+
static const String updateDialog_btn_ok = "updateDialog_btn_ok";
142+
static const String updateDialog_btn_cancel = "updateDialog_btn_cancel";
143+
static const String updateDialog_tips_ignore = "updateDialog_tips_ignore";
140144
}

lib/l10n/intl_zh_cn.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,8 @@ const translationsZhCN = {
139139
"deleteAccountDialog_content": "您确认删除账号 %s 吗?",
140140
"deleteAccountDialog_btn_ok": "确认",
141141
"deleteAccountDialog_btn_cancel": "取消",
142+
"updateDialog_title": "有新版本啦~",
143+
"updateDialog_btn_ok": "更新",
144+
"updateDialog_btn_cancel": "取消",
145+
"updateDialog_tips_ignore": "忽略此版本",
142146
};

0 commit comments

Comments
 (0)