Skip to content

Commit

Permalink
Merge pull request #32 from NextFaze/feature/remote_config_manup
Browse files Browse the repository at this point in the history
Support Firebase Remote Config as ManUp Source
  • Loading branch information
zbarbuto authored Jan 12, 2024
2 parents 3158576 + 2b531e1 commit 25c7757
Show file tree
Hide file tree
Showing 18 changed files with 1,581 additions and 84 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
run: dart pub get

- name: Build generated files
run: dart run build_runner build
run: dart run build_runner build --delete-conflicting-outputs

- name: 'Analyze project'
run: flutter analyze
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ ios/Runner/GeneratedPluginRegistrant.*
android/local.properties
.vscode
coverage
test/mandatory_update_test.mocks.dart

test/http_man_up_service_test.mocks.dart
test/firebase_remote_config_man_up_service_test.mocks.dart
# Flutter/Dart/Pub related
**/doc/api/
.dart_tool/
Expand Down
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# manUp

## [7.0.0]

- **Breaking change** Separate service into `HttpManUpService` and `FireBaseRemoteConfigManUpService`

- Extract `HttpManUpService` from `ManUpService` and create `FireBaseRemoteConfigManUpService` to support fetching app config with HTTP and Firebase remote config
- Now, the user who use `ManUpService` in previous release

```dart
ManUpService service = ManUpService('https://example.com/manup.json', client: http.Client());
```
will need to change to
```dart
HttpManUpService service = HttpManUpService('https://example.com/manup.json', client: http.Client());
```
## [6.0.0]
- **Breaking change** Update version check logic
Expand Down
39 changes: 29 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ does.

## Usage

### Remote File
You can select the method to store and fetch app config file with the following options

You need a hosted json file that contains the version metadata. This _could_ be part of your API. However,
often the reason for maintenance mode is because your API is down. An s3 bucket may be a safer bet,
even though it means a little more work in maintaining the file.
- HTTP (`HttpManUpService`)
- you need a hosted json file that contains the version metadata. This _could_ be part of your API. However,
often the reason for maintenance mode is because your API is down. An s3 bucket may be a safer bet,
even though it means a little more work in maintaining the file.
- Firebase remote config (`FireBaseRemoteConfigManUpService`)
- you need to setup firebase project and remote config, then [Add Firebase to your Flutter app](https://firebase.google.com/docs/flutter/setup?platform=ios).

App config file structure

```json
{
Expand Down Expand Up @@ -42,13 +47,27 @@ If `"ios"` or `"android"` configurations are omitted, it will treat the device a

### Using the Service Directly

You can use `ManUpService` directly in your code. As part of your app startup logic, use the service to validate the running version.
You can use service directly in your code. As part of your app startup logic, use the service to validate the running version.

```dart
ManUpService service = ManUpService('https://example.com/manup.json', client: http.Client());
ManUpStatus result = await service.validate();
service.close();
```
- `HttpManUpService`

```dart
HttpManUpService service = HttpManUpService('https://example.com/manup.json', client: http.Client());
ManUpStatus result = await service.validate();
service.close();
```

- `FireBaseRemoteConfigManUpService`

```dart
FireBaseRemoteConfigManUpService service = FireBaseRemoteConfigManUpService(
remoteConfig: FirebaseRemoteConfig.instance,
// Parameter name (key) in remote config
paramName: 'configName',
);
ManUpStatus result = await service.validate();
service.close();
```

`ManUpStatus` will let you know how the version of the app running compares to the metadata:

Expand Down
51 changes: 51 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
migrate_working_dir/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
**/doc/api/
**/ios/Flutter/.last_build_id
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.pub-cache/
.pub/
/build/

# Symbolication related
app.*.symbols

# Obfuscation related
app.*.map.json

# Android Studio will place build artifacts here
/android/app/debug
/android/app/profile
/android/app/release

ios/
android/
macos/
windows/
web/
linux/
firebase_options.dart
45 changes: 45 additions & 0 deletions example/.metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: "b0366e0a3f089e15fd89c97604ab402fe26b724c"
channel: "stable"

project_type: app

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: b0366e0a3f089e15fd89c97604ab402fe26b724c
base_revision: b0366e0a3f089e15fd89c97604ab402fe26b724c
- platform: android
create_revision: b0366e0a3f089e15fd89c97604ab402fe26b724c
base_revision: b0366e0a3f089e15fd89c97604ab402fe26b724c
- platform: ios
create_revision: b0366e0a3f089e15fd89c97604ab402fe26b724c
base_revision: b0366e0a3f089e15fd89c97604ab402fe26b724c
- platform: linux
create_revision: b0366e0a3f089e15fd89c97604ab402fe26b724c
base_revision: b0366e0a3f089e15fd89c97604ab402fe26b724c
- platform: macos
create_revision: b0366e0a3f089e15fd89c97604ab402fe26b724c
base_revision: b0366e0a3f089e15fd89c97604ab402fe26b724c
- platform: web
create_revision: b0366e0a3f089e15fd89c97604ab402fe26b724c
base_revision: b0366e0a3f089e15fd89c97604ab402fe26b724c
- platform: windows
create_revision: b0366e0a3f089e15fd89c97604ab402fe26b724c
base_revision: b0366e0a3f089e15fd89c97604ab402fe26b724c

# User provided section

# List of Local paths (relative to this file) that should be
# ignored by the migrate tool.
#
# Files that are not part of the templates will be ignored by default.
unmanaged_files:
- 'lib/main.dart'
- 'ios/Runner.xcodeproj/project.pbxproj'
28 changes: 28 additions & 0 deletions example/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This file configures the analyzer, which statically analyzes Dart code to
# check for errors, warnings, and lints.
#
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
# invoked from the command line by running `flutter analyze`.

# The following line activates a set of recommended lints for Flutter apps,
# packages, and plugins designed to encourage good coding practices.
include: package:flutter_lints/flutter.yaml

linter:
# The lint rules applied to this project can be customized in the
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
# included above or to enable additional rules. A list of all available lints
# and their documentation is published at https://dart.dev/lints.
#
# Instead of disabling a lint rule for the entire project in the
# section below, it can also be suppressed for a single line of code
# or a specific dart file by using the `// ignore: name_of_lint` and
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
# producing the lint.
rules:
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
85 changes: 85 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import 'dart:async';

import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_remote_config/firebase_remote_config.dart';
import 'package:flutter/material.dart';
import 'package:manup/manup.dart';
import 'package:manup/src/firebase_remote_config_man_up_service.dart';

// generated with flutterfire_cli
import 'firebase_options.dart';

Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);

runApp(const MyApp());
}

class MyApp extends StatefulWidget {
const MyApp({super.key});

@override
State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
late FireBaseRemoteConfigManUpService manUpService;

String statusStr = 'unknown';
String latestVersion = '-';

@override
void initState() {
super.initState();
manUpService = FireBaseRemoteConfigManUpService(
remoteConfig: FirebaseRemoteConfig.instance,
// Parameter name (key) in remote config
paramName: 'configName',
);
}

@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'App',
home: Scaffold(
body: ManUpWidget(
service: manUpService,
shouldShowAlert: () => true,
onComplete: (bool isComplete) => debugPrint('Validate complete'),
onError: (dynamic e) => debugPrint('Error: $e'),
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text('Status: $statusStr'),
Text('Latest version: $latestVersion'),
],
)),
),
floatingActionButton: FloatingActionButton(
child: const Text('Validate'),
onPressed: () {
manUpService.validate().then((status) {
setState(() {
statusStr = status.name;
latestVersion = manUpService
.setting(
key: 'latest',
orElse: '',
os: 'ios',
)
.toString();
});
}).catchError((error) {
debugPrint('error: $error');
});
},
),
),
);
}
}
Loading

0 comments on commit 25c7757

Please sign in to comment.