Skip to content

Commit

Permalink
support load data by app group
Browse files Browse the repository at this point in the history
  • Loading branch information
Notsfsssf committed Mar 28, 2021
1 parent 917a752 commit da47b58
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 17 deletions.
5 changes: 5 additions & 0 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
7C8B5972260F680600098D5C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
7CC54C3726103351009033DF /* Runner.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Runner.entitlements; sourceTree = "<group>"; };
7CD2072C2610741D00677759 /* WidgetkitPlugin.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WidgetkitPlugin.swift; sourceTree = "<group>"; };
7CD2074626107D5600677759 /* SSSGridmanExtension.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = SSSGridmanExtension.entitlements; sourceTree = "<group>"; };
9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = "<group>"; };
9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = "<group>"; };
97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -157,6 +158,7 @@
97C146E51CF9000F007C117D = {
isa = PBXGroup;
children = (
7CD2074626107D5600677759 /* SSSGridmanExtension.entitlements */,
9740EEB11CF90186004384FC /* Flutter */,
97C146F01CF9000F007C117D /* Runner */,
7C8B596C260F680500098D5C /* SSSGridman */,
Expand Down Expand Up @@ -515,6 +517,7 @@
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_ENTITLEMENTS = SSSGridmanExtension.entitlements;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = L9F8ZWCR8Z;
GCC_C_LANGUAGE_STANDARD = gnu11;
Expand Down Expand Up @@ -548,6 +551,7 @@
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_ENTITLEMENTS = SSSGridmanExtension.entitlements;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = L9F8ZWCR8Z;
GCC_C_LANGUAGE_STANDARD = gnu11;
Expand Down Expand Up @@ -578,6 +582,7 @@
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_ENTITLEMENTS = SSSGridmanExtension.entitlements;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = L9F8ZWCR8Z;
GCC_C_LANGUAGE_STANDARD = gnu11;
Expand Down
4 changes: 3 additions & 1 deletion ios/Runner/Runner.entitlements
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<plist version="1.0">
<dict>
<key>com.apple.security.application-groups</key>
<array/>
<array>
<string>group.pixez</string>
</array>
</dict>
</plist>
12 changes: 7 additions & 5 deletions ios/Runner/WidgetkitPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class WidgetkitPlugin {
binaryMessenger: controller.binaryMessenger)
batteryChannel.setMethodCallHandler({
(call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
if call.method == "getBatteryLevel" {
if call.method == "notify" {
notify()
result(nil)
return
Expand All @@ -23,10 +23,12 @@ public class WidgetkitPlugin {
}

private static func notify() {
if let data = UserDefaults(suiteName: "com.perol.pixez")!.string(forKey: "flutter.app_widget_data") {
let host = UserDefaults(suiteName: "com.perol.pixez")!.string(forKey: "flutter.picture_source") ?? "i.pximg.net"
let time = UserDefaults(suiteName: "com.perol.pixez")!.integer(forKey: "flutter.app_widget_time")
let userDefault = UserDefaults(suiteName: "com.perol.pixez")
if let data = UserDefaults.standard.string(forKey: "flutter.app_widget_data"){
let host = UserDefaults.standard.string(forKey: "flutter.picture_source") ?? "i.pximg.net"
let time = UserDefaults.standard.integer(forKey: "flutter.app_widget_time")
print(host)
print(time)
let userDefault = UserDefaults(suiteName: "group.pixez")
userDefault?.setValue(host, forKey: "widgetkit.picture_source")
userDefault?.setValue(data, forKey: "widgetkit.app_widget_data")
userDefault?.setValue(time, forKey: "widgetkit.app_widget_time")
Expand Down
16 changes: 8 additions & 8 deletions ios/SSSGridman/SSSGridman.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ struct Provider: IntentTimelineProvider {
func getTimeline(for configuration: ConfigurationIntent, in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
var entries: [SimpleEntry] = []
print("time line start")
UserDefaults.standard.string(forKey: <#T##String#>)
print(UserDefaults(suiteName: "com.perol.pixez")!.string(forKey: "flutter.app_widget_data"))
let userDefault = UserDefaults(suiteName: "group.pixez")
print(userDefault!.string(forKey: "widgetkit.app_widget_data"))

if let data = UserDefaults(suiteName: "com.perol.pixez")!.string(forKey: "flutter.app_widget_data") {
let host = UserDefaults(suiteName: "com.perol.pixez")!.string(forKey: "flutter.picture_source") ?? "i.pximg.net"
let time = UserDefaults(suiteName: "com.perol.pixez")!.integer(forKey: "flutter.app_widget_time")
if let data = userDefault!.string(forKey: "widgetkit.app_widget_data") {
let host = userDefault!.string(forKey: "widgetkit.picture_source") ?? "i.pximg.net"
let time = userDefault!.integer(forKey: "widgetkit.app_widget_time")
print(host)
print(time)
let decoder = JSONDecoder()
Expand All @@ -75,10 +75,10 @@ struct Provider: IntentTimelineProvider {
}.resume()
if(time<10){
let count = time+1
UserDefaults(suiteName: "com.perol.pixez")!.setValue(count, forKey: "flutter.app_widget_time")
userDefault!.setValue(count, forKey: "widgetkit.app_widget_time")
}else{
UserDefaults(suiteName: "com.perol.pixez")!.removeObject(forKey: "flutter.app_widget_time")
UserDefaults(suiteName: "com.perol.pixez")!.removeObject(forKey: "flutter.app_widget_data")
userDefault!.removeObject(forKey: "widgetkit.app_widget_time")
userDefault!.removeObject(forKey: "widgetkit.app_widget_data")
}
}else{
let currentDate = Date()
Expand Down
10 changes: 10 additions & 0 deletions ios/SSSGridmanExtension.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.application-groups</key>
<array>
<string>group.pixez</string>
</array>
</dict>
</plist>
9 changes: 7 additions & 2 deletions lib/lighting/lighting_store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import 'package:pixez/models/illust.dart';
import 'package:pixez/models/recommend.dart';
import 'package:pixez/network/api_client.dart';
import 'package:pixez/page/picture/illust_store.dart';
import 'package:pixez/widgetkit_plugin.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

part 'lighting_store.g.dart';
Expand Down Expand Up @@ -88,8 +89,12 @@ abstract class _LightingStoreBase with Store {
nextUrl = recommend.nextUrl;
iStores.clear();
iStores.addAll(recommend.illusts.map((e) => IllustStore(e.id, e)));
if (userSetting.prefs.getString("app_widget_data") == null)
userSetting.prefs.setString("app_widget_data", jsonEncode(recommend));
if (userSetting.prefs.getString("app_widget_data") == null) {
await userSetting.prefs
.setString("app_widget_data", jsonEncode(recommend));

}
WidgetkitPlugin.notify();
controller?.refreshCompleted();
return true;
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion lib/widgetkit_plugin.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/services.dart';

class WeissPlugin {
class WidgetkitPlugin {
static const platform = const MethodChannel('com.perol.dev/widgetkit');

static Future<void> notify() async {
Expand Down

0 comments on commit da47b58

Please sign in to comment.