@greatdayhr/capacitor-datetime-setting 1.0.0 → 1.1.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 +1 -1
- package/README.md +18 -26
- package/android/build.gradle +2 -2
- package/dist/plugin.cjs.js +0 -2
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +0 -2
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/DateTimeSettingPlugin.swift +23 -10
- package/package.json +10 -10
|
@@ -11,7 +11,7 @@ Pod::Spec.new do |s|
|
|
|
11
11
|
s.author = package['author']
|
|
12
12
|
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
|
|
13
13
|
s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
|
|
14
|
-
s.ios.deployment_target = '
|
|
14
|
+
s.ios.deployment_target = '14.0'
|
|
15
15
|
s.dependency 'Capacitor'
|
|
16
16
|
s.swift_version = '5.1'
|
|
17
17
|
end
|
package/README.md
CHANGED
|
@@ -20,8 +20,8 @@ Check if automatic time is enabled on the device.
|
|
|
20
20
|
**Returns:** `Promise<{ value: boolean }>`
|
|
21
21
|
|
|
22
22
|
**Platform Support:**
|
|
23
|
-
- ✅ Android: Returns actual setting value
|
|
24
|
-
-
|
|
23
|
+
- ✅ Android: Returns actual setting value using `Settings.Global.AUTO_TIME`
|
|
24
|
+
- ✅ iOS: Returns actual setting value using `NSTimeZone.autoupdatingCurrent` comparison
|
|
25
25
|
|
|
26
26
|
**Example:**
|
|
27
27
|
|
|
@@ -41,8 +41,8 @@ Check if automatic timezone is enabled on the device.
|
|
|
41
41
|
**Returns:** `Promise<{ value: boolean }>`
|
|
42
42
|
|
|
43
43
|
**Platform Support:**
|
|
44
|
-
- ✅ Android: Returns actual setting value
|
|
45
|
-
-
|
|
44
|
+
- ✅ Android: Returns actual setting value using `Settings.Global.AUTO_TIME_ZONE`
|
|
45
|
+
- ✅ iOS: Returns actual setting value using `NSTimeZone.autoupdatingCurrent` comparison
|
|
46
46
|
|
|
47
47
|
**Example:**
|
|
48
48
|
|
|
@@ -88,21 +88,11 @@ async function checkAutoTimeSettings() {
|
|
|
88
88
|
|
|
89
89
|
const platform = Capacitor.getPlatform();
|
|
90
90
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
|
91
|
+
// Both Android and iOS can now detect auto time settings
|
|
92
|
+
if (!timeResult.value || !timezoneResult.value) {
|
|
93
|
+
// Show alert to user
|
|
104
94
|
const shouldOpen = confirm(
|
|
105
|
-
'Please
|
|
95
|
+
'Please enable automatic date & time and timezone for accurate time tracking.'
|
|
106
96
|
);
|
|
107
97
|
|
|
108
98
|
if (shouldOpen) {
|
|
@@ -125,16 +115,18 @@ The plugin uses Android's `Settings.Global` API to check the auto time and timez
|
|
|
125
115
|
|
|
126
116
|
### iOS
|
|
127
117
|
|
|
128
|
-
iOS does not provide public APIs to:
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
-
|
|
118
|
+
iOS does not provide direct public APIs to check auto date/time settings, but this plugin uses a **workaround** technique:
|
|
119
|
+
|
|
120
|
+
**Detection Method:**
|
|
121
|
+
- Compares `NSTimeZone.autoupdatingCurrent` with `NSTimeZone.system`
|
|
122
|
+
- When auto date/time is **enabled**: these two timezone objects are equal
|
|
123
|
+
- When auto date/time is **disabled**: they may differ
|
|
132
124
|
|
|
133
|
-
|
|
134
|
-
- `
|
|
135
|
-
-
|
|
125
|
+
**Limitations:**
|
|
126
|
+
- `openSetting()` opens the main Settings app instead of the specific Date & Time page (iOS restriction)
|
|
127
|
+
- The detection method is a workaround and may not be 100% accurate in all edge cases
|
|
136
128
|
|
|
137
|
-
This is
|
|
129
|
+
**Credit:** This technique is inspired by the Flutter [date_change_checker](https://github.com/error404sushant/date_change_checker) plugin.
|
|
138
130
|
|
|
139
131
|
### Web
|
|
140
132
|
|
package/android/build.gradle
CHANGED
|
@@ -12,10 +12,10 @@ apply plugin: 'com.android.library'
|
|
|
12
12
|
|
|
13
13
|
android {
|
|
14
14
|
namespace "com.datetimesetting"
|
|
15
|
-
compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion :
|
|
15
|
+
compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 34
|
|
16
16
|
defaultConfig {
|
|
17
17
|
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
|
|
18
|
-
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion :
|
|
18
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 34
|
|
19
19
|
versionCode 1
|
|
20
20
|
versionName "1.0"
|
|
21
21
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
package/dist/plugin.cjs.js
CHANGED
package/dist/plugin.cjs.js.map
CHANGED
|
@@ -1 +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":"
|
|
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;AAC3D,IAAI;AACJ,IAAI,MAAM,cAAc,GAAG;AAC3B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;AAC3D,IAAI;AACJ,IAAI,MAAM,WAAW,GAAG;AACxB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;AAC3D,IAAI;AACJ;;;;;;;;;"}
|
package/dist/plugin.js
CHANGED
package/dist/plugin.js.map
CHANGED
|
@@ -1 +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
|
|
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;IAC3D,IAAI;IACJ,IAAI,MAAM,cAAc,GAAG;IAC3B,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;IAC3D,IAAI;IACJ,IAAI,MAAM,WAAW,GAAG;IACxB,QAAQ,MAAM,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;IAC3D,IAAI;IACJ;;;;;;;;;;;;;;;"}
|
|
@@ -15,28 +15,41 @@ public class DateTimeSettingPlugin: CAPPlugin {
|
|
|
15
15
|
/**
|
|
16
16
|
* Check if automatic time is enabled on the device.
|
|
17
17
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
18
|
+
* iOS Implementation:
|
|
19
|
+
* Uses NSTimeZone.autoupdatingCurrent comparison with NSTimeZone.system
|
|
20
|
+
* to determine if automatic date/time is enabled.
|
|
21
|
+
*
|
|
22
|
+
* When auto date/time is ON: autoupdatingCurrent equals system timezone
|
|
23
|
+
* When auto date/time is OFF: they may differ
|
|
20
24
|
*/
|
|
21
25
|
@objc func timeIsAuto(_ call: CAPPluginCall) {
|
|
22
|
-
|
|
23
|
-
|
|
26
|
+
let autoUpdatingTimeZone = NSTimeZone.autoupdatingCurrent
|
|
27
|
+
let systemTimeZone = NSTimeZone.system
|
|
28
|
+
|
|
29
|
+
// If they are equal, auto date/time is likely enabled
|
|
30
|
+
let isAutoEnabled = autoUpdatingTimeZone.isEqual(to: systemTimeZone)
|
|
31
|
+
|
|
24
32
|
call.resolve([
|
|
25
|
-
"value":
|
|
33
|
+
"value": isAutoEnabled
|
|
26
34
|
])
|
|
27
35
|
}
|
|
28
36
|
|
|
29
37
|
/**
|
|
30
38
|
* Check if automatic timezone is enabled on the device.
|
|
31
39
|
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
40
|
+
* iOS Implementation:
|
|
41
|
+
* Uses the same NSTimeZone comparison technique as timeIsAuto.
|
|
42
|
+
* This is because iOS doesn't separate auto time and auto timezone settings.
|
|
34
43
|
*/
|
|
35
44
|
@objc func timeZoneIsAuto(_ call: CAPPluginCall) {
|
|
36
|
-
|
|
37
|
-
|
|
45
|
+
let autoUpdatingTimeZone = NSTimeZone.autoupdatingCurrent
|
|
46
|
+
let systemTimeZone = NSTimeZone.system
|
|
47
|
+
|
|
48
|
+
// If they are equal, auto timezone is likely enabled
|
|
49
|
+
let isAutoEnabled = autoUpdatingTimeZone.isEqual(to: systemTimeZone)
|
|
50
|
+
|
|
38
51
|
call.resolve([
|
|
39
|
-
"value":
|
|
52
|
+
"value": isAutoEnabled
|
|
40
53
|
])
|
|
41
54
|
}
|
|
42
55
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@greatdayhr/capacitor-datetime-setting",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Capacitor plugin to get information about auto time and auto timezone, open setting if not set to auto",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -48,23 +48,23 @@
|
|
|
48
48
|
"prepublishOnly": "npm run build"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@capacitor/android": "^
|
|
52
|
-
"@capacitor/core": "^
|
|
53
|
-
"@capacitor/docgen": "^0.2.
|
|
54
|
-
"@capacitor/ios": "^
|
|
51
|
+
"@capacitor/android": "^7.0.0",
|
|
52
|
+
"@capacitor/core": "^7.0.0",
|
|
53
|
+
"@capacitor/docgen": "^0.2.2",
|
|
54
|
+
"@capacitor/ios": "^7.0.0",
|
|
55
55
|
"@ionic/eslint-config": "^0.3.0",
|
|
56
56
|
"@ionic/prettier-config": "^1.0.1",
|
|
57
57
|
"@ionic/swiftlint-config": "^1.1.2",
|
|
58
|
-
"eslint": "^
|
|
59
|
-
"prettier": "~
|
|
58
|
+
"eslint": "^8.57.0",
|
|
59
|
+
"prettier": "~3.0.0",
|
|
60
60
|
"prettier-plugin-java": "~1.0.2",
|
|
61
61
|
"rimraf": "^3.0.2",
|
|
62
|
-
"rollup": "^
|
|
62
|
+
"rollup": "^4.0.0",
|
|
63
63
|
"swiftlint": "^1.0.1",
|
|
64
|
-
"typescript": "~
|
|
64
|
+
"typescript": "~5.6.0"
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
67
|
-
"@capacitor/core": "^
|
|
67
|
+
"@capacitor/core": "^7.0.0"
|
|
68
68
|
},
|
|
69
69
|
"prettier": "@ionic/prettier-config",
|
|
70
70
|
"eslintConfig": {
|