Skip to content

Commit

Permalink
feat: windows platform support (#164)
Browse files Browse the repository at this point in the history
- init windows platform
- add timezone and sqlite support
- add fake reminder service on windows platform
- update readme file
  • Loading branch information
FriesI23 authored Apr 21, 2024
1 parent 4537d87 commit 12e9d4f
Show file tree
Hide file tree
Showing 31 changed files with 1,428 additions and 77 deletions.
10 changes: 2 additions & 8 deletions .metadata
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

version:
revision: "d211f42860350d914a5ad8102f9ec32764dc6d06"
channel: "stable"
channel: "[user-branch]"

project_type: app

Expand All @@ -15,13 +15,7 @@ migration:
- platform: root
create_revision: d211f42860350d914a5ad8102f9ec32764dc6d06
base_revision: d211f42860350d914a5ad8102f9ec32764dc6d06
- platform: android
create_revision: d211f42860350d914a5ad8102f9ec32764dc6d06
base_revision: d211f42860350d914a5ad8102f9ec32764dc6d06
- platform: ios
create_revision: d211f42860350d914a5ad8102f9ec32764dc6d06
base_revision: d211f42860350d914a5ad8102f9ec32764dc6d06
- platform: macos
- platform: windows
create_revision: d211f42860350d914a5ad8102f9ec32764dc6d06
base_revision: d211f42860350d914a5ad8102f9ec32764dc6d06

Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,23 @@ You can customize each habit with the following options:
- Reminder
- etc.

## Supported platforms

| platform | build | publish | desc. |
| -------- | ----- | ------------------------------------------------ | -------------------------- |
| android || [Github][github-myapp] / [F-Droid][fdroid-myapp] | |
| ios || | |
| macos || | |
| windows || | limit features: `reminder` |
| linux | | | |
| web | | | |

## Todo

| status | progress | desc. |
| ------- | ---------------------- | ------------------------------------------------------------ |
| PLANNED | Sync with Webdav | Expected sync solution is similar to Joplin's WebDAV method. |
| - | Publish to Google Play | |
| - | Build iOS version | build with iOS, need change some UI to Cupertino style. |
| - | Complete Documentation | [`README.md`](README.md) |

## Build from source
Expand Down
7 changes: 0 additions & 7 deletions lib/common/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import 'dart:math' as math;

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_timezone/flutter_timezone.dart';
import 'package:timezone/timezone.dart' as tz;
import 'package:tuple/tuple.dart';
import 'package:url_launcher/url_launcher.dart' as url_launcher;
import 'package:url_launcher/url_launcher_string.dart';
Expand Down Expand Up @@ -154,11 +152,6 @@ DateTime getProtoDateWithFirstDay(int firstDay) {
return DateTime(2023, 5, firstDay);
}

Future<void> configureLocalTimeZone() async {
final String timeZoneName = await FlutterTimezone.getLocalTimezone();
tz.setLocalLocation(tz.getLocation(timeZoneName));
}

Iterable<Tuple2<int, int>> getContinuousRanges(List<int> input) sync* {
int start = -1;

Expand Down
4 changes: 2 additions & 2 deletions lib/component/widgets/date_change.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import 'dart:async';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import '../../common/utils.dart';
import '../../logging/helper.dart';
import '../../model/habit_date.dart';
import '../../provider/commons.dart';
import '../../utils/local_timezone.dart';

class DateChangeNotifier extends ChangeNotifier implements ProviderMounted {
late HabitDate _dateTime;
Expand Down Expand Up @@ -117,7 +117,7 @@ class _DateChangeBuilder extends State<DateChangeBuilder> {
final tzName = now.timeZoneName;
if (changeNotifer.tzName != tzName) {
changeNotifer.tzName = tzName;
await configureLocalTimeZone();
await LocalTimeZoneManager().updateTimeZone();
}
});
super.initState();
Expand Down
7 changes: 2 additions & 5 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@
// limitations under the License.

import 'package:flutter/material.dart';
import 'package:timezone/data/latest_all.dart' as tz;

import 'common/app_info.dart';
import 'common/utils.dart';
import 'logging/logger_manager.dart';
import 'reminders/notification_service.dart';
import 'utils/local_timezone.dart';
import 'view/app.dart';

Future<void> main() async {
Expand All @@ -27,9 +26,7 @@ Future<void> main() async {
await AppLoggerMananger().init();
await AppInfo().init();
await NotificationService().init();

tz.initializeTimeZones();
await configureLocalTimeZone();
await LocalTimeZoneManager().init();

runApp(const App());
}
12 changes: 11 additions & 1 deletion lib/persistent/local/db_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import 'dart:convert';

import 'package:flutter/foundation.dart';
import 'package:path/path.dart';
import 'package:sqflite/sqflite.dart';
import 'package:sqflite_common_ffi/sqflite_ffi.dart';

import '../../assets/assets.dart';
import '../../common/async.dart';
Expand All @@ -42,6 +42,11 @@ abstract interface class DBHelper implements AsyncInitialization {
}

class _DBHelper implements DBHelper {
static const Set<TargetPlatform> useffiPlafroms = {
TargetPlatform.linux,
TargetPlatform.windows
};

late Database _db;

@override
Expand Down Expand Up @@ -108,6 +113,11 @@ class _DBHelper implements DBHelper {

@override
Future init({bool reinit = false}) async {
if (!reinit && useffiPlafroms.contains(defaultTargetPlatform)) {
sqfliteFfiInit();
databaseFactory = databaseFactoryFfi;
}

final String dbPath = join(await getDatabasesPath(), appDBName);

Future initNew() async {
Expand Down
2 changes: 1 addition & 1 deletion lib/provider/app_reminder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class AppReminderViewModel extends ChangeNotifier
switch (reminder.type) {
case AppReminderConfigType.daily:
if (reminder.timeOfDay != null) {
await NotificationService().regreAppReminderInDaily(
await NotificationService().regrAppReminderInDaily(
title: l10n.appReminder_dailyReminder_title,
subtitle: l10n.appReminder_dailyReminder_body,
timeOfDay: reminder.timeOfDay!,
Expand Down
Loading

0 comments on commit 12e9d4f

Please sign in to comment.