Line data Source code
1 : import 'package:flutter/foundation.dart' show kIsWeb;
2 :
3 : import '../../auth/enums/providers_enum.dart';
4 : import '../../settings/enums/platform_enum.dart';
5 : import '../plugins/wrappers/platform_wrapper.dart';
6 : import '../plugins/wrappers/url_launcher_wrapper.dart';
7 :
8 : class PlatformService {
9 0 : PlatformService(
10 : {PlatformWrapper? platformWrapper,
11 : UrlLauncherWrapper? urlLauncherWrapper})
12 : : _platformWrapper = platformWrapper ?? const PlatformWrapper(),
13 0 : _urlLauncherWrapper = urlLauncherWrapper ?? UrlLauncherWrapper();
14 :
15 : final UrlLauncherWrapper _urlLauncherWrapper;
16 : final PlatformWrapper _platformWrapper;
17 :
18 0 : PlatformsEnum detectPlatform() {
19 : if (kIsWeb) {
20 : return PlatformsEnum.web;
21 : }
22 0 : if (_platformWrapper.isMacOS) {
23 : return PlatformsEnum.macOS;
24 : }
25 0 : if (_platformWrapper.isFuchsia) {
26 : return PlatformsEnum.fuchsia;
27 : }
28 0 : if (_platformWrapper.isLinux) {
29 : return PlatformsEnum.linux;
30 : }
31 0 : if (_platformWrapper.isWindows) {
32 : return PlatformsEnum.windows;
33 : }
34 0 : if (_platformWrapper.isIOS) {
35 : return PlatformsEnum.iOS;
36 : }
37 0 : if (_platformWrapper.isAndroid) {
38 : return PlatformsEnum.android;
39 : }
40 : return PlatformsEnum.unknown;
41 : }
42 :
43 0 : Future<void> getAuthorized(
44 : {required ProvidersEnum provider, required String state}) async {
45 : String url;
46 0 : if (provider == ProvidersEnum.google) {
47 : url =
48 0 : 'https://us-central1-the-process-tool.cloudfunctions.net/startGoogleAuthorization?state=$state';
49 : } else {
50 : // if (provider == Provider.asana)
51 : url =
52 0 : 'https://us-central1-the-process-tool.cloudfunctions.net/startAsanaAuthorization?state=$state';
53 : }
54 :
55 0 : if (await _urlLauncherWrapper.canLaunch(url)) {
56 0 : await _urlLauncherWrapper.launch(url);
57 : } else {
58 0 : throw 'Could not launch $url';
59 : }
60 : }
61 :
62 0 : Future<void> launchUrl(String url) async {
63 0 : if (await _urlLauncherWrapper.canLaunch(url)) {
64 0 : await _urlLauncherWrapper.launch(url);
65 : } else {
66 0 : throw 'Could not launch $url';
67 : }
68 : }
69 : }
|