opt.: ios home widget

This commit is contained in:
lollipopkit
2023-10-15 16:56:53 +08:00
parent 9cf9a6fbc5
commit 2e17054037
6 changed files with 149 additions and 141 deletions

View File

@@ -4,22 +4,30 @@ import Flutter
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
let controller : FlutterViewController = window?.rootViewController as! FlutterViewController
let methodChannel = FlutterMethodChannel(name: "tech.lolli.toolbox/home_widget", binaryMessenger: controller.binaryMessenger)
methodChannel.setMethodCallHandler({
(call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
if call.method == "update" {
if #available(iOS 14.0, *) {
WidgetCenter.shared.reloadTimelines(ofKind: "StatusWidget")
let controller : FlutterViewController = window?.rootViewController as! FlutterViewController
let methodChannel = FlutterMethodChannel(name: "tech.lolli.toolbox/home_widget", binaryMessenger: controller.binaryMessenger)
methodChannel.setMethodCallHandler({(call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
if call.method == "update" {
if #available(iOS 14.0, *) {
WidgetCenter.shared.reloadTimelines(ofKind: "StatusWidget")
}
}
})
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
override func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
if url.scheme == "https" || url.scheme == "http" {
UIApplication.shared.open(url)
} else {
// Pass
}
}
})
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
return true
}
}

View File

@@ -9,6 +9,8 @@ import Foundation
let accessoryKey = "accessory_widget_url"
let helpUrl = URL(string: "https://github.com/lollipopkit/flutter_server_box/wiki#home-widget--watchos-app")!
extension Date {
func toStr() -> String {
let formatter = DateFormatter()
@@ -19,9 +21,14 @@ extension Date {
}
}
enum ErrType: Error {
case url(String)
case http(String)
}
enum ContentState {
case loading
case error(String)
case error(ErrType)
case normal(Status)
}