Skip to content

Commit

Permalink
Add additional logs
Browse files Browse the repository at this point in the history
  • Loading branch information
AhsanSarwar45 committed Sep 7, 2024
1 parent e293aa8 commit 46b2d23
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
16 changes: 11 additions & 5 deletions lib/alarm/logic/alarm_isolate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ const String setAlarmVolumePortName = "setAlarmVolumePort";

@pragma('vm:entry-point')
void triggerScheduledNotification(int scheduleId, Json params) async {
FlutterError.onError = (FlutterErrorDetails details) {
logger.f(details.exception.toString());
};

logger.i("Alarm triggered: $scheduleId");
// print("Alarm Trigger Isolate: ${Service.getIsolateID(Isolate.current)}");
if (params == null) {
Expand Down Expand Up @@ -74,10 +78,9 @@ void stopScheduledNotification(List<dynamic> message) {
}

void triggerAlarm(int scheduleId, Json params) async {
logger.i("Alarm triggered $scheduleId");
if (params == null) {
if (kDebugMode) {
print("Params was null when triggering alarm");
}
logger.e("Params was null when triggering alarm");
return;
}

Expand All @@ -101,6 +104,7 @@ void triggerAlarm(int scheduleId, Json params) async {
now.millisecondsSinceEpoch >
alarm.currentScheduleDateTime!.millisecondsSinceEpoch +
1000 * 60 * 60) {
logger.i("Skipping alarm $scheduleId");
return;
}

Expand All @@ -124,7 +128,6 @@ void triggerAlarm(int scheduleId, Json params) async {
IsolateNameServer.registerPortWithName(
receivePort.sendPort, setAlarmVolumePortName);
receivePort.listen((message) {
print("recieve message: $message");
setVolume(message[0]);
});

Expand All @@ -147,10 +150,11 @@ void triggerAlarm(int scheduleId, Json params) async {
}

void setVolume(double volume) {
RingtonePlayer.setVolume(volume/100);
RingtonePlayer.setVolume(volume / 100);
}

void stopAlarm(int scheduleId, AlarmStopAction action) async {
logger.i("Stopping alarm $scheduleId with action: ${action.name}");
if (action == AlarmStopAction.snooze) {
await updateAlarmById(scheduleId, (alarm) async => await alarm.snooze());
// await createSnoozeNotification(scheduleId);
Expand All @@ -168,6 +172,7 @@ void stopAlarm(int scheduleId, AlarmStopAction action) async {
}

void triggerTimer(int scheduleId, Json params) async {
logger.i("Timer triggered $scheduleId");
ClockTimer? timer = getTimerById(scheduleId);

if (timer == null || !timer.isRunning) {
Expand Down Expand Up @@ -204,6 +209,7 @@ void triggerTimer(int scheduleId, Json params) async {
}

void stopTimer(int scheduleId, AlarmStopAction action) async {
logger.i("Stopping timer $scheduleId with action: ${action.name}");
ClockTimer? timer = getTimerById(scheduleId);
if (timer == null) return;
if (action == AlarmStopAction.snooze) {
Expand Down
8 changes: 5 additions & 3 deletions lib/audio/types/ringtone_player.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:audio_session/audio_session.dart';
import 'package:clock_app/alarm/types/alarm.dart';
import 'package:clock_app/audio/types/ringtone_manager.dart';
import 'package:clock_app/debug/logic/logger.dart';
import 'package:clock_app/timer/types/timer.dart';
import 'package:just_audio/just_audio.dart';
import 'package:vibration/vibration.dart';
Expand Down Expand Up @@ -98,6 +99,7 @@ class RingtonePlayer {
}

static Future<void> setVolume(double volume) async {
logger.t("Setting volume to $volume");
await activePlayer?.setVolume(volume);
}

Expand All @@ -117,15 +119,15 @@ class RingtonePlayer {
await activePlayer?.stop();
await activePlayer?.setLoopMode(loopMode);
await activePlayer?.setAudioSource(AudioSource.uri(Uri.parse(ringtoneUri)));
await activePlayer?.setVolume(volume);
// activePlayer.setMode
await setVolume(volume);

// Gradually increase the volume
if (secondsToMaxVolume > 0) {
for (int i = 0; i <= 10; i++) {
Future.delayed(
Duration(milliseconds: i * (secondsToMaxVolume * 100)),
() {
activePlayer?.setVolume((i / 10) * volume);
setVolume((i / 10) * volume);
},
);
}
Expand Down
2 changes: 0 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ import 'package:clock_app/settings/types/listener_manager.dart';
import 'package:clock_app/system/data/app_info.dart';
import 'package:clock_app/system/data/device_info.dart';
import 'package:clock_app/system/logic/handle_boot.dart';
import 'package:clock_app/system/logic/quick_actions.dart';
import 'package:clock_app/timer/logic/update_timers.dart';
import 'package:flutter/material.dart';
import 'package:flutter_boot_receiver/flutter_boot_receiver.dart';
import 'package:flutter_show_when_locked/flutter_show_when_locked.dart';
import 'package:quick_actions/quick_actions.dart';
import 'package:timezone/data/latest_all.dart';

void main() async {
Expand Down

0 comments on commit 46b2d23

Please sign in to comment.