Skip to content
This repository was archived by the owner on Dec 27, 2022. It is now read-only.

Commit 982a583

Browse files
committed
implemented version checker package
1 parent 9e6f9a1 commit 982a583

26 files changed

+359
-35
lines changed

README.md

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,66 @@
1-
# flutter_package_template
1+
# version_checker
22

3-
![Build](https://github.com/marchdev-tk/flutter_package_template/workflows/build/badge.svg)
4-
[![Pub](https://img.shields.io/pub/v/flutter_package_template.svg)](https://pub.dartlang.org/packages/flutter_package_template)
5-
![GitHub](https://img.shields.io/github/license/marchdev-tk/flutter_package_template)
6-
![GitHub stars](https://img.shields.io/github/stars/marchdev-tk/flutter_package_template?style=social)
3+
![Build](https://github.com/marchdev-tk/version_checker/workflows/build/badge.svg)
4+
[![Pub](https://img.shields.io/pub/v/version_checker.svg)](https://pub.dartlang.org/packages/version_checker)
5+
![GitHub](https://img.shields.io/github/license/marchdev-tk/version_checker)
6+
![GitHub stars](https://img.shields.io/github/stars/marchdev-tk/version_checker?style=social)
77

8-
Package description
8+
Version Checker Popup is used to prompt user for website reloading with clearing cached data to apply a new version of the site.
99

1010
## Getting Started
1111

12-
Add intro here
12+
To start using this popup `VersionChecker.initialize` method should be called only once, for instance within constructor of <Your>App class within main.dart file.
13+
14+
Via `VersionChecker.initialize` method could be set delay for checking version:
15+
16+
* `timerDelay` - periodical delay.
17+
* `instantDelay` - if `instantCheck` is set to `true`, then after this delay version will be checked instantly.
18+
19+
Also, for localization purposes this method has following arguments:
20+
21+
* `newVersionAvailableText` - title of popup.
22+
* `applyText` - complete action button title.
23+
24+
If `debugOutput` argument is set to `true`, then extra info will be printed into console.
25+
26+
### Before building and deploying web site you should execute following script:
27+
28+
**Linux:**
29+
```bash
30+
#!/bin/bash
31+
32+
VERSION=$(sed -n -e 's/^version: \([0-9]*\.[0-9]*\.[0-9]*\)\(+[0-9]*\)*/\1/p' pubspec.yaml)
33+
34+
echo "App Version: ${VERSION}"
35+
echo "Updating app version..."
36+
37+
sed -i "s/var appVersion = \"[0-9]*\.[0-9]*\.[0-9]*\";/var appVersion = \"${VERSION}\";/g" web/index.html
38+
sed -i "s/src=\"main.dart.js\"/src=\"main.dart.js?v=${VERSION}\"/g" web/index.html
39+
sed -i "s/\"app_version\": \"[0-9]*\.[0-9]*\.[0-9]*\"/\"app_version\": \"${VERSION}\"/g" assets/env.json
40+
41+
echo "App version updated"
42+
```
43+
44+
**macOS:**
45+
```bash
46+
#!/bin/bash
47+
48+
VERSION=$(sed -n -e 's/^version: \([0-9]*\.[0-9]*\.[0-9]*\)\(+[0-9]*\)*/\1/p' pubspec.yaml)
49+
50+
echo "App Version: ${VERSION}"
51+
echo "Updating app version..."
52+
53+
sed -i '' "s/var appVersion = \"[0-9]*\.[0-9]*\.[0-9]*\";/var appVersion = \"${VERSION}\";/g" web/index.html
54+
sed -i '' "s/src=\"main.dart.js\"/src=\"main.dart.js?v=${VERSION}\"/g" web/index.html
55+
sed -i '' "s/\"app_version\": \"[0-9]*\.[0-9]*\.[0-9]*\"/\"app_version\": \"${VERSION}\"/g" assets/env.json
56+
57+
echo "App version updated"
58+
```
1359

1460
## Examples
1561

1662
Add examples here
1763

1864
## Feature requests and Bug reports
1965

20-
Feel free to post a feature requests or report a bug [here](https://github.com/marchdev-tk/flutter_package_template/issues).
66+
Feel free to post a feature requests or report a bug [here](https://github.com/marchdev-tk/version_checker/issues).

assets/env.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"app_version": "0.0.0"
3+
}

example/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# flutter_package_template_example
1+
# version_checker_example
22

3-
Demonstrates how to use the flutter_package_template package.
3+
Demonstrates how to use the version_checker package.
44

55
## Usage
66

example/android/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ android {
3737
}
3838

3939
defaultConfig {
40-
applicationId "marchdev.tk.flutter_package_template_example"
40+
applicationId "marchdev.tk.version_checker_example"
4141
minSdkVersion 16
4242
targetSdkVersion 28
4343
versionCode flutterVersionCode.toInteger()

example/android/app/src/debug/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="marchdev.tk.flutter_package_template_example">
2+
package="marchdev.tk.version_checker_example">
33
<!-- Flutter needs it to communicate with the running application
44
to allow setting breakpoints, to provide hot reload, etc.
55
-->

example/android/app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="marchdev.tk.flutter_package_template_example">
2+
package="marchdev.tk.version_checker_example">
33
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
44
calls FlutterMain.startInitialization(this); in its onCreate method.
55
In most cases you can leave this as-is, but you if you want to provide
66
additional functionality it is fine to subclass or reimplement
77
FlutterApplication and put your custom class here. -->
88
<application
99
android:name="io.flutter.app.FlutterApplication"
10-
android:label="flutter_package_template_example"
10+
android:label="version_checker_example"
1111
android:icon="@mipmap/ic_launcher">
1212
<activity
1313
android:name=".MainActivity"

example/android/app/src/main/kotlin/com/example/example/MainActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package marchdev.tk.flutter_package_template_example
1+
package marchdev.tk.version_checker_example
22

33
import androidx.annotation.NonNull;
44
import io.flutter.embedding.android.FlutterActivity

example/android/app/src/main/kotlin/marchdev/tk/example/MainActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package marchdev.tk.flutter_package_template_example
1+
package marchdev.tk.version_checker_example
22

33
import io.flutter.embedding.android.FlutterActivity
44

example/android/app/src/profile/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="marchdev.tk.flutter_package_template_example">
2+
package="marchdev.tk.version_checker_example">
33
<!-- Flutter needs it to communicate with the running application
44
to allow setting breakpoints, to provide hot reload, etc.
55
-->

example/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@
320320
"$(inherited)",
321321
"$(PROJECT_DIR)/Flutter",
322322
);
323-
PRODUCT_BUNDLE_IDENTIFIER = marchdev.tk.flutter_package_template_example;
323+
PRODUCT_BUNDLE_IDENTIFIER = marchdev.tk.version_checker_example;
324324
PRODUCT_NAME = "$(TARGET_NAME)";
325325
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
326326
SWIFT_VERSION = 5.0;
@@ -454,7 +454,7 @@
454454
"$(inherited)",
455455
"$(PROJECT_DIR)/Flutter",
456456
);
457-
PRODUCT_BUNDLE_IDENTIFIER = marchdev.tk.flutter_package_template_example;
457+
PRODUCT_BUNDLE_IDENTIFIER = marchdev.tk.version_checker_example;
458458
PRODUCT_NAME = "$(TARGET_NAME)";
459459
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
460460
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
@@ -481,7 +481,7 @@
481481
"$(inherited)",
482482
"$(PROJECT_DIR)/Flutter",
483483
);
484-
PRODUCT_BUNDLE_IDENTIFIER = marchdev.tk.flutter_package_template_example;
484+
PRODUCT_BUNDLE_IDENTIFIER = marchdev.tk.version_checker_example;
485485
PRODUCT_NAME = "$(TARGET_NAME)";
486486
SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h";
487487
SWIFT_VERSION = 5.0;

example/ios/Runner/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<key>CFBundleInfoDictionaryVersion</key>
1212
<string>6.0</string>
1313
<key>CFBundleName</key>
14-
<string>flutter_package_template_example</string>
14+
<string>version_checker_example</string>
1515
<key>CFBundlePackageType</key>
1616
<string>APPL</string>
1717
<key>CFBundleShortVersionString</key>

example/lib/main.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:flutter/material.dart';
6-
import 'package:flutter_package_template/flutter_package_template.dart';
6+
import 'package:version_checker/version_checker.dart';
77

88
void main() {
99
WidgetsFlutterBinding.ensureInitialized();
@@ -14,7 +14,7 @@ class MyApp extends StatelessWidget {
1414
@override
1515
Widget build(BuildContext context) {
1616
return MaterialApp(
17-
title: 'flutter_package_template Demo',
17+
title: 'Version Checker Demo',
1818
theme: ThemeData(
1919
primarySwatch: Colors.blue,
2020
),

example/pubspec.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
name: flutter_package_template_example
2-
description: Demonstrates how to use the flutter_package_template package.
1+
name: version_checker_example
2+
description: Demonstrates how to use the version_checker package.
33

44
environment:
55
sdk: ">=2.6.0 <3.0.0"
@@ -8,7 +8,7 @@ dependencies:
88
flutter:
99
sdk: flutter
1010

11-
flutter_package_template:
11+
version_checker:
1212
path: ../
1313

1414
flutter:

example/web/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html>
33
<head>
44
<meta charset="UTF-8">
5-
<title>flutter_package_template_example</title>
5+
<title>version_checker_example</title>
66
</head>
77
<body>
88
<script src="main.dart.js" type="application/javascript"></script>

example/web/manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "flutter_package_template_example",
3-
"short_name": "flutter_package_template_example",
2+
"name": "version_checker_example",
3+
"short_name": "version_checker_example",
44
"start_url": ".",
55
"display": "minimal-ui",
66
"background_color": "#0175C2",

lib/src/dom_injector.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) 2020, the MarchDev Toolkit project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'dom_injector/dom_injector_stub.dart'
6+
if (dart.library.io) 'dom_injector/dom_injector_io.dart'
7+
if (dart.library.html) 'dom_injector/dom_injector_web.dart';
8+
9+
class DOMInjector {
10+
static void inject() => DOMInjectorImpl.inject();
11+
}

lib/flutter_package_template.dart renamed to lib/src/dom_injector/dom_injector_io.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
library flutter_package_template;
6-
7-
5+
class DOMInjectorImpl {
6+
static void inject() {}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright (c) 2020, the MarchDev Toolkit project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
class DOMInjectorImpl {
6+
static void inject() => throw UnimplementedError();
7+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) 2020, the MarchDev Toolkit project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'dart:html' as html;
6+
7+
class DOMInjectorImpl {
8+
static void inject() {
9+
final head = html.querySelector('head');
10+
head.appendHtml(
11+
'''
12+
<script>
13+
var appVersion = "0.0.0";
14+
15+
function hardReload() {
16+
setTimeout(function () {
17+
window.location.reload(true);
18+
}, 100);
19+
}
20+
</script>
21+
''',
22+
treeSanitizer: html.NodeTreeSanitizer.trusted,
23+
);
24+
}
25+
}

lib/src/new_version_popup.dart

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// Copyright (c) 2020, the MarchDev Toolkit project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:flutter/material.dart';
6+
7+
import 'version_helper.dart';
8+
9+
class NewVersionModal extends StatelessWidget {
10+
const NewVersionModal._(this.newVersionAvailableText, this.applyText);
11+
12+
static bool _opened = false;
13+
14+
static Future open(
15+
BuildContext context, {
16+
String newVersionAvailableText = 'NEW VERSION AVAILABLE',
17+
String applyText = 'Apply',
18+
}) async {
19+
if (_opened) return;
20+
21+
_opened = true;
22+
23+
try {
24+
await showDialog(
25+
context: context,
26+
builder: (context) =>
27+
NewVersionModal._(newVersionAvailableText, applyText),
28+
);
29+
} finally {
30+
_opened = false;
31+
}
32+
}
33+
34+
final String newVersionAvailableText;
35+
final String applyText;
36+
37+
@override
38+
Widget build(BuildContext context) => AlertDialog(
39+
content: Container(
40+
height: 100,
41+
width: 200,
42+
child: Column(
43+
mainAxisAlignment: MainAxisAlignment.center,
44+
crossAxisAlignment: CrossAxisAlignment.center,
45+
children: <Widget>[
46+
Text(
47+
newVersionAvailableText ?? 'NEW VERSION AVAILABLE',
48+
style: TextStyle(fontWeight: FontWeight.bold),
49+
),
50+
const SizedBox(height: 16),
51+
Center(
52+
child: RaisedButton(
53+
textColor: Colors.white,
54+
child: Text(applyText ?? 'Apply'),
55+
onPressed: () => VersionHelper.refresh(),
56+
),
57+
),
58+
],
59+
),
60+
),
61+
);
62+
}

lib/src/version_helper.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (c) 2020, the MarchDev Toolkit project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'dart:async';
6+
7+
import 'package:pub_semver/pub_semver.dart';
8+
9+
import 'version_helper/version_helper_stub.dart'
10+
if (dart.library.io) 'version_helper/version_helper_io.dart'
11+
if (dart.library.html) 'version_helper/version_helper_web.dart';
12+
13+
class VersionHelper {
14+
static void refresh() => VersionHelperImpl.refresh();
15+
16+
static Future<Version> getActualVersion() =>
17+
VersionHelperImpl.getActualVersion();
18+
19+
static Future<Version> getAppVersion() => VersionHelperImpl.getAppVersion();
20+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) 2020, the MarchDev Toolkit project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:pub_semver/pub_semver.dart';
6+
import 'package:package_info/package_info.dart';
7+
8+
class VersionHelperImpl {
9+
static void refresh() {}
10+
11+
static Future<Version> getActualVersion() async =>
12+
Version.parse((await PackageInfo.fromPlatform()).version);
13+
14+
static Future<Version> getAppVersion() async =>
15+
Version.parse((await PackageInfo.fromPlatform()).version);
16+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright (c) 2020, the MarchDev Toolkit project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:pub_semver/pub_semver.dart';
6+
7+
class VersionHelperImpl {
8+
static void refresh() => throw UnimplementedError();
9+
10+
static Future<Version> getActualVersion() => throw UnimplementedError();
11+
12+
static Future<Version> getAppVersion() => throw UnimplementedError();
13+
}

0 commit comments

Comments
 (0)