From 8cc0d2cea97e8ff90b8962fa50dc01bb20e317ac Mon Sep 17 00:00:00 2001 From: Calcitem Date: Thu, 24 Jun 2021 00:09:47 +0800 Subject: [PATCH] Replace third party notices page to oss license page --- flutter-init.sh | 4 + src/ui/flutter_app/lib/l10n/intl_de.arb | 4 + src/ui/flutter_app/lib/l10n/intl_en.arb | 4 + src/ui/flutter_app/lib/l10n/intl_fa.arb | 4 + src/ui/flutter_app/lib/l10n/intl_hu.arb | 4 + src/ui/flutter_app/lib/l10n/intl_ro.arb | 4 + src/ui/flutter_app/lib/l10n/intl_zh.arb | 3 +- .../flutter_app/lib/widgets/about_page.dart | 10 +- .../lib/widgets/oss_license_page.dart | 126 ++++++++++++++++++ src/ui/flutter_app/pubspec.yaml | 1 + 10 files changed, 162 insertions(+), 2 deletions(-) create mode 100644 src/ui/flutter_app/lib/widgets/oss_license_page.dart diff --git a/flutter-init.sh b/flutter-init.sh index f0a32992..fea2c54a 100755 --- a/flutter-init.sh +++ b/flutter-init.sh @@ -11,9 +11,13 @@ cd src/ui/flutter_app || exit flutter config --no-analytics flutter pub get + flutter pub global activate intl_utils flutter --no-color pub global run intl_utils:generate +flutter pub run flutter_oss_licenses:generate.dart +mv lib/oss_licenses.dart lib/generated + mkdir -p $GEN_FILE_PATH || true echo "const Map flutterVersion =" > $FLUTTER_VERSION_FILE diff --git a/src/ui/flutter_app/lib/l10n/intl_de.arb b/src/ui/flutter_app/lib/l10n/intl_de.arb index 766a5ee5..a32a01cf 100644 --- a/src/ui/flutter_app/lib/l10n/intl_de.arb +++ b/src/ui/flutter_app/lib/l10n/intl_de.arb @@ -939,5 +939,9 @@ "experiments": "Experimente", "@experiments": { "description": "Experiments" + }, + "ossLicenses": "Open Source Lizenzen", + "@ossLicenses": { + "description": "Open source licenses" } } diff --git a/src/ui/flutter_app/lib/l10n/intl_en.arb b/src/ui/flutter_app/lib/l10n/intl_en.arb index 809bcd7c..131a0fd1 100644 --- a/src/ui/flutter_app/lib/l10n/intl_en.arb +++ b/src/ui/flutter_app/lib/l10n/intl_en.arb @@ -939,5 +939,9 @@ "experiments": "Experiments", "@experiments": { "description": "Experiments" + }, + "ossLicenses": "Open source licenses", + "@ossLicenses": { + "description": "Open source licenses" } } diff --git a/src/ui/flutter_app/lib/l10n/intl_fa.arb b/src/ui/flutter_app/lib/l10n/intl_fa.arb index 4b4078cc..ad8f0268 100644 --- a/src/ui/flutter_app/lib/l10n/intl_fa.arb +++ b/src/ui/flutter_app/lib/l10n/intl_fa.arb @@ -939,5 +939,9 @@ "experiments": "آزمایش", "@experiments": { "description": "Experiments" + }, + "ossLicenses": "Open Source Lizenzen", + "@ossLicenses": { + "description": "مجوزهای منبع آزاد" } } diff --git a/src/ui/flutter_app/lib/l10n/intl_hu.arb b/src/ui/flutter_app/lib/l10n/intl_hu.arb index da614116..23e97b42 100644 --- a/src/ui/flutter_app/lib/l10n/intl_hu.arb +++ b/src/ui/flutter_app/lib/l10n/intl_hu.arb @@ -939,5 +939,9 @@ "experiments": "Kísérletek", "@experiments": { "description": "Experiments" + }, + "ossLicenses": "Nyílt forráskódú licencek", + "@ossLicenses": { + "description": "Open source licenses" } } diff --git a/src/ui/flutter_app/lib/l10n/intl_ro.arb b/src/ui/flutter_app/lib/l10n/intl_ro.arb index 2943acad..4ea230ed 100644 --- a/src/ui/flutter_app/lib/l10n/intl_ro.arb +++ b/src/ui/flutter_app/lib/l10n/intl_ro.arb @@ -939,5 +939,9 @@ "experiments": "Experimente", "@experiments": { "description": "Experiments" + }, + "ossLicenses": "Licențe open source", + "@ossLicenses": { + "description": "Open source licenses" } } \ No newline at end of file diff --git a/src/ui/flutter_app/lib/l10n/intl_zh.arb b/src/ui/flutter_app/lib/l10n/intl_zh.arb index 19ff43f7..008a3843 100644 --- a/src/ui/flutter_app/lib/l10n/intl_zh.arb +++ b/src/ui/flutter_app/lib/l10n/intl_zh.arb @@ -234,5 +234,6 @@ "environmentVariables": "环境变量", "more": "更多", "experimental": "此仍属实验性功能。", - "experiments": "实验性功能" + "experiments": "实验性功能", + "ossLicenses": "开放源代码许可" } \ No newline at end of file diff --git a/src/ui/flutter_app/lib/widgets/about_page.dart b/src/ui/flutter_app/lib/widgets/about_page.dart index 8a599eae..497ddd00 100644 --- a/src/ui/flutter_app/lib/widgets/about_page.dart +++ b/src/ui/flutter_app/lib/widgets/about_page.dart @@ -30,6 +30,7 @@ import 'package:url_launcher/url_launcher.dart'; import 'license_page.dart'; import 'list_item_divider.dart'; +import 'oss_license_page.dart'; class AboutPage extends StatefulWidget { @override @@ -135,7 +136,7 @@ class _AboutPageState extends State { ListItemDivider(), SettingsListTile( context: context, - titleString: S.of(context).thirdPartyNotices, + titleString: S.of(context).ossLicenses, onTap: () { _launchThirdPartyNotices(); }, @@ -216,6 +217,12 @@ class _AboutPageState extends State { } _launchThirdPartyNotices() async { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => OssLicensesPage(), + )); + /* String? locale = "en_US"; if (!Platform.isWindows) { @@ -230,6 +237,7 @@ class _AboutPageState extends State { _launchURL( 'https://github.com/calcitem/Sanmill/wiki/third-party_notices'); } + */ } _launchPrivacyPolicy() async { diff --git a/src/ui/flutter_app/lib/widgets/oss_license_page.dart b/src/ui/flutter_app/lib/widgets/oss_license_page.dart new file mode 100644 index 00000000..5b33b8f4 --- /dev/null +++ b/src/ui/flutter_app/lib/widgets/oss_license_page.dart @@ -0,0 +1,126 @@ +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'package:sanmill/generated/l10n.dart'; +import 'package:sanmill/generated/oss_licenses.dart'; +import 'package:url_launcher/url_launcher.dart'; + +class FlutterLicense extends LicenseEntry { + final List packages; + final List paragraphs; + + FlutterLicense(this.packages, this.paragraphs); +} + +/// display all used packages and their license +class OssLicensesPage extends StatelessWidget { + static Future> loadLicenses() async { + Stream licenses() async* { + yield FlutterLicense([ + 'Sound Effects' + ], [ + LicenseParagraph( + 'CC-0\nhttps://freesound.org/people/unfa/sounds/243749/', 0) + ]); + } + + LicenseRegistry.addLicense(licenses); + + // merging non-dart based dependency list using LicenseRegistry. + final ossKeys = ossLicenses.keys.toList(); + final lm = >{}; + await for (var l in LicenseRegistry.licenses) { + for (var p in l.packages) { + if (!ossKeys.contains(p)) { + final lp = lm.putIfAbsent(p, () => []); + lp.addAll(l.paragraphs.map((p) => p.text)); + ossKeys.add(p); + } + } + } + for (var key in lm.keys) { + ossLicenses[key] = {'license': lm[key]!.join('\n')}; + } + return ossKeys..sort(); + } + + static final _licenses = loadLicenses(); + + @override + Widget build(BuildContext context) => Scaffold( + appBar: AppBar( + title: Text(S.of(context).ossLicenses), + ), + body: FutureBuilder>( + future: _licenses, + builder: (context, snapshot) => ListView.separated( + padding: const EdgeInsets.all(0), + itemCount: snapshot.data?.length ?? 0, + itemBuilder: (context, index) { + final key = snapshot.data![index]; + final ossl = ossLicenses[key]; + final version = ossl['version']; + final desc = ossl['description']; + return ListTile( + title: Text('$key ${version ?? ''}'), + subtitle: desc != null ? Text(desc) : null, + trailing: Icon(Icons.chevron_right), + onTap: () => Navigator.of(context).push(MaterialPageRoute( + builder: (context) => + MiscOssLicenseSingle(name: key, json: ossl)))); + }, + separatorBuilder: (context, index) => const Divider()))); +} + +class MiscOssLicenseSingle extends StatelessWidget { + final String name; + final Map json; + + String get version => json['version'] == null ? "" : json['version']; + String? get description => json['description']; + String get licenseText => json['license']; + String? get homepage => json['homepage']; + + MiscOssLicenseSingle({required this.name, required this.json}); + + String _bodyText() => licenseText.split('\n').map((line) { + if (line.startsWith('//')) line = line.substring(2); + line = line.trim(); + return line; + }).join('\n'); + + @override + Widget build(BuildContext context) => Scaffold( + appBar: AppBar(title: Text('$name $version')), + body: Container( + color: Theme.of(context).canvasColor, + child: ListView(children: [ + if (description != null) + Padding( + padding: const EdgeInsets.only( + top: 12.0, left: 12.0, right: 12.0), + child: Text(description!, + style: Theme.of(context) + .textTheme + .bodyText2! + .copyWith(fontWeight: FontWeight.bold))), + if (homepage != null) + Padding( + padding: const EdgeInsets.only( + top: 12.0, left: 12.0, right: 12.0), + child: InkWell( + child: Text(homepage!, + style: const TextStyle( + color: Colors.blue, + decoration: TextDecoration.underline)), + onTap: () => launch(homepage!), + )), + if (description != null || homepage != null) const Divider(), + Padding( + padding: + const EdgeInsets.only(top: 12.0, left: 12.0, right: 12.0), + child: Text(_bodyText(), + style: Theme.of(context).textTheme.bodyText2), + ), + ])), + ); +} diff --git a/src/ui/flutter_app/pubspec.yaml b/src/ui/flutter_app/pubspec.yaml index a4f63b6c..2c106b6a 100644 --- a/src/ui/flutter_app/pubspec.yaml +++ b/src/ui/flutter_app/pubspec.yaml @@ -29,6 +29,7 @@ dependencies: #screen_recorder: ^0.0.2 dev_dependencies: + flutter_oss_licenses: ^1.0.1 flutter_test: sdk: flutter msix: ^2.1.0