Skip to content

Commit 634edf6

Browse files
authored
feat(ferry): expose store flush() in isolate client (#628)
1 parent 014d245 commit 634edf6

File tree

17 files changed

+604
-12
lines changed

17 files changed

+604
-12
lines changed

examples/pokemon_explorer/lib/__generated__/schema.schema.gql.dart

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/pokemon_explorer/lib/__generated__/serializers.gql.dart

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/pokemon_explorer/lib/main.dart

+14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:flutter/material.dart';
22
import 'package:get_it/get_it.dart';
33
import 'package:ferry/ferry.dart';
4+
import 'package:pokemon_explorer/src/flush.dart';
45

56
import './src/client.dart';
67
import './src/app.dart';
@@ -10,5 +11,18 @@ const apiUrl = "https://pokeapi.dev";
1011
void main() async {
1112
final client = await initClient();
1213
GetIt.I.registerLazySingleton<TypedLink>(() => client);
14+
GetIt.I.registerSingleton<Flush>(_SyncFlush(client));
15+
1316
runApp(const App());
1417
}
18+
19+
class _SyncFlush implements Flush {
20+
final Client client;
21+
22+
_SyncFlush(this.client);
23+
24+
@override
25+
void flush() {
26+
client.cache.store.flush();
27+
}
28+
}

examples/pokemon_explorer/lib/main_isolate.dart

+14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import 'package:ferry/ferry.dart';
2+
import 'package:ferry/ferry_isolate.dart';
23
import 'package:flutter/widgets.dart';
34
import 'package:get_it/get_it.dart';
45
import 'package:pokemon_explorer/src/app.dart';
6+
import 'package:pokemon_explorer/src/flush.dart';
57

68
import 'src/client_isolate.dart';
79

@@ -10,5 +12,17 @@ void main() async {
1012
WidgetsFlutterBinding.ensureInitialized();
1113
final client = await initIsolateClient();
1214
GetIt.I.registerLazySingleton<TypedLink>(() => client);
15+
GetIt.I.registerSingleton<Flush>(_IsolateFlush(client));
1316
runApp(const App());
1417
}
18+
19+
class _IsolateFlush implements Flush {
20+
final IsolateClient client;
21+
22+
_IsolateFlush(this.client);
23+
24+
@override
25+
void flush() {
26+
client.flushStore().then((_) => debugPrint('Store flushed'));
27+
}
28+
}

examples/pokemon_explorer/lib/src/app.dart

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
import 'package:flutter/material.dart';
2+
import 'package:get_it/get_it.dart';
3+
import 'package:pokemon_explorer/src/flush.dart';
24

35
import 'pokemon_list.dart';
46
import './pokemon_detail.dart';
57

6-
class App extends StatelessWidget {
8+
class App extends StatefulWidget {
79
const App({Key? key}) : super(key: key);
810

11+
@override
12+
State<App> createState() => _AppState();
13+
}
14+
15+
class _AppState extends State<App> with WidgetsBindingObserver {
916
@override
1017
Widget build(BuildContext context) {
1118
return MaterialApp(
@@ -24,4 +31,24 @@ class App extends StatelessWidget {
2431
},
2532
);
2633
}
34+
35+
@override
36+
void initState() {
37+
super.initState();
38+
WidgetsBinding.instance.addObserver(this);
39+
}
40+
41+
@override
42+
void dispose() {
43+
WidgetsBinding.instance.removeObserver(this);
44+
super.dispose();
45+
}
46+
47+
@override
48+
void didChangeAppLifecycleState(AppLifecycleState state) {
49+
print('AppLifecycleState: $state');
50+
if (state == AppLifecycleState.hidden) {
51+
GetIt.I<Flush>().flush();
52+
}
53+
}
2754
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/// Interface for flushing both Client and IsolateClient.
2+
abstract interface class Flush {
3+
void flush();
4+
}

examples/pokemon_explorer/macos/Podfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
platform :osx, '10.11'
1+
platform :osx, '10.14'
22

33
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
44
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
PODS:
2+
- FlutterMacOS (1.0.0)
3+
- path_provider_foundation (0.0.1):
4+
- Flutter
5+
- FlutterMacOS
6+
7+
DEPENDENCIES:
8+
- FlutterMacOS (from `Flutter/ephemeral`)
9+
- path_provider_foundation (from `Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin`)
10+
11+
EXTERNAL SOURCES:
12+
FlutterMacOS:
13+
:path: Flutter/ephemeral
14+
path_provider_foundation:
15+
:path: Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin
16+
17+
SPEC CHECKSUMS:
18+
FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24
19+
path_provider_foundation: 080d55be775b7414fd5a5ef3ac137b97b097e564
20+
21+
PODFILE CHECKSUM: 353c8bcc5d5b0994e508d035b5431cfe18c1dea7
22+
23+
COCOAPODS: 1.16.2

examples/pokemon_explorer/macos/Runner.xcodeproj/project.pbxproj

+67-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
archiveVersion = 1;
44
classes = {
55
};
6-
objectVersion = 51;
6+
objectVersion = 54;
77
objects = {
88

99
/* Begin PBXAggregateTarget section */
@@ -26,6 +26,7 @@
2626
33CC10F32044A3C60003C045 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 33CC10F22044A3C60003C045 /* Assets.xcassets */; };
2727
33CC10F62044A3C60003C045 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 33CC10F42044A3C60003C045 /* MainMenu.xib */; };
2828
33CC11132044BFA00003C045 /* MainFlutterWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33CC11122044BFA00003C045 /* MainFlutterWindow.swift */; };
29+
919762FE8B11176C0853F4CB /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 365657A0E780DBF30096592C /* Pods_Runner.framework */; };
2930
/* End PBXBuildFile section */
3031

3132
/* Begin PBXContainerItemProxy section */
@@ -54,7 +55,7 @@
5455
/* Begin PBXFileReference section */
5556
333000ED22D3DE5D00554162 /* Warnings.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Warnings.xcconfig; sourceTree = "<group>"; };
5657
335BBD1A22A9A15E00E9071D /* GeneratedPluginRegistrant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GeneratedPluginRegistrant.swift; sourceTree = "<group>"; };
57-
33CC10ED2044A3C60003C045 /* pokemon_explorer.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "pokemon_explorer.app"; sourceTree = BUILT_PRODUCTS_DIR; };
58+
33CC10ED2044A3C60003C045 /* pokemon_explorer.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = pokemon_explorer.app; sourceTree = BUILT_PRODUCTS_DIR; };
5859
33CC10F02044A3C60003C045 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
5960
33CC10F22044A3C60003C045 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Assets.xcassets; path = Runner/Assets.xcassets; sourceTree = "<group>"; };
6061
33CC10F52044A3C60003C045 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = "<group>"; };
@@ -66,21 +67,37 @@
6667
33E51913231747F40026EE4D /* DebugProfile.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = DebugProfile.entitlements; sourceTree = "<group>"; };
6768
33E51914231749380026EE4D /* Release.entitlements */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.entitlements; path = Release.entitlements; sourceTree = "<group>"; };
6869
33E5194F232828860026EE4D /* AppInfo.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = AppInfo.xcconfig; sourceTree = "<group>"; };
70+
365657A0E780DBF30096592C /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; };
71+
5D544C70276BD0508C9D8E0C /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = "<group>"; };
72+
6CFA503BAC79620E097EC60F /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = "<group>"; };
6973
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Release.xcconfig; sourceTree = "<group>"; };
7074
9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Debug.xcconfig; sourceTree = "<group>"; };
75+
A7DC8FF0A5EDF9F96CBB9AAF /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = "<group>"; };
7176
/* End PBXFileReference section */
7277

7378
/* Begin PBXFrameworksBuildPhase section */
7479
33CC10EA2044A3C60003C045 /* Frameworks */ = {
7580
isa = PBXFrameworksBuildPhase;
7681
buildActionMask = 2147483647;
7782
files = (
83+
919762FE8B11176C0853F4CB /* Pods_Runner.framework in Frameworks */,
7884
);
7985
runOnlyForDeploymentPostprocessing = 0;
8086
};
8187
/* End PBXFrameworksBuildPhase section */
8288

8389
/* Begin PBXGroup section */
90+
158ABBFD32872162376DD38A /* Pods */ = {
91+
isa = PBXGroup;
92+
children = (
93+
A7DC8FF0A5EDF9F96CBB9AAF /* Pods-Runner.debug.xcconfig */,
94+
5D544C70276BD0508C9D8E0C /* Pods-Runner.release.xcconfig */,
95+
6CFA503BAC79620E097EC60F /* Pods-Runner.profile.xcconfig */,
96+
);
97+
name = Pods;
98+
path = Pods;
99+
sourceTree = "<group>";
100+
};
84101
33BA886A226E78AF003329D5 /* Configs */ = {
85102
isa = PBXGroup;
86103
children = (
@@ -99,6 +116,7 @@
99116
33CEB47122A05771004F2AC0 /* Flutter */,
100117
33CC10EE2044A3C60003C045 /* Products */,
101118
D73912EC22F37F3D000D13A0 /* Frameworks */,
119+
158ABBFD32872162376DD38A /* Pods */,
102120
);
103121
sourceTree = "<group>";
104122
};
@@ -148,6 +166,7 @@
148166
D73912EC22F37F3D000D13A0 /* Frameworks */ = {
149167
isa = PBXGroup;
150168
children = (
169+
365657A0E780DBF30096592C /* Pods_Runner.framework */,
151170
);
152171
name = Frameworks;
153172
sourceTree = "<group>";
@@ -159,11 +178,13 @@
159178
isa = PBXNativeTarget;
160179
buildConfigurationList = 33CC10FB2044A3C60003C045 /* Build configuration list for PBXNativeTarget "Runner" */;
161180
buildPhases = (
181+
C3A64B3C0584FEA2CE432143 /* [CP] Check Pods Manifest.lock */,
162182
33CC10E92044A3C60003C045 /* Sources */,
163183
33CC10EA2044A3C60003C045 /* Frameworks */,
164184
33CC10EB2044A3C60003C045 /* Resources */,
165185
33CC110E2044A8840003C045 /* Bundle Framework */,
166186
3399D490228B24CF009A79C7 /* ShellScript */,
187+
82988F4DFC4A0FA9C616F97B /* [CP] Embed Pods Frameworks */,
167188
);
168189
buildRules = (
169190
);
@@ -182,7 +203,7 @@
182203
isa = PBXProject;
183204
attributes = {
184205
LastSwiftUpdateCheck = 0920;
185-
LastUpgradeCheck = 1300;
206+
LastUpgradeCheck = 1510;
186207
ORGANIZATIONNAME = "";
187208
TargetAttributes = {
188209
33CC10EC2044A3C60003C045 = {
@@ -235,6 +256,7 @@
235256
/* Begin PBXShellScriptBuildPhase section */
236257
3399D490228B24CF009A79C7 /* ShellScript */ = {
237258
isa = PBXShellScriptBuildPhase;
259+
alwaysOutOfDate = 1;
238260
buildActionMask = 2147483647;
239261
files = (
240262
);
@@ -270,6 +292,45 @@
270292
shellPath = /bin/sh;
271293
shellScript = "\"$FLUTTER_ROOT\"/packages/flutter_tools/bin/macos_assemble.sh && touch Flutter/ephemeral/tripwire";
272294
};
295+
82988F4DFC4A0FA9C616F97B /* [CP] Embed Pods Frameworks */ = {
296+
isa = PBXShellScriptBuildPhase;
297+
buildActionMask = 2147483647;
298+
files = (
299+
);
300+
inputFileListPaths = (
301+
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist",
302+
);
303+
name = "[CP] Embed Pods Frameworks";
304+
outputFileListPaths = (
305+
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist",
306+
);
307+
runOnlyForDeploymentPostprocessing = 0;
308+
shellPath = /bin/sh;
309+
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
310+
showEnvVarsInLog = 0;
311+
};
312+
C3A64B3C0584FEA2CE432143 /* [CP] Check Pods Manifest.lock */ = {
313+
isa = PBXShellScriptBuildPhase;
314+
buildActionMask = 2147483647;
315+
files = (
316+
);
317+
inputFileListPaths = (
318+
);
319+
inputPaths = (
320+
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
321+
"${PODS_ROOT}/Manifest.lock",
322+
);
323+
name = "[CP] Check Pods Manifest.lock";
324+
outputFileListPaths = (
325+
);
326+
outputPaths = (
327+
"$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt",
328+
);
329+
runOnlyForDeploymentPostprocessing = 0;
330+
shellPath = /bin/sh;
331+
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
332+
showEnvVarsInLog = 0;
333+
};
273334
/* End PBXShellScriptBuildPhase section */
274335

275336
/* Begin PBXSourcesBuildPhase section */
@@ -344,7 +405,7 @@
344405
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
345406
GCC_WARN_UNUSED_FUNCTION = YES;
346407
GCC_WARN_UNUSED_VARIABLE = YES;
347-
MACOSX_DEPLOYMENT_TARGET = 10.11;
408+
MACOSX_DEPLOYMENT_TARGET = 10.14;
348409
MTL_ENABLE_DEBUG_INFO = NO;
349410
SDKROOT = macosx;
350411
SWIFT_COMPILATION_MODE = wholemodule;
@@ -423,7 +484,7 @@
423484
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
424485
GCC_WARN_UNUSED_FUNCTION = YES;
425486
GCC_WARN_UNUSED_VARIABLE = YES;
426-
MACOSX_DEPLOYMENT_TARGET = 10.11;
487+
MACOSX_DEPLOYMENT_TARGET = 10.14;
427488
MTL_ENABLE_DEBUG_INFO = YES;
428489
ONLY_ACTIVE_ARCH = YES;
429490
SDKROOT = macosx;
@@ -470,7 +531,7 @@
470531
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
471532
GCC_WARN_UNUSED_FUNCTION = YES;
472533
GCC_WARN_UNUSED_VARIABLE = YES;
473-
MACOSX_DEPLOYMENT_TARGET = 10.11;
534+
MACOSX_DEPLOYMENT_TARGET = 10.14;
474535
MTL_ENABLE_DEBUG_INFO = NO;
475536
SDKROOT = macosx;
476537
SWIFT_COMPILATION_MODE = wholemodule;

examples/pokemon_explorer/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1300"
3+
LastUpgradeVersion = "1510"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

examples/pokemon_explorer/macos/Runner.xcworkspace/contents.xcworkspacedata

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import Cocoa
22
import FlutterMacOS
33

4-
@NSApplicationMain
4+
@main
55
class AppDelegate: FlutterAppDelegate {
66
override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
77
return true
88
}
9+
10+
override func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {
11+
return true
12+
}
913
}

examples/pokemon_explorer/macos/Runner/DebugProfile.entitlements

+2
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@
88
<true/>
99
<key>com.apple.security.network.server</key>
1010
<true/>
11+
<key>com.apple.security.network.client</key>
12+
<true/>
1113
</dict>
1214
</plist>

examples/pokemon_explorer/macos/Runner/Release.entitlements

+2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@
44
<dict>
55
<key>com.apple.security.app-sandbox</key>
66
<true/>
7+
<key>com.apple.security.network.client</key>
8+
<true/>
79
</dict>
810
</plist>

packages/ferry/lib/ferry_isolate.dart

+5
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,11 @@ class IsolateClient extends TypedLink {
367367
return value as T;
368368
});
369369
}
370+
371+
/// flushes the store, persisting all pending changes to the disk
372+
Future<void> flushStore() {
373+
return _handleSingleResponseCommand((sendPort) => FlushCommand(sendPort));
374+
}
370375
}
371376

372377
// initialization message, send when creating the client

0 commit comments

Comments
 (0)