diff --git a/lib/main.dart b/lib/main.dart index f72d538..a2acaea 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,7 +1,9 @@ +import 'package:lms/services/database_local.dart'; import 'package:lms/services/imports.dart'; import 'package:about/about.dart'; import 'package:flutter/cupertino.dart'; import 'package:lms/models/link.dart'; +import 'package:url_launcher/url_launcher_string.dart'; const int kDBVersion = 1; @@ -30,6 +32,7 @@ class MyApp extends StatelessWidget { primarySwatch: Colors.pink, ), home: const MyHomePage(), + builder: EasyLoading.init(), ); } } @@ -54,68 +57,6 @@ class _MyHomePageState extends State { return prefs!.getBool(kDBConfigured) ?? false; } - Future openDB() async { - DatabaseFactory databaseFactory = databaseFactoryFfi; - - databaseFactory.setDatabasesPath(kDBPath); - - db = await databaseFactory.openDatabase(kDBPath); - if (kDebugMode) { - print('DB VERSION:'); - print(await db?.getVersion()); - } - - if (await dbConfigured() && await db?.getVersion() == kDBVersion) { - // if (db.getVersion()) expect(await db.getVersion(), 0); - } else { - sqfliteFfiInit(); - await prefs?.setBool('db_configured', true); - - await db?.setVersion(kDBVersion); - - await db?.execute(''' - CREATE TABLE Links ( - id INTEGER PRIMARY KEY, - title TEXT, - description TEXT, - url TEXT - ) - '''); - } - if (kDebugMode) { - print('QUERY FROM DATABASE'); - print(await db?.query('Links')); - print('\n\n'); - } - links = Link.fromJson(body: await db?.query('Links')); - - if (kDebugMode) { - print('first read DB'); - } - setState(() {}); - } - - Future closeDB() async { - if (db != null && db!.isOpen) { - await db!.close(); - } - } - - Future addLink( - {required String title, - required String description, - required String url}) async { - await db?.insert('Links', { - 'title': title, - 'description': description, - 'url': url - }); - if (await db?.query('Links', where: 'url = ?', whereArgs: [url]) != null) { - return true; - } - return false; - } - Future deleteLink({required String id}) async { await db?.delete('Links', where: 'id = ?', whereArgs: [id]); setState(() {}); @@ -145,31 +86,33 @@ class _MyHomePageState extends State { } void _showMaterialDialog() async { - if (!_isEnabled && !await dbConfigured()) { - showDialog( - context: context, - builder: (context) { - return AlertDialog( - title: const Text('Apertura al login'), - content: const Text('Vuoi che LMS si apra al login?'), - actions: [ - TextButton( + await dbConfigured().then((value) { + if (!_isEnabled && !value) { + showDialog( + context: context, + builder: (context) { + return AlertDialog( + title: const Text('Open at login'), + content: const Text('Do you want LMS open at login?'), + actions: [ + TextButton( + onPressed: () async { + await _handleDisable(); + Navigator.of(context).pop(); + }, + child: const Text('No')), + TextButton( onPressed: () async { - await _handleDisable(); + await _handleEnable(); Navigator.of(context).pop(); }, - child: const Text('No')), - TextButton( - onPressed: () async { - await _handleEnable(); - Navigator.of(context).pop(); - }, - child: const Text('Si'), - ) - ], - ); - }); - } + child: const Text('Si'), + ) + ], + ); + }); + } + }); } @override @@ -181,7 +124,7 @@ class _MyHomePageState extends State { @override void dispose() { - closeDB(); + DatabaseLocal(db).closeDB(); super.dispose(); } @@ -191,55 +134,12 @@ class _MyHomePageState extends State { return Scaffold( appBar: AppBar( leading: IconButton( - onPressed: () async { - PackageInfo packageInfo = await PackageInfo.fromPlatform(); - - showAboutPage( - context: context, - values: { - 'version': packageInfo.version, - 'year': DateTime.now().year.toString(), - }, - applicationLegalese: - 'Copyright © Simone Porcari | Riccardo Rettore | Francesco Vezzani, {{ year }}', - applicationDescription: - const Text('Applicazione per la gestione dei link.'), - children: [ - const MarkdownPageListTile( - icon: Icon(Icons.list), - title: Text('Changelog'), - filename: 'CHANGELOG.md', - ), - const LicensesPageListTile( - icon: Icon(Icons.favorite), - ), - StatefulBuilder( - builder: (context, setState) => ListTile( - leading: Icon(_isEnabled - ? CupertinoIcons.check_mark_circled - : CupertinoIcons.xmark_circle), - title: const Text('Apertura al login'), - onTap: () async { - if (_isEnabled) { - await launchAtStartup.disable(); - } else { - await launchAtStartup.enable(); - } - setState(() => _isEnabled = !_isEnabled); - }), - ), - ], - applicationIcon: const SizedBox( - width: 100, - height: 100, - child: Image( - image: AssetImage('assets/icon.png'), - ), - ), - ); - }, + onPressed: () => showAboutApp(), icon: const Icon(CupertinoIcons.infinite)), - title: const Text('Link Management System'), + title: GestureDetector( + child: const Text('Link Management System'), + onTap: () => showAboutApp(), + ), ), body: Center( child: Column( @@ -279,9 +179,9 @@ class _MyHomePageState extends State { style: Theme.of(context).textTheme.subtitle1, ), TextButton( - child: const Text('Apri link'), + child: const Text('Open link'), onPressed: () async { - if (!await launch(link.url.toString())) { + if (!await launchUrlString(link.url.toString())) { throw 'Could not launch ${link.url.toString()}'; } }, @@ -306,14 +206,14 @@ class _MyHomePageState extends State { String url = ''; return AlertDialog( - title: const Text('Inserisci link'), + title: const Text('Insert link'), content: SingleChildScrollView( child: ListBody( children: [ TextField( decoration: const InputDecoration( border: OutlineInputBorder(), - labelText: 'Titolo', + labelText: 'Title (es. Monday meeting)', ), onChanged: (value) => title = value, ), @@ -321,7 +221,7 @@ class _MyHomePageState extends State { TextField( decoration: const InputDecoration( border: OutlineInputBorder(), - labelText: 'Descrizione', + labelText: 'Description (es. Every friday)', ), onChanged: (value) => description = value, ), @@ -329,7 +229,7 @@ class _MyHomePageState extends State { TextField( decoration: const InputDecoration( border: OutlineInputBorder(), - labelText: 'Link del sito o della videochiamata', + labelText: 'Link (ex. site or meeting)', ), onChanged: (value) => url = value, ), @@ -339,7 +239,7 @@ class _MyHomePageState extends State { actions: [ TextButton( child: Text( - 'Annulla', + 'Cancel', style: Theme.of(context) .textTheme .button! @@ -350,21 +250,107 @@ class _MyHomePageState extends State { }, ), TextButton( - child: const Text('Salva'), - onPressed: () async { - await addLink( - title: title, description: description, url: url) - .then((value) => readDB()); - Navigator.of(context).pop(); - }, + child: const Text('Save'), + onPressed: () async => await DatabaseLocal(db) + .addLink(title: title, description: description, url: url) + .then((value) => readDB()) + .whenComplete(() => Navigator.of(context).pop()), ), ], ); }, ), - tooltip: 'Aggiungi link', + tooltip: 'Add link', child: const Icon(Icons.add), - ), // This trailing comma makes auto-formatting nicer for build methods. + ), ); } + + Future openDB() async { + DatabaseFactory databaseFactory = databaseFactoryFfi; + + databaseFactory.setDatabasesPath(kDBPath); + + db = await databaseFactory.openDatabase(kDBPath); + if (kDebugMode) { + print('DB VERSION:'); + print(await db?.getVersion()); + } + + if (await dbConfigured() && await db?.getVersion() == kDBVersion) { + // if (db.getVersion()) expect(await db.getVersion(), 0); + } else { + sqfliteFfiInit(); + await prefs?.setBool('db_configured', true); + + await db?.setVersion(kDBVersion); + + await db?.execute(''' + CREATE TABLE Links ( + id INTEGER PRIMARY KEY, + title TEXT, + description TEXT, + url TEXT + ) + '''); + } + if (kDebugMode) { + print('QUERY FROM DATABASE'); + print(await db?.query('Links')); + print('\n\n'); + } + links = Link.fromJson(body: await db?.query('Links')); + + if (kDebugMode) { + print('first read DB'); + } + setState(() {}); + } + + Future showAboutApp() async => await PackageInfo.fromPlatform() + .then((PackageInfo packageInfo) => showAboutPage( + context: context, + values: { + 'version': packageInfo.version, + 'year': DateTime.now().year.toString(), + }, + applicationLegalese: + 'Copyright © Simone Porcari | Riccardo Rettore | Francesco Vezzani, {{ year }}', + applicationDescription: + const Text('Desktop application for links management.'), + children: [ + const MarkdownPageListTile( + icon: Icon(Icons.list), + title: Text('Changelog'), + filename: 'CHANGELOG.md', + ), + const LicensesPageListTile( + icon: Icon(Icons.favorite), + ), + StatefulBuilder( + builder: (context, setState) => ListTile( + leading: Icon(_isEnabled + ? CupertinoIcons.check_mark_circled + : CupertinoIcons.xmark_circle), + title: const Text('Launch at startup'), + onTap: () async { + if (_isEnabled) { + EasyLoading.showInfo('Disabled launch at startup'); + await launchAtStartup.disable(); + } else { + EasyLoading.showInfo('Enabled launch at startup'); + await launchAtStartup.enable(); + } + setState(() => _isEnabled = !_isEnabled); + }), + ), + ], + applicationIcon: const SizedBox( + width: 100, + height: 100, + child: Image( + image: AssetImage('assets/icon.png'), + ), + ), + )); } diff --git a/lib/services/database_local.dart b/lib/services/database_local.dart new file mode 100644 index 0000000..c0018b7 --- /dev/null +++ b/lib/services/database_local.dart @@ -0,0 +1,27 @@ +import 'package:lms/services/imports.dart'; + +class DatabaseLocal{ + final Database? db; + DatabaseLocal( this.db); + + + Future closeDB() async { + if (db != null && db!.isOpen) { + await db!.close(); + } + } + Future addLink( + {required String title, + required String description, + required String url}) async { + await db?.insert('Links', { + 'title': title, + 'description': description, + 'url': url + }); + if (await db?.query('Links', where: 'url = ?', whereArgs: [url]) != null) { + return true; + } + return false; + } +} \ No newline at end of file diff --git a/lib/services/imports.dart b/lib/services/imports.dart index b7c6bff..cc3e72c 100644 --- a/lib/services/imports.dart +++ b/lib/services/imports.dart @@ -8,5 +8,6 @@ export 'package:shared_preferences/shared_preferences.dart'; export 'package:url_launcher/url_launcher.dart'; export 'package:package_info_plus/package_info_plus.dart'; export 'package:flutter/material.dart'; +export 'package:flutter_easyloading/flutter_easyloading.dart'; export 'package:lms/constants.dart'; diff --git a/macos/Podfile b/macos/Podfile index dade8df..049abe2 100644 --- a/macos/Podfile +++ b/macos/Podfile @@ -1,4 +1,4 @@ -platform :osx, '10.11' +platform :osx, '10.14' # CocoaPods analytics sends network stats synchronously affecting flutter build latency. ENV['COCOAPODS_DISABLE_STATS'] = 'true' diff --git a/macos/Podfile.lock b/macos/Podfile.lock index 51272f6..7c3f824 100644 --- a/macos/Podfile.lock +++ b/macos/Podfile.lock @@ -2,20 +2,27 @@ PODS: - auto_updater (0.0.1): - FlutterMacOS - Sparkle + - dynamic_color (0.0.2): + - FlutterMacOS - FlutterMacOS (1.0.0) - - package_info_plus_macos (0.0.1): + - macos_ui (0.1.0): + - FlutterMacOS + - package_info_plus (0.0.1): - FlutterMacOS - - shared_preferences_macos (0.0.1): + - shared_preferences_foundation (0.0.1): + - Flutter - FlutterMacOS - - Sparkle (2.1.0) + - Sparkle (2.3.0) - url_launcher_macos (0.0.1): - FlutterMacOS DEPENDENCIES: - auto_updater (from `Flutter/ephemeral/.symlinks/plugins/auto_updater/macos`) + - dynamic_color (from `Flutter/ephemeral/.symlinks/plugins/dynamic_color/macos`) - FlutterMacOS (from `Flutter/ephemeral`) - - package_info_plus_macos (from `Flutter/ephemeral/.symlinks/plugins/package_info_plus_macos/macos`) - - shared_preferences_macos (from `Flutter/ephemeral/.symlinks/plugins/shared_preferences_macos/macos`) + - macos_ui (from `Flutter/ephemeral/.symlinks/plugins/macos_ui/macos`) + - package_info_plus (from `Flutter/ephemeral/.symlinks/plugins/package_info_plus/macos`) + - shared_preferences_foundation (from `Flutter/ephemeral/.symlinks/plugins/shared_preferences_foundation/macos`) - url_launcher_macos (from `Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos`) SPEC REPOS: @@ -25,23 +32,29 @@ SPEC REPOS: EXTERNAL SOURCES: auto_updater: :path: Flutter/ephemeral/.symlinks/plugins/auto_updater/macos + dynamic_color: + :path: Flutter/ephemeral/.symlinks/plugins/dynamic_color/macos FlutterMacOS: :path: Flutter/ephemeral - package_info_plus_macos: - :path: Flutter/ephemeral/.symlinks/plugins/package_info_plus_macos/macos - shared_preferences_macos: - :path: Flutter/ephemeral/.symlinks/plugins/shared_preferences_macos/macos + macos_ui: + :path: Flutter/ephemeral/.symlinks/plugins/macos_ui/macos + package_info_plus: + :path: Flutter/ephemeral/.symlinks/plugins/package_info_plus/macos + shared_preferences_foundation: + :path: Flutter/ephemeral/.symlinks/plugins/shared_preferences_foundation/macos url_launcher_macos: :path: Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos SPEC CHECKSUMS: auto_updater: d3c03e9e5f2a00ec78572d9f7473cb8c9a6c0273 - FlutterMacOS: 57701585bf7de1b3fc2bb61f6378d73bbdea8424 - package_info_plus_macos: f010621b07802a241d96d01876d6705f15e77c1c - shared_preferences_macos: a64dc611287ed6cbe28fd1297898db1336975727 - Sparkle: 7f5f6d4328458515e23272f4138e610c1fa3e32d - url_launcher_macos: 597e05b8e514239626bcf4a850fcf9ef5c856ec3 + dynamic_color: 2eaa27267de1ca20d879fbd6e01259773fb1670f + FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24 + macos_ui: 125c911559d646194386d84c017ad6819122e2db + package_info_plus: 02d7a575e80f194102bef286361c6c326e4c29ce + shared_preferences_foundation: 297b3ebca31b34ec92be11acd7fb0ba932c822ca + Sparkle: 568478a5d774eee0f5dab78535456c95fb8211b4 + url_launcher_macos: c04e4fa86382d4f94f6b38f14625708be3ae52e2 -PODFILE CHECKSUM: 6eac6b3292e5142cfc23bdeb71848a40ec51c14c +PODFILE CHECKSUM: 353c8bcc5d5b0994e508d035b5431cfe18c1dea7 COCOAPODS: 1.11.3 diff --git a/macos/Runner.xcodeproj/project.pbxproj b/macos/Runner.xcodeproj/project.pbxproj index f42474a..70f81f8 100644 --- a/macos/Runner.xcodeproj/project.pbxproj +++ b/macos/Runner.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 51; + objectVersion = 54; objects = { /* Begin PBXAggregateTarget section */ @@ -202,7 +202,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0920; - LastUpgradeCheck = 1330; + LastUpgradeCheck = 1300; ORGANIZATIONNAME = ""; TargetAttributes = { 33CC10EC2044A3C60003C045 = { @@ -255,6 +255,7 @@ /* Begin PBXShellScriptBuildPhase section */ 3399D490228B24CF009A79C7 /* ShellScript */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); @@ -393,6 +394,7 @@ CLANG_WARN_SUSPICIOUS_MOVE = YES; CODE_SIGN_IDENTITY = "-"; COPY_PHASE_STRIP = NO; + DEAD_CODE_STRIPPING = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; @@ -403,7 +405,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.11; + MACOSX_DEPLOYMENT_TARGET = 10.14; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = macosx; SWIFT_COMPILATION_MODE = wholemodule; @@ -422,6 +424,7 @@ CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; CURRENT_PROJECT_VERSION = 3; + DEAD_CODE_STRIPPING = YES; DEVELOPMENT_TEAM = P8WULW25UZ; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = Runner/Info.plist; @@ -429,6 +432,7 @@ "$(inherited)", "@executable_path/../Frameworks", ); + MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)"; PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_VERSION = 5.0; }; @@ -438,6 +442,8 @@ isa = XCBuildConfiguration; buildSettings = { CODE_SIGN_STYLE = Manual; + DEAD_CODE_STRIPPING = YES; + MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)"; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Profile; @@ -470,6 +476,7 @@ CLANG_WARN_SUSPICIOUS_MOVE = YES; CODE_SIGN_IDENTITY = "-"; COPY_PHASE_STRIP = NO; + DEAD_CODE_STRIPPING = YES; DEBUG_INFORMATION_FORMAT = dwarf; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; @@ -486,7 +493,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.11; + MACOSX_DEPLOYMENT_TARGET = 10.14; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; @@ -523,6 +530,7 @@ CLANG_WARN_SUSPICIOUS_MOVE = YES; CODE_SIGN_IDENTITY = "-"; COPY_PHASE_STRIP = NO; + DEAD_CODE_STRIPPING = YES; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; @@ -533,7 +541,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.11; + MACOSX_DEPLOYMENT_TARGET = 10.14; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = macosx; SWIFT_COMPILATION_MODE = wholemodule; @@ -552,6 +560,7 @@ CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; CURRENT_PROJECT_VERSION = 3; + DEAD_CODE_STRIPPING = YES; DEVELOPMENT_TEAM = P8WULW25UZ; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = Runner/Info.plist; @@ -559,6 +568,7 @@ "$(inherited)", "@executable_path/../Frameworks", ); + MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)"; PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 5.0; @@ -576,6 +586,7 @@ CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; CURRENT_PROJECT_VERSION = 3; + DEAD_CODE_STRIPPING = YES; DEVELOPMENT_TEAM = P8WULW25UZ; ENABLE_HARDENED_RUNTIME = YES; INFOPLIST_FILE = Runner/Info.plist; @@ -583,6 +594,7 @@ "$(inherited)", "@executable_path/../Frameworks", ); + MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)"; PROVISIONING_PROFILE_SPECIFIER = ""; SWIFT_VERSION = 5.0; }; @@ -592,6 +604,8 @@ isa = XCBuildConfiguration; buildSettings = { CODE_SIGN_STYLE = Manual; + DEAD_CODE_STRIPPING = YES; + MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)"; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Debug; @@ -600,6 +614,8 @@ isa = XCBuildConfiguration; buildSettings = { CODE_SIGN_STYLE = Automatic; + DEAD_CODE_STRIPPING = YES; + MACOSX_DEPLOYMENT_TARGET = "$(RECOMMENDED_MACOSX_DEPLOYMENT_TARGET)"; PRODUCT_NAME = "$(TARGET_NAME)"; }; name = Release; diff --git a/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index a427d61..8179d68 100644 --- a/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ =2.16.1 <3.0.0" @@ -21,6 +21,7 @@ dependencies: adaptive_dialog: ^1.8.2 launch_at_startup: ^0.2.1 auto_updater: ^0.1.6 + flutter_easyloading: ^3.0.5 dev_dependencies: flutter_test: