Skip to content

Commit

Permalink
Merge branch 'beta'
Browse files Browse the repository at this point in the history
  • Loading branch information
JGeek00 committed Oct 5, 2023
2 parents b539ad7 + 1f1edf7 commit b25d3fd
Show file tree
Hide file tree
Showing 12 changed files with 258 additions and 127 deletions.
9 changes: 8 additions & 1 deletion lib/l10n/app_zh.arb
Original file line number Diff line number Diff line change
Expand Up @@ -653,5 +653,12 @@
"queries": "查询",
"adultSites": "成人网站",
"quickFilters": "状态过滤器",
"searchDomainInternet": "在互联网上搜索该域名"
"searchDomainInternet": "在互联网上搜索该域名",
"hideServerAddress": "隐藏服务器地址",
"hideServerAddressDescription": "在主页上隐藏服务器地址",
"topItemsOrder": "顶部项目顺序",
"topItemsOrderDescription": "排列主页顶部项目列表",
"topItemsReorderInfo": "按住并滑动一个项目以重新排序。",
"discardChanges": "放弃更改",
"discardChangesDescription": "您确定要放弃更改吗?"
}
9 changes: 8 additions & 1 deletion lib/l10n/app_zh_CN.arb
Original file line number Diff line number Diff line change
Expand Up @@ -653,5 +653,12 @@
"queries": "查询",
"adultSites": "成人网站",
"quickFilters": "状态过滤器",
"searchDomainInternet": "在互联网上搜索该域名"
"searchDomainInternet": "在互联网上搜索该域名",
"hideServerAddress": "隐藏服务器地址",
"hideServerAddressDescription": "在主页上隐藏服务器地址",
"topItemsOrder": "顶部项目顺序",
"topItemsOrderDescription": "排列主页顶部项目列表",
"topItemsReorderInfo": "按住并滑动一个项目以重新排序。",
"discardChanges": "放弃更改",
"discardChangesDescription": "您确定要放弃更改吗?"
}
4 changes: 2 additions & 2 deletions lib/models/dhcp.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ class DhcpStatus {

factory DhcpStatus.fromJson(Map<String, dynamic> json) => DhcpStatus(
interfaceName: json["interface_name"],
v4: IpVersion.fromJson(json["v4"]),
v6: IpVersion.fromJson(json["v6"]),
v4: json["v4"] != null ? IpVersion.fromJson(json["v4"]) : null,
v6: json["v6"] != null ? IpVersion.fromJson(json["v6"]) : null,
leases: List<Lease>.from(json["leases"].map((x) => Lease.fromJson(x))),
staticLeases: List<Lease>.from(json["static_leases"].map((x) => Lease.fromJson(x))),
enabled: json["enabled"],
Expand Down
2 changes: 1 addition & 1 deletion lib/models/dns_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class DnsInfo {
int? cacheSize;
int? cacheTtlMin;
int? cacheTtlMax;
bool cacheOptimistic;
bool? cacheOptimistic;
bool resolveClients;
bool usePrivatePtrResolvers;
List<String> localPtrUpstreams;
Expand Down
14 changes: 9 additions & 5 deletions lib/providers/servers_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,14 @@ class ServersProvider with ChangeNotifier {

void checkServerUpdatesAvailable({
required Server server,
ApiClient? apiClient
}) async {
final client = apiClient ?? _apiClient;
setUpdateAvailableLoadStatus(LoadStatus.loading, true);
final result = await _apiClient!.checkServerUpdates();
final result = await client!.checkServerUpdates();
if (result['result'] == 'success') {
UpdateAvailableData data = UpdateAvailableData.fromJson(result['data']);
final gitHubResult = await _apiClient!.getUpdateChangelog(releaseTag: data.newVersion ?? data.currentVersion);
final gitHubResult = await client.getUpdateChangelog(releaseTag: data.newVersion ?? data.currentVersion);
if (gitHubResult['result'] == 'success') {
data.changelog = gitHubResult['body'];
}
Expand All @@ -186,11 +188,12 @@ class ServersProvider with ChangeNotifier {
}
}

Future initializateServer(Server server) async {
Future initializateServer(Server server, ApiClient apiClient) async {
final serverStatus = await _apiClient!.getServerStatus();
if (serverStatus['result'] == 'success') {
checkServerUpdatesAvailable( // Do not await
server: server,
apiClient: apiClient
);
}
}
Expand Down Expand Up @@ -222,8 +225,9 @@ class ServersProvider with ChangeNotifier {

if (defaultServer != null) {
_selectedServer = defaultServer;
_apiClient = ApiClient(server: defaultServer);
initializateServer(defaultServer);
final client = ApiClient(server: defaultServer);
_apiClient = client;
initializateServer(defaultServer, client);
}
}
else {
Expand Down
2 changes: 1 addition & 1 deletion lib/screens/home/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ class _HomeState extends State<Home> {
displacement: 95,
onRefresh: () async {
final result = await statusProvider.getServerStatus();
if (result == false) {
if (mounted && result == false) {
showSnacbkar(
appConfigProvider: appConfigProvider,
label: AppLocalizations.of(context)!.serverStatusNotRefreshed,
Expand Down
2 changes: 1 addition & 1 deletion lib/screens/home/management_modal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class _ManagementModalState extends State<ManagementModal> with SingleTickerProv
newStatus: value,
time: time
);
if (result != null) {
if (mounted && result != null) {
if (result != false) {
appConfigProvider.addLog(result);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/screens/settings/dns/cache_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class _CacheConfigDnsScreenState extends State<CacheConfigDnsScreen> {
cacheSizeController.text = dnsProvider.dnsInfo!.cacheSize.toString();
overrideMinTtlController.text = dnsProvider.dnsInfo!.cacheTtlMin.toString();
overrideMaxTtlController.text = dnsProvider.dnsInfo!.cacheTtlMax.toString();
optimisticCache = dnsProvider.dnsInfo!.cacheOptimistic;
optimisticCache = dnsProvider.dnsInfo!.cacheOptimistic ?? false;
validData = true;
super.initState();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/screens/top_items/top_items.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class _TopItemsScreenState extends State<TopItemsScreen> {
body: RefreshIndicator(
onRefresh: () async {
final result = await statusProvider.getServerStatus();
if (result == false) {
if (mounted && result == false) {
showSnacbkar(
appConfigProvider: appConfigProvider,
label: AppLocalizations.of(context)!.serverStatusNotRefreshed,
Expand Down
73 changes: 70 additions & 3 deletions lib/services/db/database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,76 @@ Future<Map<String, dynamic>> loadDb(bool acceptsDynamicTheme) async {
'adguard_home_manager.db',
version: 9,
onCreate: (Database db, int version) async {
await db.execute("CREATE TABLE servers (id TEXT PRIMARY KEY, name TEXT, connectionMethod TEXT, domain TEXT, path TEXT, port INTEGER, user TEXT, password TEXT, defaultServer INTEGER, authToken TEXT, runningOnHa INTEGER)");
await db.execute("CREATE TABLE appConfig (theme NUMERIC, overrideSslCheck NUMERIC, hideZeroValues NUMERIC, useDynamicColor NUMERIC, staticColor NUMERIC, useThemeColorForStatus NUMERIC, showTimeLogs NUMERIC, showIpLogs NUMERIC, combinedChart NUMERIC, doNotRememberVersion TEXT, hideServerAddress NUMERIC, homeTopItemsOrder TEXT)");
await db.execute("INSERT INTO appConfig (theme, overrideSslCheck, hideZeroValues, useDynamicColor, staticColor, useThemeColorForStatus, showTimeLogs, showIpLogs, combinedChart, hideServerAddress, homeTopItemsOrder) VALUES (0, 0, 0, ${acceptsDynamicTheme == true ? 1 : 0}, 0, 0, 0, 0, 0, 0, $homeTopItemsDefaultOrderString)");
await db.execute(
"""
CREATE TABLE
servers (
id TEXT PRIMARY KEY,
name TEXT,
connectionMethod TEXT,
domain TEXT,
path TEXT,
port INTEGER,
user TEXT,
password TEXT,
defaultServer INTEGER,
authToken TEXT,
runningOnHa INTEGER
)
"""
);

await db.execute(
"""
CREATE TABLE
appConfig (
theme NUMERIC,
overrideSslCheck NUMERIC,
hideZeroValues NUMERIC,
useDynamicColor NUMERIC,
staticColor NUMERIC,
useThemeColorForStatus NUMERIC,
showTimeLogs NUMERIC,
showIpLogs NUMERIC,
combinedChart NUMERIC,
doNotRememberVersion TEXT,
hideServerAddress NUMERIC,
homeTopItemsOrder TEXT
)
"""
);

await db.execute(
"""
INSERT INTO
appConfig (
theme,
overrideSslCheck,
hideZeroValues,
useDynamicColor,
staticColor,
useThemeColorForStatus,
showTimeLogs,
showIpLogs,
combinedChart,
hideServerAddress,
homeTopItemsOrder
)
VALUES (
0,
0,
0,
${acceptsDynamicTheme == true ? 1 : 0},
0,
0,
0,
0,
0,
0,
'$homeTopItemsDefaultOrderString'
)
"""
);
},
onUpgrade: (Database db, int oldVersion, int newVersion) async {
if (oldVersion == 1) {
Expand Down
Loading

0 comments on commit b25d3fd

Please sign in to comment.