@greatdayhr/capacitor-datetime-setting 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CapacitorDatetimeSetting.podspec +17 -0
- package/LICENSE +21 -0
- package/README.md +149 -0
- package/android/build.gradle +49 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/java/com/datetimesetting/DateTimeSettingPlugin.java +101 -0
- package/dist/esm/definitions.d.ts +45 -0
- package/dist/esm/definitions.d.ts.map +1 -0
- package/dist/esm/definitions.js +1 -0
- package/dist/esm/index.d.ts +5 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/web.d.ts +12 -0
- package/dist/esm/web.d.ts.map +1 -0
- package/dist/esm/web.js +12 -0
- package/dist/plugin.cjs.js +29 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +32 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Plugin/DateTimeSettingPlugin.m +10 -0
- package/ios/Plugin/DateTimeSettingPlugin.swift +68 -0
- package/package.json +81 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = 'CapacitorDatetimeSetting'
|
|
7
|
+
s.version = package['version']
|
|
8
|
+
s.summary = package['description']
|
|
9
|
+
s.license = package['license']
|
|
10
|
+
s.homepage = package['repository']['url']
|
|
11
|
+
s.author = package['author']
|
|
12
|
+
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
|
|
13
|
+
s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
|
|
14
|
+
s.ios.deployment_target = '13.0'
|
|
15
|
+
s.dependency 'Capacitor'
|
|
16
|
+
s.swift_version = '5.1'
|
|
17
|
+
end
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# Capacitor DateTime Setting Plugin
|
|
2
|
+
|
|
3
|
+
Capacitor plugin to get information about auto time and auto timezone settings, and open device settings if needed.
|
|
4
|
+
|
|
5
|
+
This plugin is a Capacitor port of the Flutter [datetime_setting](https://github.com/fuadarradhi/datetime_setting) plugin.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install capacitor-datetime-setting
|
|
11
|
+
npx cap sync
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## API
|
|
15
|
+
|
|
16
|
+
### `timeIsAuto()`
|
|
17
|
+
|
|
18
|
+
Check if automatic time is enabled on the device.
|
|
19
|
+
|
|
20
|
+
**Returns:** `Promise<{ value: boolean }>`
|
|
21
|
+
|
|
22
|
+
**Platform Support:**
|
|
23
|
+
- ✅ Android: Returns actual setting value
|
|
24
|
+
- ⚠️ iOS: Always returns `false` (iOS doesn't provide API to check this)
|
|
25
|
+
|
|
26
|
+
**Example:**
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import { DateTimeSetting } from 'capacitor-datetime-setting';
|
|
30
|
+
|
|
31
|
+
const result = await DateTimeSetting.timeIsAuto();
|
|
32
|
+
console.log('Auto time enabled:', result.value);
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
### `timeZoneIsAuto()`
|
|
38
|
+
|
|
39
|
+
Check if automatic timezone is enabled on the device.
|
|
40
|
+
|
|
41
|
+
**Returns:** `Promise<{ value: boolean }>`
|
|
42
|
+
|
|
43
|
+
**Platform Support:**
|
|
44
|
+
- ✅ Android: Returns actual setting value
|
|
45
|
+
- ⚠️ iOS: Always returns `false` (iOS doesn't provide API to check this)
|
|
46
|
+
|
|
47
|
+
**Example:**
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
import { DateTimeSetting } from 'capacitor-datetime-setting';
|
|
51
|
+
|
|
52
|
+
const result = await DateTimeSetting.timeZoneIsAuto();
|
|
53
|
+
console.log('Auto timezone enabled:', result.value);
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
### `openSetting()`
|
|
59
|
+
|
|
60
|
+
Open the device's date and time settings screen.
|
|
61
|
+
|
|
62
|
+
**Returns:** `Promise<void>`
|
|
63
|
+
|
|
64
|
+
**Platform Support:**
|
|
65
|
+
- ✅ Android: Opens Date & Time settings directly
|
|
66
|
+
- ⚠️ iOS: Opens main Settings app (cannot open specific settings page)
|
|
67
|
+
|
|
68
|
+
**Example:**
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
import { DateTimeSetting } from 'capacitor-datetime-setting';
|
|
72
|
+
|
|
73
|
+
await DateTimeSetting.openSetting();
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Usage Example
|
|
77
|
+
|
|
78
|
+
Here's a complete example showing how to check settings and prompt user to enable auto time:
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
import { DateTimeSetting } from 'capacitor-datetime-setting';
|
|
82
|
+
import { Capacitor } from '@capacitor/core';
|
|
83
|
+
|
|
84
|
+
async function checkAutoTimeSettings() {
|
|
85
|
+
try {
|
|
86
|
+
const timeResult = await DateTimeSetting.timeIsAuto();
|
|
87
|
+
const timezoneResult = await DateTimeSetting.timeZoneIsAuto();
|
|
88
|
+
|
|
89
|
+
const platform = Capacitor.getPlatform();
|
|
90
|
+
|
|
91
|
+
if (platform === 'android') {
|
|
92
|
+
if (!timeResult.value || !timezoneResult.value) {
|
|
93
|
+
// Show alert to user
|
|
94
|
+
const shouldOpen = confirm(
|
|
95
|
+
'Please enable automatic date & time and timezone for accurate time tracking.'
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
if (shouldOpen) {
|
|
99
|
+
await DateTimeSetting.openSetting();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
} else if (platform === 'ios') {
|
|
103
|
+
// iOS doesn't provide API to check, so we can only prompt user to check manually
|
|
104
|
+
const shouldOpen = confirm(
|
|
105
|
+
'Please ensure automatic date & time is enabled in Settings.'
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
if (shouldOpen) {
|
|
109
|
+
await DateTimeSetting.openSetting();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
} catch (error) {
|
|
113
|
+
console.error('Error checking time settings:', error);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## Platform-Specific Notes
|
|
119
|
+
|
|
120
|
+
### Android
|
|
121
|
+
|
|
122
|
+
The plugin uses Android's `Settings.Global` API to check the auto time and timezone settings. It supports Android API level 17 (Jelly Bean MR1) and above, with fallback to `Settings.System` for older versions.
|
|
123
|
+
|
|
124
|
+
**Permissions:** No special permissions required.
|
|
125
|
+
|
|
126
|
+
### iOS
|
|
127
|
+
|
|
128
|
+
iOS does not provide public APIs to:
|
|
129
|
+
- Check if automatic date & time is enabled
|
|
130
|
+
- Check if automatic timezone is enabled
|
|
131
|
+
- Open the Date & Time settings page directly
|
|
132
|
+
|
|
133
|
+
Therefore:
|
|
134
|
+
- `timeIsAuto()` and `timeZoneIsAuto()` always return `false`
|
|
135
|
+
- `openSetting()` opens the main Settings app instead of the specific Date & Time page
|
|
136
|
+
|
|
137
|
+
This is a platform limitation, not a plugin limitation.
|
|
138
|
+
|
|
139
|
+
### Web
|
|
140
|
+
|
|
141
|
+
This plugin is not supported on web. All methods will throw "Not implemented on web" errors.
|
|
142
|
+
|
|
143
|
+
## License
|
|
144
|
+
|
|
145
|
+
MIT
|
|
146
|
+
|
|
147
|
+
## Credits
|
|
148
|
+
|
|
149
|
+
This plugin is based on the Flutter [datetime_setting](https://github.com/fuadarradhi/datetime_setting) plugin by [fuadarradhi](https://github.com/fuadarradhi).
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
buildscript {
|
|
2
|
+
repositories {
|
|
3
|
+
google()
|
|
4
|
+
mavenCentral()
|
|
5
|
+
}
|
|
6
|
+
dependencies {
|
|
7
|
+
classpath 'com.android.tools.build:gradle:8.0.0'
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
apply plugin: 'com.android.library'
|
|
12
|
+
|
|
13
|
+
android {
|
|
14
|
+
namespace "com.datetimesetting"
|
|
15
|
+
compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 33
|
|
16
|
+
defaultConfig {
|
|
17
|
+
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
|
|
18
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 33
|
|
19
|
+
versionCode 1
|
|
20
|
+
versionName "1.0"
|
|
21
|
+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
22
|
+
}
|
|
23
|
+
buildTypes {
|
|
24
|
+
release {
|
|
25
|
+
minifyEnabled false
|
|
26
|
+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
lintOptions {
|
|
30
|
+
abortOnError false
|
|
31
|
+
}
|
|
32
|
+
compileOptions {
|
|
33
|
+
sourceCompatibility JavaVersion.VERSION_17
|
|
34
|
+
targetCompatibility JavaVersion.VERSION_17
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
repositories {
|
|
39
|
+
google()
|
|
40
|
+
mavenCentral()
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
dependencies {
|
|
44
|
+
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
45
|
+
implementation project(':capacitor-android')
|
|
46
|
+
testImplementation 'junit:junit:4.13.2'
|
|
47
|
+
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
|
|
48
|
+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
|
|
49
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
package com.datetimesetting;
|
|
2
|
+
|
|
3
|
+
import android.content.Intent;
|
|
4
|
+
import android.os.Build;
|
|
5
|
+
import android.provider.Settings;
|
|
6
|
+
|
|
7
|
+
import com.getcapacitor.JSObject;
|
|
8
|
+
import com.getcapacitor.Plugin;
|
|
9
|
+
import com.getcapacitor.PluginCall;
|
|
10
|
+
import com.getcapacitor.PluginMethod;
|
|
11
|
+
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* DateTimeSettingPlugin
|
|
15
|
+
*
|
|
16
|
+
* Capacitor plugin to check auto time/timezone settings and open device settings.
|
|
17
|
+
*/
|
|
18
|
+
@CapacitorPlugin(name = "DateTimeSetting")
|
|
19
|
+
public class DateTimeSettingPlugin extends Plugin {
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Check if automatic time is enabled on the device.
|
|
23
|
+
*
|
|
24
|
+
* @param call The plugin call
|
|
25
|
+
*/
|
|
26
|
+
@PluginMethod
|
|
27
|
+
public void timeIsAuto(PluginCall call) {
|
|
28
|
+
try {
|
|
29
|
+
boolean isAuto;
|
|
30
|
+
|
|
31
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
|
32
|
+
isAuto = Settings.Global.getInt(
|
|
33
|
+
getContext().getContentResolver(),
|
|
34
|
+
Settings.Global.AUTO_TIME,
|
|
35
|
+
0
|
|
36
|
+
) == 1;
|
|
37
|
+
} else {
|
|
38
|
+
isAuto = Settings.System.getInt(
|
|
39
|
+
getContext().getContentResolver(),
|
|
40
|
+
Settings.System.AUTO_TIME,
|
|
41
|
+
0
|
|
42
|
+
) == 1;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
JSObject result = new JSObject();
|
|
46
|
+
result.put("value", isAuto);
|
|
47
|
+
call.resolve(result);
|
|
48
|
+
} catch (Exception e) {
|
|
49
|
+
call.reject("Failed to check auto time setting", e);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Check if automatic timezone is enabled on the device.
|
|
55
|
+
*
|
|
56
|
+
* @param call The plugin call
|
|
57
|
+
*/
|
|
58
|
+
@PluginMethod
|
|
59
|
+
public void timeZoneIsAuto(PluginCall call) {
|
|
60
|
+
try {
|
|
61
|
+
boolean isAuto;
|
|
62
|
+
|
|
63
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
|
64
|
+
isAuto = Settings.Global.getInt(
|
|
65
|
+
getContext().getContentResolver(),
|
|
66
|
+
Settings.Global.AUTO_TIME_ZONE,
|
|
67
|
+
0
|
|
68
|
+
) == 1;
|
|
69
|
+
} else {
|
|
70
|
+
isAuto = Settings.System.getInt(
|
|
71
|
+
getContext().getContentResolver(),
|
|
72
|
+
Settings.System.AUTO_TIME_ZONE,
|
|
73
|
+
0
|
|
74
|
+
) == 1;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
JSObject result = new JSObject();
|
|
78
|
+
result.put("value", isAuto);
|
|
79
|
+
call.resolve(result);
|
|
80
|
+
} catch (Exception e) {
|
|
81
|
+
call.reject("Failed to check auto timezone setting", e);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Open the device's date and time settings screen.
|
|
87
|
+
*
|
|
88
|
+
* @param call The plugin call
|
|
89
|
+
*/
|
|
90
|
+
@PluginMethod
|
|
91
|
+
public void openSetting(PluginCall call) {
|
|
92
|
+
try {
|
|
93
|
+
Intent intent = new Intent(Settings.ACTION_DATE_SETTINGS);
|
|
94
|
+
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
95
|
+
getContext().startActivity(intent);
|
|
96
|
+
call.resolve();
|
|
97
|
+
} catch (Exception e) {
|
|
98
|
+
call.reject("Failed to open date/time settings", e);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export interface DateTimeSettingPlugin {
|
|
2
|
+
/**
|
|
3
|
+
* Check if automatic time is enabled on the device.
|
|
4
|
+
*
|
|
5
|
+
* @returns Promise with boolean value indicating if auto time is enabled
|
|
6
|
+
* @since 1.0.0
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const result = await DateTimeSetting.timeIsAuto();
|
|
11
|
+
* console.log('Auto time enabled:', result.value);
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
timeIsAuto(): Promise<{
|
|
15
|
+
value: boolean;
|
|
16
|
+
}>;
|
|
17
|
+
/**
|
|
18
|
+
* Check if automatic timezone is enabled on the device.
|
|
19
|
+
*
|
|
20
|
+
* @returns Promise with boolean value indicating if auto timezone is enabled
|
|
21
|
+
* @since 1.0.0
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const result = await DateTimeSetting.timeZoneIsAuto();
|
|
26
|
+
* console.log('Auto timezone enabled:', result.value);
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
timeZoneIsAuto(): Promise<{
|
|
30
|
+
value: boolean;
|
|
31
|
+
}>;
|
|
32
|
+
/**
|
|
33
|
+
* Open the device's date and time settings screen.
|
|
34
|
+
*
|
|
35
|
+
* @returns Promise that resolves when settings are opened
|
|
36
|
+
* @since 1.0.0
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* await DateTimeSetting.openSetting();
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
openSetting(): Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=definitions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definitions.d.ts","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,qBAAqB;IAClC;;;;;;;;;;;OAWG;IACH,UAAU,IAAI,OAAO,CAAC;QAAE,KAAK,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IAE1C;;;;;;;;;;;OAWG;IACH,cAAc,IAAI,OAAO,CAAC;QAAE,KAAK,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;IAE9C;;;;;;;;;;OAUG;IACH,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAChC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAE3D,QAAA,MAAM,eAAe,uBAEnB,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,eAAe,EAAE,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
import type { DateTimeSettingPlugin } from './definitions';
|
|
3
|
+
export declare class DateTimeSettingWeb extends WebPlugin implements DateTimeSettingPlugin {
|
|
4
|
+
timeIsAuto(): Promise<{
|
|
5
|
+
value: boolean;
|
|
6
|
+
}>;
|
|
7
|
+
timeZoneIsAuto(): Promise<{
|
|
8
|
+
value: boolean;
|
|
9
|
+
}>;
|
|
10
|
+
openSetting(): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=web.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.d.ts","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAE3D,qBAAa,kBAAmB,SAAQ,SAAU,YAAW,qBAAqB;IACxE,UAAU,IAAI,OAAO,CAAC;QAAE,KAAK,EAAE,OAAO,CAAA;KAAE,CAAC;IAIzC,cAAc,IAAI,OAAO,CAAC;QAAE,KAAK,EAAE,OAAO,CAAA;KAAE,CAAC;IAI7C,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;CAGrC"}
|
package/dist/esm/web.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
export class DateTimeSettingWeb extends WebPlugin {
|
|
3
|
+
async timeIsAuto() {
|
|
4
|
+
throw this.unimplemented('Not implemented on web.');
|
|
5
|
+
}
|
|
6
|
+
async timeZoneIsAuto() {
|
|
7
|
+
throw this.unimplemented('Not implemented on web.');
|
|
8
|
+
}
|
|
9
|
+
async openSetting() {
|
|
10
|
+
throw this.unimplemented('Not implemented on web.');
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var core = require('@capacitor/core');
|
|
6
|
+
|
|
7
|
+
const DateTimeSetting = core.registerPlugin('DateTimeSetting', {
|
|
8
|
+
web: () => Promise.resolve().then(function () { return web; }).then(m => new m.DateTimeSettingWeb()),
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
class DateTimeSettingWeb extends core.WebPlugin {
|
|
12
|
+
async timeIsAuto() {
|
|
13
|
+
throw this.unimplemented('Not implemented on web.');
|
|
14
|
+
}
|
|
15
|
+
async timeZoneIsAuto() {
|
|
16
|
+
throw this.unimplemented('Not implemented on web.');
|
|
17
|
+
}
|
|
18
|
+
async openSetting() {
|
|
19
|
+
throw this.unimplemented('Not implemented on web.');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
24
|
+
__proto__: null,
|
|
25
|
+
DateTimeSettingWeb: DateTimeSettingWeb
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
exports.DateTimeSetting = DateTimeSetting;
|
|
29
|
+
//# sourceMappingURL=plugin.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst DateTimeSetting = registerPlugin('DateTimeSetting', {\n web: () => import('./web').then(m => new m.DateTimeSettingWeb()),\n});\nexport * from './definitions';\nexport { DateTimeSetting };\n","import { WebPlugin } from '@capacitor/core';\nexport class DateTimeSettingWeb extends WebPlugin {\n async timeIsAuto() {\n throw this.unimplemented('Not implemented on web.');\n }\n async timeZoneIsAuto() {\n throw this.unimplemented('Not implemented on web.');\n }\n async openSetting() {\n throw this.unimplemented('Not implemented on web.');\n }\n}\n"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;;;AACK,MAAC,eAAe,GAAGA,mBAAc,CAAC,iBAAiB,EAAE;AAC1D,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,kBAAkB,EAAE,CAAC;AACpE,CAAC;;ACFM,MAAM,kBAAkB,SAASC,cAAS,CAAC;AAClD,IAAI,MAAM,UAAU,GAAG;AACvB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;AAC5D,KAAK;AACL,IAAI,MAAM,cAAc,GAAG;AAC3B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;AAC5D,KAAK;AACL,IAAI,MAAM,WAAW,GAAG;AACxB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;AAC5D,KAAK;AACL;;;;;;;;;"}
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
var capacitorDatetimeSetting = (function (exports, core) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const DateTimeSetting = core.registerPlugin('DateTimeSetting', {
|
|
5
|
+
web: () => Promise.resolve().then(function () { return web; }).then(m => new m.DateTimeSettingWeb()),
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
class DateTimeSettingWeb extends core.WebPlugin {
|
|
9
|
+
async timeIsAuto() {
|
|
10
|
+
throw this.unimplemented('Not implemented on web.');
|
|
11
|
+
}
|
|
12
|
+
async timeZoneIsAuto() {
|
|
13
|
+
throw this.unimplemented('Not implemented on web.');
|
|
14
|
+
}
|
|
15
|
+
async openSetting() {
|
|
16
|
+
throw this.unimplemented('Not implemented on web.');
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
21
|
+
__proto__: null,
|
|
22
|
+
DateTimeSettingWeb: DateTimeSettingWeb
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
exports.DateTimeSetting = DateTimeSetting;
|
|
26
|
+
|
|
27
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
28
|
+
|
|
29
|
+
return exports;
|
|
30
|
+
|
|
31
|
+
})({}, capacitorExports);
|
|
32
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst DateTimeSetting = registerPlugin('DateTimeSetting', {\n web: () => import('./web').then(m => new m.DateTimeSettingWeb()),\n});\nexport * from './definitions';\nexport { DateTimeSetting };\n","import { WebPlugin } from '@capacitor/core';\nexport class DateTimeSettingWeb extends WebPlugin {\n async timeIsAuto() {\n throw this.unimplemented('Not implemented on web.');\n }\n async timeZoneIsAuto() {\n throw this.unimplemented('Not implemented on web.');\n }\n async openSetting() {\n throw this.unimplemented('Not implemented on web.');\n }\n}\n"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,eAAe,GAAGA,mBAAc,CAAC,iBAAiB,EAAE;IAC1D,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,kBAAkB,EAAE,CAAC;IACpE,CAAC;;ICFM,MAAM,kBAAkB,SAASC,cAAS,CAAC;IAClD,IAAI,MAAM,UAAU,GAAG;IACvB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IAC5D,KAAK;IACL,IAAI,MAAM,cAAc,GAAG;IAC3B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IAC5D,KAAK;IACL,IAAI,MAAM,WAAW,GAAG;IACxB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC,CAAC;IAC5D,KAAK;IACL;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#import <Foundation/Foundation.h>
|
|
2
|
+
#import <Capacitor/Capacitor.h>
|
|
3
|
+
|
|
4
|
+
// Define the plugin using the CAP_PLUGIN Macro, and
|
|
5
|
+
// each method the plugin supports using the CAP_PLUGIN_METHOD macro.
|
|
6
|
+
CAP_PLUGIN(DateTimeSettingPlugin, "DateTimeSetting",
|
|
7
|
+
CAP_PLUGIN_METHOD(timeIsAuto, CAPPluginReturnPromise);
|
|
8
|
+
CAP_PLUGIN_METHOD(timeZoneIsAuto, CAPPluginReturnPromise);
|
|
9
|
+
CAP_PLUGIN_METHOD(openSetting, CAPPluginReturnPromise);
|
|
10
|
+
)
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* DateTimeSettingPlugin
|
|
6
|
+
*
|
|
7
|
+
* Capacitor plugin to check auto time/timezone settings and open device settings.
|
|
8
|
+
*
|
|
9
|
+
* Note: iOS does not provide APIs to check if auto time/timezone is enabled.
|
|
10
|
+
* The timeIsAuto and timeZoneIsAuto methods will return false with a note.
|
|
11
|
+
*/
|
|
12
|
+
@objc(DateTimeSettingPlugin)
|
|
13
|
+
public class DateTimeSettingPlugin: CAPPlugin {
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Check if automatic time is enabled on the device.
|
|
17
|
+
*
|
|
18
|
+
* Note: iOS does not provide an API to check this setting.
|
|
19
|
+
* This method returns false as iOS doesn't expose this information.
|
|
20
|
+
*/
|
|
21
|
+
@objc func timeIsAuto(_ call: CAPPluginCall) {
|
|
22
|
+
// iOS does not provide API to check auto time setting
|
|
23
|
+
// We return false as we cannot determine the actual state
|
|
24
|
+
call.resolve([
|
|
25
|
+
"value": false
|
|
26
|
+
])
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Check if automatic timezone is enabled on the device.
|
|
31
|
+
*
|
|
32
|
+
* Note: iOS does not provide an API to check this setting.
|
|
33
|
+
* This method returns false as iOS doesn't expose this information.
|
|
34
|
+
*/
|
|
35
|
+
@objc func timeZoneIsAuto(_ call: CAPPluginCall) {
|
|
36
|
+
// iOS does not provide API to check auto timezone setting
|
|
37
|
+
// We return false as we cannot determine the actual state
|
|
38
|
+
call.resolve([
|
|
39
|
+
"value": false
|
|
40
|
+
])
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Open the device's Settings app.
|
|
45
|
+
*
|
|
46
|
+
* On iOS, this opens the main Settings app as there's no direct way
|
|
47
|
+
* to open the Date & Time settings page.
|
|
48
|
+
*/
|
|
49
|
+
@objc func openSetting(_ call: CAPPluginCall) {
|
|
50
|
+
DispatchQueue.main.async {
|
|
51
|
+
if let settingsUrl = URL(string: UIApplication.openSettingsURLString) {
|
|
52
|
+
if UIApplication.shared.canOpenURL(settingsUrl) {
|
|
53
|
+
UIApplication.shared.open(settingsUrl, options: [:]) { success in
|
|
54
|
+
if success {
|
|
55
|
+
call.resolve()
|
|
56
|
+
} else {
|
|
57
|
+
call.reject("Failed to open settings")
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
} else {
|
|
61
|
+
call.reject("Cannot open settings URL")
|
|
62
|
+
}
|
|
63
|
+
} else {
|
|
64
|
+
call.reject("Invalid settings URL")
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@greatdayhr/capacitor-datetime-setting",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Capacitor plugin to get information about auto time and auto timezone, open setting if not set to auto",
|
|
5
|
+
"main": "dist/plugin.cjs.js",
|
|
6
|
+
"module": "dist/esm/index.js",
|
|
7
|
+
"types": "dist/esm/index.d.ts",
|
|
8
|
+
"unpkg": "dist/plugin.js",
|
|
9
|
+
"files": [
|
|
10
|
+
"android/build.gradle",
|
|
11
|
+
"android/src",
|
|
12
|
+
"dist/",
|
|
13
|
+
"ios/Plugin/",
|
|
14
|
+
"CapacitorDatetimeSetting.podspec"
|
|
15
|
+
],
|
|
16
|
+
"author": "rakaraka029",
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/rakaraka029/capacitor-datetime-setting.git"
|
|
21
|
+
},
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://github.com/rakaraka029/capacitor-datetime-setting/issues"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"capacitor",
|
|
27
|
+
"plugin",
|
|
28
|
+
"native",
|
|
29
|
+
"datetime",
|
|
30
|
+
"timezone",
|
|
31
|
+
"auto-time",
|
|
32
|
+
"settings"
|
|
33
|
+
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
|
|
36
|
+
"verify:ios": "cd ios && pod install && xcodebuild -workspace Plugin.xcworkspace -scheme Plugin -destination generic/platform=iOS && cd ..",
|
|
37
|
+
"verify:android": "cd android && ./gradlew clean build test && cd ..",
|
|
38
|
+
"verify:web": "npm run build",
|
|
39
|
+
"lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
|
|
40
|
+
"fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
|
|
41
|
+
"eslint": "eslint . --ext ts",
|
|
42
|
+
"prettier": "prettier \"**/*.{css,html,ts,js,java}\"",
|
|
43
|
+
"swiftlint": "node-swiftlint",
|
|
44
|
+
"docgen": "docgen --api DateTimeSettingPlugin --output-readme README.md --output-json dist/docs.json",
|
|
45
|
+
"build": "npm run clean && tsc && rollup -c rollup.config.js",
|
|
46
|
+
"clean": "rimraf ./dist",
|
|
47
|
+
"watch": "tsc --watch",
|
|
48
|
+
"prepublishOnly": "npm run build"
|
|
49
|
+
},
|
|
50
|
+
"devDependencies": {
|
|
51
|
+
"@capacitor/android": "^5.0.0",
|
|
52
|
+
"@capacitor/core": "^5.0.0",
|
|
53
|
+
"@capacitor/docgen": "^0.2.0",
|
|
54
|
+
"@capacitor/ios": "^5.0.0",
|
|
55
|
+
"@ionic/eslint-config": "^0.3.0",
|
|
56
|
+
"@ionic/prettier-config": "^1.0.1",
|
|
57
|
+
"@ionic/swiftlint-config": "^1.1.2",
|
|
58
|
+
"eslint": "^7.11.0",
|
|
59
|
+
"prettier": "~2.3.0",
|
|
60
|
+
"prettier-plugin-java": "~1.0.2",
|
|
61
|
+
"rimraf": "^3.0.2",
|
|
62
|
+
"rollup": "^2.32.0",
|
|
63
|
+
"swiftlint": "^1.0.1",
|
|
64
|
+
"typescript": "~4.1.5"
|
|
65
|
+
},
|
|
66
|
+
"peerDependencies": {
|
|
67
|
+
"@capacitor/core": "^5.0.0"
|
|
68
|
+
},
|
|
69
|
+
"prettier": "@ionic/prettier-config",
|
|
70
|
+
"eslintConfig": {
|
|
71
|
+
"extends": "@ionic/eslint-config/recommended"
|
|
72
|
+
},
|
|
73
|
+
"capacitor": {
|
|
74
|
+
"ios": {
|
|
75
|
+
"src": "ios"
|
|
76
|
+
},
|
|
77
|
+
"android": {
|
|
78
|
+
"src": "android"
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|