mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2025-12-17 15:24:35 +01:00
#26 android home widget
This commit is contained in:
@@ -528,6 +528,12 @@ abstract class S {
|
||||
/// **'Go to'**
|
||||
String get goto;
|
||||
|
||||
/// No description provided for @homeWidgetUrlConfig.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Config home widget url'**
|
||||
String get homeWidgetUrlConfig;
|
||||
|
||||
/// No description provided for @host.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
|
||||
@@ -236,6 +236,9 @@ class SDe extends S {
|
||||
@override
|
||||
String get goto => 'Pfad öffnen';
|
||||
|
||||
@override
|
||||
String get homeWidgetUrlConfig => 'Home-Widget-Link konfigurieren';
|
||||
|
||||
@override
|
||||
String get host => 'Host';
|
||||
|
||||
|
||||
@@ -236,6 +236,9 @@ class SEn extends S {
|
||||
@override
|
||||
String get goto => 'Go to';
|
||||
|
||||
@override
|
||||
String get homeWidgetUrlConfig => 'Config home widget url';
|
||||
|
||||
@override
|
||||
String get host => 'Host';
|
||||
|
||||
|
||||
@@ -236,6 +236,9 @@ class SZh extends S {
|
||||
@override
|
||||
String get goto => '前往';
|
||||
|
||||
@override
|
||||
String get homeWidgetUrlConfig => '桌面部件链接配置';
|
||||
|
||||
@override
|
||||
String get host => '主机';
|
||||
|
||||
@@ -885,6 +888,9 @@ class SZhTw extends SZh {
|
||||
@override
|
||||
String get goto => '前往';
|
||||
|
||||
@override
|
||||
String get homeWidgetUrlConfig => '桌面部件鏈接配置';
|
||||
|
||||
@override
|
||||
String get host => '主機';
|
||||
|
||||
|
||||
@@ -36,5 +36,25 @@
|
||||
<meta-data
|
||||
android:name="flutterEmbedding"
|
||||
android:value="2" />
|
||||
|
||||
|
||||
<receiver
|
||||
android:name=".widget.HomeWidget"
|
||||
android:exported="false"
|
||||
android:label="StatusWidget">
|
||||
<intent-filter>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
||||
<action android:name="tech.lolli.toolbox.UPDATE_WIDGET" />
|
||||
<action android:name="miui.appwidget.action.APPWIDGET_UPDATE" />
|
||||
</intent-filter>
|
||||
<!--
|
||||
<meta-data
|
||||
android:name="miuiWidget"
|
||||
android:value="true" />
|
||||
-->
|
||||
<meta-data
|
||||
android:name="android.appwidget.provider"
|
||||
android:resource="@xml/home_widget" />
|
||||
</receiver>
|
||||
</application>
|
||||
</manifest>
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
package tech.lolli.toolbox.widget
|
||||
|
||||
import android.app.PendingIntent
|
||||
import android.appwidget.AppWidgetManager
|
||||
import android.appwidget.AppWidgetProvider
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.view.View
|
||||
import android.widget.RemoteViews
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import org.json.JSONObject
|
||||
import tech.lolli.toolbox.R
|
||||
import java.net.URL
|
||||
|
||||
class HomeWidget : AppWidgetProvider() {
|
||||
override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) {
|
||||
for (appWidgetId in appWidgetIds) {
|
||||
updateAppWidget(context, appWidgetManager, appWidgetId)
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
private fun updateAppWidget(context: Context, appWidgetManager: AppWidgetManager, appWidgetId: Int) {
|
||||
val views = RemoteViews(context.packageName, R.layout.home_widget)
|
||||
val sp = context.getSharedPreferences("FlutterSharedPreferences", Context.MODE_PRIVATE)
|
||||
var url = sp.getString("$appWidgetId", null)
|
||||
val gUrl = sp.getString("*", null)
|
||||
if (url.isNullOrEmpty()) {
|
||||
url = gUrl
|
||||
}
|
||||
|
||||
if (url.isNullOrEmpty()) {
|
||||
views.setViewVisibility(R.id.widget_cpu_label, View.INVISIBLE)
|
||||
views.setViewVisibility(R.id.widget_mem_label, View.INVISIBLE)
|
||||
views.setViewVisibility(R.id.widget_disk_label, View.INVISIBLE)
|
||||
views.setViewVisibility(R.id.widget_net_label, View.INVISIBLE)
|
||||
views.setTextViewText(R.id.widget_name, "ID: $appWidgetId")
|
||||
appWidgetManager.updateAppWidget(appWidgetId, views)
|
||||
return
|
||||
}
|
||||
|
||||
GlobalScope.launch(Dispatchers.IO) {
|
||||
val jsonStr = URL(url).readText()
|
||||
val jsonObject = JSONObject(jsonStr)
|
||||
val data = jsonObject.getJSONObject("data")
|
||||
val server = data.getString("name")
|
||||
val cpu = data.getString("cpu")
|
||||
val mem = data.getString("mem")
|
||||
val disk = data.getString("disk")
|
||||
val net = data.getString("net")
|
||||
|
||||
GlobalScope.launch(Dispatchers.Main) {
|
||||
// mem or disk is empty -> get status failed
|
||||
// (cpu | net) isEmpty -> data is not ready
|
||||
if (mem.isEmpty() || disk.isEmpty()) {
|
||||
return@launch
|
||||
}
|
||||
views.setTextViewText(R.id.widget_name, server)
|
||||
|
||||
views.setTextViewText(R.id.widget_cpu, cpu)
|
||||
views.setTextViewText(R.id.widget_mem, mem)
|
||||
views.setTextViewText(R.id.widget_disk, disk)
|
||||
views.setTextViewText(R.id.widget_net, net)
|
||||
|
||||
// eg: 17:17
|
||||
val timeStr = android.text.format.DateFormat.format("HH:mm", java.util.Date()).toString()
|
||||
views.setTextViewText(R.id.widget_time, timeStr)
|
||||
|
||||
appWidgetManager.updateAppWidget(appWidgetId, views)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
5
android/app/src/main/res/drawable/memory_24.xml
Normal file
5
android/app/src/main/res/drawable/memory_24.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<vector android:height="24dp" android:tint="@color/widgetTitleText"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M15,9L9,9v6h6L15,9zM13,13h-2v-2h2v2zM21,11L21,9h-2L19,7c0,-1.1 -0.9,-2 -2,-2h-2L15,3h-2v2h-2L11,3L9,3v2L7,5c-1.1,0 -2,0.9 -2,2v2L3,9v2h2v2L3,13v2h2v2c0,1.1 0.9,2 2,2h2v2h2v-2h2v2h2v-2h2c1.1,0 2,-0.9 2,-2v-2h2v-2h-2v-2h2zM17,17L7,17L7,7h10v10z"/>
|
||||
</vector>
|
||||
5
android/app/src/main/res/drawable/net_24.xml
Normal file
5
android/app/src/main/res/drawable/net_24.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<vector android:height="24dp" android:tint="@color/widgetTitleText"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M7.77,6.76L6.23,5.48 0.82,12l5.41,6.52 1.54,-1.28L3.42,12l4.35,-5.24zM7,13h2v-2L7,11v2zM17,11h-2v2h2v-2zM11,13h2v-2h-2v2zM17.77,5.48l-1.54,1.28L20.58,12l-4.35,5.24 1.54,1.28L23.18,12l-5.41,-6.52z"/>
|
||||
</vector>
|
||||
5
android/app/src/main/res/drawable/settings_24.xml
Normal file
5
android/app/src/main/res/drawable/settings_24.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<vector android:height="24dp" android:tint="@color/widgetTitleText"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M19.14,12.94c0.04,-0.3 0.06,-0.61 0.06,-0.94c0,-0.32 -0.02,-0.64 -0.07,-0.94l2.03,-1.58c0.18,-0.14 0.23,-0.41 0.12,-0.61l-1.92,-3.32c-0.12,-0.22 -0.37,-0.29 -0.59,-0.22l-2.39,0.96c-0.5,-0.38 -1.03,-0.7 -1.62,-0.94L14.4,2.81c-0.04,-0.24 -0.24,-0.41 -0.48,-0.41h-3.84c-0.24,0 -0.43,0.17 -0.47,0.41L9.25,5.35C8.66,5.59 8.12,5.92 7.63,6.29L5.24,5.33c-0.22,-0.08 -0.47,0 -0.59,0.22L2.74,8.87C2.62,9.08 2.66,9.34 2.86,9.48l2.03,1.58C4.84,11.36 4.8,11.69 4.8,12s0.02,0.64 0.07,0.94l-2.03,1.58c-0.18,0.14 -0.23,0.41 -0.12,0.61l1.92,3.32c0.12,0.22 0.37,0.29 0.59,0.22l2.39,-0.96c0.5,0.38 1.03,0.7 1.62,0.94l0.36,2.54c0.05,0.24 0.24,0.41 0.48,0.41h3.84c0.24,0 0.44,-0.17 0.47,-0.41l0.36,-2.54c0.59,-0.24 1.13,-0.56 1.62,-0.94l2.39,0.96c0.22,0.08 0.47,0 0.59,-0.22l1.92,-3.32c0.12,-0.22 0.07,-0.47 -0.12,-0.61L19.14,12.94zM12,15.6c-1.98,0 -3.6,-1.62 -3.6,-3.6s1.62,-3.6 3.6,-3.6s3.6,1.62 3.6,3.6S13.98,15.6 12,15.6z"/>
|
||||
</vector>
|
||||
5
android/app/src/main/res/drawable/speed_24.xml
Normal file
5
android/app/src/main/res/drawable/speed_24.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<vector android:height="24dp" android:tint="@color/widgetTitleText"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M20.38,8.57l-1.23,1.85a8,8 0,0 1,-0.22 7.58L5.07,18A8,8 0,0 1,15.58 6.85l1.85,-1.23A10,10 0,0 0,3.35 19a2,2 0,0 0,1.72 1h13.85a2,2 0,0 0,1.74 -1,10 10,0 0,0 -0.27,-10.44zM10.59,15.41a2,2 0,0 0,2.83 0l5.66,-8.49 -8.49,5.66a2,2 0,0 0,0 2.83z"/>
|
||||
</vector>
|
||||
5
android/app/src/main/res/drawable/storage_24.xml
Normal file
5
android/app/src/main/res/drawable/storage_24.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<vector android:height="24dp" android:tint="@color/widgetTitleText"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M2,20h20v-4L2,16v4zM4,17h2v2L4,19v-2zM2,4v4h20L22,4L2,4zM6,7L4,7L4,5h2v2zM2,14h20v-4L2,10v4zM4,11h2v2L4,13v-2z"/>
|
||||
</vector>
|
||||
5
android/app/src/main/res/drawable/widget_background.xml
Normal file
5
android/app/src/main/res/drawable/widget_background.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<corners android:radius="16dp"/>
|
||||
<solid android:color="@color/widgetBackground" />
|
||||
</shape>
|
||||
147
android/app/src/main/res/layout/home_widget.xml
Normal file
147
android/app/src/main/res/layout/home_widget.xml
Normal file
@@ -0,0 +1,147 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/widget_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/widget_background"
|
||||
android:padding="17dp"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/widget_name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/widgetTitleText"
|
||||
android:textSize="23sp"
|
||||
android:textStyle="bold"
|
||||
tools:text="Server Name" />
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/widget_container_inner"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingTop="13dp">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/widget_cpu_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="2.7dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="17dp"
|
||||
android:layout_height="17dp"
|
||||
android:src="@drawable/speed_24">
|
||||
</ImageView>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/widget_cpu"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="11dp"
|
||||
android:singleLine="true"
|
||||
android:ellipsize = "marquee"
|
||||
android:textColor="@color/widgetTitleText"
|
||||
android:textSize="12.7sp"
|
||||
tools:text="CPU" />
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/widget_mem_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="2.7dp"
|
||||
android:layout_below="@id/widget_cpu_label"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="17dp"
|
||||
android:layout_height="17dp"
|
||||
android:src="@drawable/memory_24">
|
||||
</ImageView>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/widget_mem"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="11dp"
|
||||
android:maxLines="1"
|
||||
android:textColor="@color/widgetTitleText"
|
||||
android:textSize="12.7sp"
|
||||
tools:text="Mem" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/widget_disk_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="2.7dp"
|
||||
android:layout_below="@id/widget_mem_label"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="17dp"
|
||||
android:layout_height="17dp"
|
||||
android:src="@drawable/storage_24">
|
||||
</ImageView>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/widget_disk"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="11dp"
|
||||
android:maxLines="1"
|
||||
android:textColor="@color/widgetTitleText"
|
||||
android:textSize="12.7sp"
|
||||
tools:text="Disk" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/widget_net_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/widget_disk_label"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="17dp"
|
||||
android:layout_height="17dp"
|
||||
android:src="@drawable/net_24">
|
||||
</ImageView>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/widget_net"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="11dp"
|
||||
android:maxLines="1"
|
||||
android:textColor="@color/widgetTitleText"
|
||||
android:textSize="12.7sp"
|
||||
tools:text="Net" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/widget_time"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:maxLines="2"
|
||||
android:textColor="@color/widgetSummaryText"
|
||||
android:textSize="11sp"
|
||||
tools:text="UpdateTime" />
|
||||
|
||||
</RelativeLayout>
|
||||
6
android/app/src/main/res/values-night/colors.xml
Normal file
6
android/app/src/main/res/values-night/colors.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="widgetBackground">#000000</color>
|
||||
<color name="widgetTitleText">#FFFFFF</color>
|
||||
<color name="widgetSummaryText">#BBBBBB</color>
|
||||
</resources>
|
||||
7
android/app/src/main/res/values/colors.xml
Normal file
7
android/app/src/main/res/values/colors.xml
Normal file
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<resources>
|
||||
<color name="colorLaunch">#EEEEEE</color>
|
||||
<color name="widgetBackground">#FFFFFF</color>
|
||||
<color name="widgetTitleText">#000000</color>
|
||||
<color name="widgetSummaryText">#333333</color>
|
||||
</resources>
|
||||
11
android/app/src/main/res/xml/home_widget.xml
Normal file
11
android/app/src/main/res/xml/home_widget.xml
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:minWidth="110dp"
|
||||
android:maxHeight="110dp"
|
||||
android:maxWidth="110dp"
|
||||
android:minHeight="110dp"
|
||||
android:updatePeriodMillis="1800001"
|
||||
android:initialLayout="@layout/home_widget"
|
||||
android:resizeMode="none"
|
||||
android:widgetCategory="home_screen">
|
||||
</appwidget-provider>
|
||||
@@ -17,7 +17,6 @@
|
||||
E33A3E392A626DCD009744AB /* SwiftUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E33A3E382A626DCD009744AB /* SwiftUI.framework */; };
|
||||
E33A3E3C2A626DCE009744AB /* StatusWidgetBundle.swift in Sources */ = {isa = PBXBuildFile; fileRef = E33A3E3B2A626DCE009744AB /* StatusWidgetBundle.swift */; };
|
||||
E33A3E402A626DCE009744AB /* StatusWidget.swift in Sources */ = {isa = PBXBuildFile; fileRef = E33A3E3F2A626DCE009744AB /* StatusWidget.swift */; };
|
||||
E33A3E432A626DD0009744AB /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E33A3E422A626DD0009744AB /* Assets.xcassets */; };
|
||||
E33A3E452A626DD0009744AB /* StatusWidget.intentdefinition in Sources */ = {isa = PBXBuildFile; fileRef = E33A3E412A626DCE009744AB /* StatusWidget.intentdefinition */; };
|
||||
E33A3E462A626DD0009744AB /* StatusWidget.intentdefinition in Sources */ = {isa = PBXBuildFile; fileRef = E33A3E412A626DCE009744AB /* StatusWidget.intentdefinition */; };
|
||||
E33A3E492A626DD0009744AB /* StatusWidgetExtension.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = E33A3E352A626DCD009744AB /* StatusWidgetExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
|
||||
@@ -81,7 +80,6 @@
|
||||
E33A3E3B2A626DCE009744AB /* StatusWidgetBundle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusWidgetBundle.swift; sourceTree = "<group>"; };
|
||||
E33A3E3F2A626DCE009744AB /* StatusWidget.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusWidget.swift; sourceTree = "<group>"; };
|
||||
E33A3E412A626DCE009744AB /* StatusWidget.intentdefinition */ = {isa = PBXFileReference; lastKnownFileType = file.intentdefinition; path = StatusWidget.intentdefinition; sourceTree = "<group>"; };
|
||||
E33A3E422A626DD0009744AB /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
||||
E33A3E442A626DD0009744AB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
E398BF6A29BDB34500FE4FD5 /* Runner.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Runner.entitlements; sourceTree = "<group>"; };
|
||||
E3DB67EC2A31FE200027B8CB /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
|
||||
@@ -182,7 +180,6 @@
|
||||
E33A3E3B2A626DCE009744AB /* StatusWidgetBundle.swift */,
|
||||
E33A3E3F2A626DCE009744AB /* StatusWidget.swift */,
|
||||
E33A3E412A626DCE009744AB /* StatusWidget.intentdefinition */,
|
||||
E33A3E422A626DD0009744AB /* Assets.xcassets */,
|
||||
E33A3E442A626DD0009744AB /* Info.plist */,
|
||||
);
|
||||
path = StatusWidget;
|
||||
@@ -286,7 +283,6 @@
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
E33A3E432A626DD0009744AB /* Assets.xcassets in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
@@ -474,7 +470,7 @@
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
|
||||
CURRENT_PROJECT_VERSION = 376;
|
||||
CURRENT_PROJECT_VERSION = 377;
|
||||
DEVELOPMENT_TEAM = BA88US33G6;
|
||||
ENABLE_BITCODE = NO;
|
||||
INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist";
|
||||
@@ -482,7 +478,7 @@
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
);
|
||||
MARKETING_VERSION = 1.0.376;
|
||||
MARKETING_VERSION = 1.0.377;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
||||
@@ -606,7 +602,7 @@
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
|
||||
CURRENT_PROJECT_VERSION = 376;
|
||||
CURRENT_PROJECT_VERSION = 377;
|
||||
DEVELOPMENT_TEAM = BA88US33G6;
|
||||
ENABLE_BITCODE = NO;
|
||||
INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist";
|
||||
@@ -614,7 +610,7 @@
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
);
|
||||
MARKETING_VERSION = 1.0.376;
|
||||
MARKETING_VERSION = 1.0.377;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
||||
@@ -632,7 +628,7 @@
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CODE_SIGN_ENTITLEMENTS = Runner/Runner.entitlements;
|
||||
CURRENT_PROJECT_VERSION = 376;
|
||||
CURRENT_PROJECT_VERSION = 377;
|
||||
DEVELOPMENT_TEAM = BA88US33G6;
|
||||
ENABLE_BITCODE = NO;
|
||||
INFOPLIST_FILE = "Runner/Info-$(CONFIGURATION).plist";
|
||||
@@ -640,7 +636,7 @@
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
);
|
||||
MARKETING_VERSION = 1.0.376;
|
||||
MARKETING_VERSION = 1.0.377;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
|
||||
@@ -661,7 +657,7 @@
|
||||
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
|
||||
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
CURRENT_PROJECT_VERSION = 377;
|
||||
DEVELOPMENT_TEAM = BA88US33G6;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu11;
|
||||
GENERATE_INFOPLIST_FILE = YES;
|
||||
@@ -674,7 +670,7 @@
|
||||
"@executable_path/Frameworks",
|
||||
"@executable_path/../../Frameworks",
|
||||
);
|
||||
MARKETING_VERSION = 1.0;
|
||||
MARKETING_VERSION = 1.0.377;
|
||||
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
|
||||
MTL_FAST_MATH = YES;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox.StatusWidget;
|
||||
@@ -700,7 +696,7 @@
|
||||
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
|
||||
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
CURRENT_PROJECT_VERSION = 377;
|
||||
DEVELOPMENT_TEAM = BA88US33G6;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu11;
|
||||
GENERATE_INFOPLIST_FILE = YES;
|
||||
@@ -713,7 +709,7 @@
|
||||
"@executable_path/Frameworks",
|
||||
"@executable_path/../../Frameworks",
|
||||
);
|
||||
MARKETING_VERSION = 1.0;
|
||||
MARKETING_VERSION = 1.0.377;
|
||||
MTL_FAST_MATH = YES;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox.StatusWidget;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
@@ -736,7 +732,7 @@
|
||||
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
|
||||
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
CURRENT_PROJECT_VERSION = 377;
|
||||
DEVELOPMENT_TEAM = BA88US33G6;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu11;
|
||||
GENERATE_INFOPLIST_FILE = YES;
|
||||
@@ -749,7 +745,7 @@
|
||||
"@executable_path/Frameworks",
|
||||
"@executable_path/../../Frameworks",
|
||||
);
|
||||
MARKETING_VERSION = 1.0;
|
||||
MARKETING_VERSION = 1.0.377;
|
||||
MTL_FAST_MATH = YES;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.lollipopkit.toolbox.StatusWidget;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
<key>INIntentParameterMetadataCapitalization</key>
|
||||
<string>Characters</string>
|
||||
<key>INIntentParameterMetadataDefaultValue</key>
|
||||
<string>https://push.lolli.tech</string>
|
||||
<string>https://</string>
|
||||
<key>INIntentParameterMetadataDefaultValueID</key>
|
||||
<string>wwvqC2</string>
|
||||
<key>INIntentParameterMetadataDisableAutocorrect</key>
|
||||
|
||||
@@ -70,7 +70,7 @@ struct StatusWidgetEntryView : View {
|
||||
case .loading:
|
||||
ProgressView().padding()
|
||||
case .error(let descriotion):
|
||||
Text(descriotion)
|
||||
Text(descriotion).padding(.all, 13)
|
||||
case .normal:
|
||||
VStack(alignment: .leading, spacing: 5.7) {
|
||||
Text(entry.data.name).font(.system(.title3))
|
||||
@@ -108,8 +108,8 @@ struct StatusWidget_Previews: PreviewProvider {
|
||||
|
||||
struct StatusLoader {
|
||||
static func fetch(completion: @escaping (Result<Status, Error>) -> Void) {
|
||||
if url == nil || url == "" {
|
||||
completion(.failure(NSError(domain: domain, code: 1, userInfo: [NSLocalizedDescriptionKey: "Please longpress it to config first."])))
|
||||
if let url = url, url.count < 12 {
|
||||
completion(.failure(NSError(domain: domain, code: 1, userInfo: [NSLocalizedDescriptionKey: "https://github.com/lollipopkit/server_box_monitor/wiki"])))
|
||||
return
|
||||
}
|
||||
let URL = URL(string: url!)!
|
||||
@@ -134,7 +134,6 @@ struct StatusLoader {
|
||||
}
|
||||
|
||||
static func getStatus(fromData data: Foundation.Data) -> Result<Status, Error> {
|
||||
|
||||
let jsonAll = try! JSONSerialization.jsonObject(with: data, options: []) as! [String: Any]
|
||||
let code = jsonAll["code"] as! Int
|
||||
if (code != 0) {
|
||||
@@ -194,7 +193,6 @@ struct DetailItem: View {
|
||||
|
||||
func date2String(_ date:Date, dateFormat:String = "yyyy-MM-dd HH:mm:ss") -> String {
|
||||
let formatter = DateFormatter()
|
||||
formatter.locale = Locale.init(identifier: "zh_CN")
|
||||
formatter.dateFormat = dateFormat
|
||||
let date = formatter.string(from: date)
|
||||
return date
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
class BuildData {
|
||||
static const String name = "ServerBox";
|
||||
static const int build = 376;
|
||||
static const String engine = "3.10.5";
|
||||
static const String buildAt = "2023-07-08 15:09:08.542818";
|
||||
static const int modifications = 2;
|
||||
static const int build = 377;
|
||||
static const String engine = "3.10.6";
|
||||
static const String buildAt = "2023-07-16 23:02:53.506145";
|
||||
static const int modifications = 3;
|
||||
}
|
||||
|
||||
@@ -72,6 +72,7 @@
|
||||
"getPushTokenFailed": "Push-Token kann nicht abgerufen werden",
|
||||
"gettingToken": "Getting token...",
|
||||
"goto": "Pfad öffnen",
|
||||
"homeWidgetUrlConfig": "Home-Widget-Link konfigurieren",
|
||||
"host": "Host",
|
||||
"httpFailedWithCode": "Anfrage fehlgeschlagen, Statuscode: {code}",
|
||||
"image": "Image",
|
||||
|
||||
@@ -72,6 +72,7 @@
|
||||
"getPushTokenFailed": "Can't fetch push token",
|
||||
"gettingToken": "Getting token...",
|
||||
"goto": "Go to",
|
||||
"homeWidgetUrlConfig": "Config home widget url",
|
||||
"host": "Host",
|
||||
"httpFailedWithCode": "request failed, status code: {code}",
|
||||
"image": "Image",
|
||||
|
||||
@@ -72,6 +72,7 @@
|
||||
"getPushTokenFailed": "未能获取到推送token",
|
||||
"gettingToken": "正在获取Token...",
|
||||
"goto": "前往",
|
||||
"homeWidgetUrlConfig": "桌面部件链接配置",
|
||||
"host": "主机",
|
||||
"httpFailedWithCode": "请求失败, 状态码: {code}",
|
||||
"image": "镜像",
|
||||
|
||||
@@ -72,6 +72,7 @@
|
||||
"getPushTokenFailed": "未能獲取到推送token",
|
||||
"gettingToken": "正在獲取Token...",
|
||||
"goto": "前往",
|
||||
"homeWidgetUrlConfig": "桌面部件鏈接配置",
|
||||
"host": "主機",
|
||||
"httpFailedWithCode": "請求失敗, 狀態碼: {code}",
|
||||
"image": "鏡像",
|
||||
|
||||
@@ -6,6 +6,7 @@ import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
import 'package:flutter_highlight/theme_map.dart';
|
||||
import 'package:flutter_material_color_picker/flutter_material_color_picker.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:toolbox/core/extension/locale.dart';
|
||||
import 'package:toolbox/core/extension/navigator.dart';
|
||||
import 'package:toolbox/core/route.dart';
|
||||
@@ -51,6 +52,7 @@ class _SettingPageState extends State<SettingPage> {
|
||||
late final ServerProvider _serverProvider;
|
||||
late MediaQueryData _media;
|
||||
late S _s;
|
||||
late SharedPreferences _sp;
|
||||
|
||||
final _selectedColorValue = ValueNotifier(0);
|
||||
final _launchPageIdx = ValueNotifier(0);
|
||||
@@ -89,6 +91,8 @@ class _SettingPageState extends State<SettingPage> {
|
||||
_editorDarkTheme.value = _setting.editorDarkTheme.fetch()!;
|
||||
_keyboardType.value = _setting.keyboardType.fetch()!;
|
||||
_rotateQuarter.value = _setting.fullScreenRotateQuarter.fetch()!;
|
||||
SharedPreferences.setPrefix('');
|
||||
SharedPreferences.getInstance().then((value) => _sp = value);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -141,6 +145,7 @@ class _SettingPageState extends State<SettingPage> {
|
||||
}
|
||||
if (isAndroid) {
|
||||
children.add(_buildBgRun());
|
||||
children.add(_buildAndroidWidgetSharedPreference());
|
||||
}
|
||||
return Column(
|
||||
children: children.map((e) => RoundRectCard(e)).toList(),
|
||||
@@ -836,4 +841,56 @@ class _SettingPageState extends State<SettingPage> {
|
||||
).go(context),
|
||||
);
|
||||
}
|
||||
|
||||
void _saveWidgetSP(String data, Map<String, String> old) {
|
||||
context.pop();
|
||||
try {
|
||||
final map = Map<String, String>.from(json.decode(data));
|
||||
final keysDel = old.keys.toSet().difference(map.keys.toSet());
|
||||
for (final key in keysDel) {
|
||||
_sp.remove(key);
|
||||
}
|
||||
map.forEach((key, value) {
|
||||
_sp.setString(key, value);
|
||||
});
|
||||
showSnackBar(context, Text(_s.success));
|
||||
} catch (e) {
|
||||
showSnackBar(context, Text(e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildAndroidWidgetSharedPreference() {
|
||||
return ListTile(
|
||||
title: Text(_s.homeWidgetUrlConfig),
|
||||
trailing: const Icon(Icons.arrow_forward_ios, size: 13),
|
||||
onTap: () {
|
||||
final data = <String, String>{};
|
||||
_sp.getKeys().forEach((key) {
|
||||
final val = _sp.getString(key);
|
||||
if (val != null) {
|
||||
data[key] = val;
|
||||
}
|
||||
});
|
||||
final ctrl = TextEditingController(text: json.encode(data));
|
||||
showRoundDialog(
|
||||
context: context,
|
||||
title: Text(_s.homeWidgetUrlConfig),
|
||||
child: Input(
|
||||
controller: ctrl,
|
||||
label: 'JSON',
|
||||
type: TextInputType.visiblePassword,
|
||||
maxLines: 7,
|
||||
onSubmitted: (p0) => _saveWidgetSP(p0, data),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
_saveWidgetSP(ctrl.text, data);
|
||||
},
|
||||
child: Text(_s.ok),
|
||||
),
|
||||
]);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,11 +8,13 @@ import Foundation
|
||||
import flutter_volume_controller
|
||||
import path_provider_foundation
|
||||
import share_plus
|
||||
import shared_preferences_foundation
|
||||
import url_launcher_macos
|
||||
|
||||
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
|
||||
FlutterVolumeControllerPlugin.register(with: registry.registrar(forPlugin: "FlutterVolumeControllerPlugin"))
|
||||
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
|
||||
SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin"))
|
||||
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
|
||||
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
|
||||
}
|
||||
|
||||
@@ -475,9 +475,9 @@
|
||||
baseConfigurationReference = C1C758C41C4E208965A68933 /* Pods-RunnerTests.debug.xcconfig */;
|
||||
buildSettings = {
|
||||
BUNDLE_LOADER = "$(TEST_HOST)";
|
||||
CURRENT_PROJECT_VERSION = 376;
|
||||
CURRENT_PROJECT_VERSION = 377;
|
||||
GENERATE_INFOPLIST_FILE = YES;
|
||||
MARKETING_VERSION = 1.0.376;
|
||||
MARKETING_VERSION = 1.0.377;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = tech.lolli.serverBox.RunnerTests;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_VERSION = 5.0;
|
||||
@@ -490,9 +490,9 @@
|
||||
baseConfigurationReference = 15AF97DF993E8968098D6EBE /* Pods-RunnerTests.release.xcconfig */;
|
||||
buildSettings = {
|
||||
BUNDLE_LOADER = "$(TEST_HOST)";
|
||||
CURRENT_PROJECT_VERSION = 376;
|
||||
CURRENT_PROJECT_VERSION = 377;
|
||||
GENERATE_INFOPLIST_FILE = YES;
|
||||
MARKETING_VERSION = 1.0.376;
|
||||
MARKETING_VERSION = 1.0.377;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = tech.lolli.serverBox.RunnerTests;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_VERSION = 5.0;
|
||||
@@ -505,9 +505,9 @@
|
||||
baseConfigurationReference = 7CFA7DE7FABA75685DFB6948 /* Pods-RunnerTests.profile.xcconfig */;
|
||||
buildSettings = {
|
||||
BUNDLE_LOADER = "$(TEST_HOST)";
|
||||
CURRENT_PROJECT_VERSION = 376;
|
||||
CURRENT_PROJECT_VERSION = 377;
|
||||
GENERATE_INFOPLIST_FILE = YES;
|
||||
MARKETING_VERSION = 1.0.376;
|
||||
MARKETING_VERSION = 1.0.377;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = tech.lolli.serverBox.RunnerTests;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_VERSION = 5.0;
|
||||
|
||||
56
pubspec.lock
56
pubspec.lock
@@ -774,6 +774,62 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.2.1"
|
||||
shared_preferences:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: shared_preferences
|
||||
sha256: "0344316c947ffeb3a529eac929e1978fcd37c26be4e8468628bac399365a3ca1"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.2.0"
|
||||
shared_preferences_android:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_android
|
||||
sha256: fe8401ec5b6dcd739a0fe9588802069e608c3fdbfd3c3c93e546cf2f90438076
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.2.0"
|
||||
shared_preferences_foundation:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_foundation
|
||||
sha256: f39696b83e844923b642ce9dd4bd31736c17e697f6731a5adf445b1274cf3cd4
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.3.2"
|
||||
shared_preferences_linux:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_linux
|
||||
sha256: "71d6806d1449b0a9d4e85e0c7a917771e672a3d5dc61149cc9fac871115018e1"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.3.0"
|
||||
shared_preferences_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_platform_interface
|
||||
sha256: "23b052f17a25b90ff2b61aad4cc962154da76fb62848a9ce088efe30d7c50ab1"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.3.0"
|
||||
shared_preferences_web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_web
|
||||
sha256: "7347b194fb0bbeb4058e6a4e87ee70350b6b2b90f8ac5f8bd5b3a01548f6d33a"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.2.0"
|
||||
shared_preferences_windows:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shared_preferences_windows
|
||||
sha256: f95e6a43162bce43c9c3405f3eb6f39e5b5d11f65fab19196cf8225e2777624d
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.3.0"
|
||||
shelf:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
||||
@@ -66,6 +66,7 @@ dependencies:
|
||||
code_text_field: ^1.1.0
|
||||
flutter_volume_controller: ^1.2.6
|
||||
nil: ^1.1.1
|
||||
shared_preferences: ^2.1.1
|
||||
|
||||
dev_dependencies:
|
||||
flutter_native_splash: ^2.1.6
|
||||
|
||||
Reference in New Issue
Block a user