Skip to content

Commit 4398792

Browse files
authored
Merge pull request #12 from CoderJava/feature/tambahkan-pengecekan-accesibility-permission
Feature - Tambahkan pengecekan accesibility permission
2 parents ff79cc6 + 2c284b4 commit 4398792

5 files changed

Lines changed: 80 additions & 4 deletions

File tree

assets/translations/en-US.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,9 @@
198198
"check_for_update": "Check For Update",
199199
"reminder_not_tracking_time": "Reminder: You're not tracking time",
200200
"title_screen_recording_mac": "Screen Recording",
201-
"description_screen_recording_mac": "This app would like to record this computer's screen. Grant access to this app in Security & Privacy preferences. located in System Preferences. If it doesn't exists please add manually or if it exists please delete it.",
201+
"description_screen_recording_mac": "This app would like to record this computer's screen. Grant access to this app in Security & Privacy preferences. Located in System Preferences. If it doesn't exists please add manually or if it exists please delete it.",
202202
"screen_recording_issued": "Screen recording not granted",
203-
"note_description_screen_recording_mac": "Always remember to reopen this app after changing permissions.",
203+
"note_description_permission": "Always remember to reopen this app after changing permissions.",
204204
"launch_at_startup": "Launch at Startup",
205205
"subtitle_launch_at_startup": "Dipantau will start running automatically when you turn your computer on.",
206206
"notification": "Notification",
@@ -228,5 +228,7 @@
228228
"n_minute": "{} minutes",
229229
"choose": "Choose",
230230
"finish_time_must_be_after_start_time": "Finish time must be after start time",
231-
"play_sound": "Play sound"
231+
"play_sound": "Play sound",
232+
"title_accessibility_mac": "Accessibility",
233+
"description_accessibility_mac": "This app would like to get keyboard & mouse activity. Grant access to this app in Security & Privacy preferences. Located in System Preferences. If it doesn't exists please add manually of if it exists please delete it."
232234
}

lib/core/util/platform_channel_helper.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class PlatformChannelHelper {
1313
final _keyInvokeMethodQuitApp = 'quit_app';
1414
final _keyInvokeMethodTakeScreenshot = 'take_screenshot';
1515
final _keyInvokeMethodCheckPermissionScreenRecording = 'check_permission_screen_recording';
16+
final _keyInvokeMethodCheckPermissionAccessibility = 'check_permission_accessibility';
1617

1718
// Event channel
1819
final _eventChannelName = 'dipantau/event';
@@ -109,4 +110,14 @@ class PlatformChannelHelper {
109110
return false;
110111
}
111112
}
113+
114+
Future<bool?> checkPermissionAccessibility() async {
115+
try {
116+
final result = await _methodChannel.invokeMethod<bool>(_keyInvokeMethodCheckPermissionAccessibility);
117+
return result;
118+
} catch (error) {
119+
debugPrint('Error check permission accessibility: $error');
120+
return false;
121+
}
122+
}
112123
}

lib/core/util/widget_helper.dart

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class WidgetHelper {
112112
text: '\n${'note'.tr()}',
113113
),
114114
TextSpan(
115-
text: ' ${'note_description_screen_recording_mac'.tr()}',
115+
text: ' ${'note_description_permission'.tr()}',
116116
),
117117
],
118118
),
@@ -135,4 +135,51 @@ class WidgetHelper {
135135
},
136136
);
137137
}
138+
139+
void showDialogPermissionAccessibility(BuildContext context) {
140+
showDialog(
141+
context: context,
142+
barrierDismissible: false,
143+
builder: (context) {
144+
return AlertDialog(
145+
title: Text(
146+
'title_accessibility_mac'.tr(),
147+
),
148+
content: Column(
149+
crossAxisAlignment: CrossAxisAlignment.start,
150+
mainAxisSize: MainAxisSize.min,
151+
children: [
152+
Text(
153+
'description_accessibility_mac'.tr(),
154+
),
155+
Text.rich(
156+
TextSpan(
157+
children: [
158+
TextSpan(
159+
text: '\n${'note'.tr()}',
160+
),
161+
TextSpan(
162+
text: ' ${'note_description_permission'.tr()}',
163+
),
164+
],
165+
),
166+
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
167+
fontStyle: FontStyle.italic,
168+
fontWeight: FontWeight.w500,
169+
),
170+
),
171+
],
172+
),
173+
actions: [
174+
TextButton(
175+
onPressed: () {
176+
Navigator.pop(context);
177+
},
178+
child: Text('ok'.tr()),
179+
),
180+
],
181+
);
182+
},
183+
);
184+
}
138185
}

lib/feature/presentation/page/home/home_page.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,14 @@ class _HomePageState extends State<HomePage> with TrayListener, WindowListener {
595595
return;
596596
}
597597

598+
if (isPermissionScreenRecordingGranted!) {
599+
final isPermissionAccessibilityGranted = await platformChannelHelper.checkPermissionAccessibility();
600+
if (mounted && isPermissionAccessibilityGranted != null && !isPermissionAccessibilityGranted) {
601+
widgetHelper.showDialogPermissionAccessibility(context);
602+
return;
603+
}
604+
}
605+
598606
if (selectedTask != itemTask) {
599607
if (selectedTask != null) {
600608
selectedTask!.trackedInSeconds = valueNotifierTotalTracked.value;

macos/Runner/AppDelegate.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ class AppDelegate: FlutterAppDelegate, FlutterStreamHandler {
4040
} else {
4141
result(true)
4242
}
43+
} else if ("check_permission_accessibility" == call.method) {
44+
var hasAccessibility = AXIsProcessTrusted()
45+
if (hasAccessibility) {
46+
result(true)
47+
} else {
48+
NSWorkspace.shared.open(URL(string: "x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility")!)
49+
result(false)
50+
}
4351
}
4452
})
4553

0 commit comments

Comments
 (0)