@gachlab/capacitor-dnd-plugin 1.0.0 → 1.2.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/README.md CHANGED
@@ -13,44 +13,21 @@ npx cap sync
13
13
 
14
14
  <docgen-index>
15
15
 
16
- * [`monitor(...)`](#monitor)
17
- * [`toggleDoNotDisturb()`](#toggledonotdisturb)
18
- * [Interfaces](#interfaces)
16
+ * [`monitor()`](#monitor)
19
17
 
20
18
  </docgen-index>
21
19
 
22
20
  <docgen-api>
23
21
  <!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
24
22
 
25
- ### monitor(...)
23
+ ### monitor()
26
24
 
27
25
  ```typescript
28
- monitor(callback: (result: DoNotDisturbState) => void) => Promise<void>
26
+ monitor() => Promise<{ enabled: boolean; }>
29
27
  ```
30
28
 
31
- | Param | Type |
32
- | -------------- | ------------------------------------------------------------------------------------ |
33
- | **`callback`** | <code>(result: <a href="#donotdisturbstate">DoNotDisturbState</a>) =&gt; void</code> |
29
+ **Returns:** <code>Promise&lt;{ enabled: boolean; }&gt;</code>
34
30
 
35
31
  --------------------
36
32
 
37
-
38
- ### toggleDoNotDisturb()
39
-
40
- ```typescript
41
- toggleDoNotDisturb() => Promise<void>
42
- ```
43
-
44
- --------------------
45
-
46
-
47
- ### Interfaces
48
-
49
-
50
- #### DoNotDisturbState
51
-
52
- | Prop | Type |
53
- | ------------------ | -------------------- |
54
- | **`doNotDisturb`** | <code>boolean</code> |
55
-
56
33
  </docgen-api>
@@ -1,2 +1,3 @@
1
1
  <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ <uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />
2
3
  </manifest>
@@ -0,0 +1,40 @@
1
+ package com.gachlab.capacitor.dnd;
2
+
3
+ import android.app.NotificationManager;
4
+ import android.content.BroadcastReceiver;
5
+ import android.content.Context;
6
+ import android.content.Intent;
7
+ import android.content.IntentFilter;
8
+
9
+ public class DoNotDisturb {
10
+ private Context context;
11
+ private BroadcastReceiver receiver;
12
+ private Runnable callback;
13
+
14
+ public DoNotDisturb(Context context) {
15
+ this.context = context;
16
+ }
17
+
18
+ public boolean isEnabled() {
19
+ NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
20
+ return nm.getCurrentInterruptionFilter() != NotificationManager.INTERRUPTION_FILTER_ALL;
21
+ }
22
+
23
+ public void startListening(Runnable callback) {
24
+ this.callback = callback;
25
+ receiver = new BroadcastReceiver() {
26
+ @Override
27
+ public void onReceive(Context context, Intent intent) {
28
+ if (callback != null) callback.run();
29
+ }
30
+ };
31
+ context.registerReceiver(receiver, new IntentFilter(NotificationManager.ACTION_INTERRUPTION_FILTER_CHANGED));
32
+ }
33
+
34
+ public void stopListening() {
35
+ if (receiver != null) {
36
+ context.unregisterReceiver(receiver);
37
+ receiver = null;
38
+ }
39
+ }
40
+ }
@@ -1,84 +1,42 @@
1
1
  package com.gachlab.capacitor.dnd;
2
2
 
3
- import static android.Manifest.permission.ACCESS_NOTIFICATION_POLICY;
4
-
5
- import android.app.NotificationManager;
6
- import android.content.Context;
7
- import android.os.Build;
8
- import android.provider.Settings;
9
-
10
- import androidx.annotation.RequiresApi;
3
+ import android.Manifest;
11
4
 
12
5
  import com.getcapacitor.JSObject;
13
- import com.getcapacitor.PermissionState;
14
6
  import com.getcapacitor.Plugin;
15
7
  import com.getcapacitor.PluginCall;
16
8
  import com.getcapacitor.PluginMethod;
17
9
  import com.getcapacitor.annotation.CapacitorPlugin;
18
10
  import com.getcapacitor.annotation.Permission;
19
- import com.getcapacitor.annotation.PermissionCallback;
20
-
21
- import java.util.Timer;
22
- import java.util.TimerTask;
23
11
 
24
- @RequiresApi(api = Build.VERSION_CODES.M)
25
- @CapacitorPlugin(
26
- name = "DoNotDisturb",
27
- permissions = {
28
- @Permission(alias = "notifications-policy", strings = {ACCESS_NOTIFICATION_POLICY})
29
- })
12
+ @CapacitorPlugin(name = "DoNotDisturb", permissions = {
13
+ @Permission(alias = "notifications-policy", strings = { Manifest.permission.ACCESS_NOTIFICATION_POLICY })
14
+ })
30
15
  public class DoNotDisturbPlugin extends Plugin {
31
- private NotificationManager notificationManager = null;
32
16
 
33
- @PluginMethod(returnType = PluginMethod.RETURN_CALLBACK)
34
- public void monitor(PluginCall call) {
35
- call.setKeepAlive(true);
36
- JSObject ret = new JSObject();
37
- new Timer().scheduleAtFixedRate(new TimerTask() {
38
- @Override
39
- public void run() {
40
- try {
41
- ret.put(
42
- "doNotDisturb",
43
- Settings.Global.getInt(getActivity().getApplicationContext().getContentResolver(), "zen_mode") == 1
44
- );
45
- } catch (Settings.SettingNotFoundException e) {
46
- ret.put(
47
- "doNotDisturb",
48
- null);
49
- }
50
- call.resolve(ret);
51
- }
52
- }, 5000, 10000);
53
- }
17
+ private DoNotDisturb implementation;
54
18
 
55
- @PluginMethod(returnType = PluginMethod.RETURN_NONE)
56
- public void toggleDoNotDisturb(PluginCall call) {
57
- this.notificationManager = (NotificationManager) getActivity().getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
58
- // Check if the notification policy access has been granted for the app.
59
- if (!notificationManager.isNotificationPolicyAccessGranted()) {
60
- requestPermissionForAlias("notifications-policy", call, "doNotDisturbPermsCallback");
61
-
62
- } else {
63
- ToggleDoNotDisturb(call);
64
- }
19
+ @Override
20
+ public void load() {
21
+ implementation = new DoNotDisturb(getContext());
22
+ implementation.startListening(() -> {
23
+ JSObject ret = new JSObject();
24
+ ret.put("enabled", implementation.isEnabled());
25
+ notifyListeners("monitor", ret);
26
+ });
65
27
  }
66
28
 
67
- @PermissionCallback
68
- private void doNotDisturbPermsCallback(PluginCall call) {
69
- if (getPermissionState("notifications-policy") == PermissionState.GRANTED) {
70
- ToggleDoNotDisturb(call);
71
- } else {
72
- call.reject("Permission is required to take a picture");
73
- }
29
+ @PluginMethod
30
+ public void monitor(PluginCall call) {
31
+ JSObject ret = new JSObject();
32
+ ret.put("enabled", implementation.isEnabled());
33
+ call.resolve(ret);
74
34
  }
75
35
 
76
- private void ToggleDoNotDisturb(PluginCall call) {
77
- if (notificationManager.getCurrentInterruptionFilter() == NotificationManager.INTERRUPTION_FILTER_ALL) {
78
- notificationManager.setInterruptionFilter(NotificationManager.INTERRUPTION_FILTER_NONE);
79
- } else {
80
- notificationManager.setInterruptionFilter(NotificationManager.INTERRUPTION_FILTER_ALL);
36
+ @Override
37
+ protected void handleOnDestroy() {
38
+ if (implementation != null) {
39
+ implementation.stopListening();
81
40
  }
82
- call.resolve();
83
41
  }
84
42
  }
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <resources>
3
+ <string name="service_name">DND Service</string>
4
+ </resources>
@@ -1,7 +1,5 @@
1
- export interface DoNotDisturbState {
2
- doNotDisturb: boolean;
3
- }
4
1
  export interface DoNotDisturbPlugin {
5
- monitor(callback: (result: DoNotDisturbState) => void): Promise<void>;
6
- toggleDoNotDisturb(): Promise<void>;
2
+ monitor(): Promise<{
3
+ enabled: boolean;
4
+ }>;
7
5
  }
package/dist/esm/index.js CHANGED
@@ -1,7 +1,8 @@
1
- import { registerPlugin } from '@capacitor/core';
2
- const DoNotDisturb = registerPlugin('DoNotDisturb', {
3
- web: () => import('./web').then(m => new m.DoNotDisturbWeb()),
1
+ import { registerPlugin as o } from "@capacitor/core";
2
+ const e = o("DoNotDisturb", {
3
+ web: () => import("../web-DRkBjitQ.mjs").then((t) => new t.DoNotDisturbWeb())
4
4
  });
5
- export * from './definitions';
6
- export { DoNotDisturb };
7
- //# sourceMappingURL=index.js.map
5
+ export {
6
+ e as DoNotDisturb
7
+ };
8
+ //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,YAAY,GAAG,cAAc,CAAqB,cAAc,EAAE;IACtE,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,eAAe,EAAE,CAAC;CAC9D,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { DoNotDisturbPlugin } from './definitions';\n\nconst DoNotDisturb = registerPlugin<DoNotDisturbPlugin>('DoNotDisturb', {\n web: () => import('./web').then(m => new m.DoNotDisturbWeb()),\n});\n\nexport * from './definitions';\nexport { DoNotDisturb };\n"]}
1
+ {"version":3,"file":"index.js","sources":["../../src/index.ts"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { DoNotDisturbPlugin } from './definitions';\n\nconst DoNotDisturb = registerPlugin<DoNotDisturbPlugin>('DoNotDisturb', {\n web: () => import('./web').then(m => new m.DoNotDisturbWeb()),\n});\n\nexport * from './definitions';\nexport { DoNotDisturb };\n"],"names":["DoNotDisturb","registerPlugin","m"],"mappings":";AAIM,MAAAA,IAAeC,EAAmC,gBAAgB;AAAA,EACtE,KAAK,MAAM,OAAO,qBAAO,EAAE,KAAK,CAAKC,MAAA,IAAIA,EAAE,gBAAiB,CAAA;AAC9D,CAAC;"}
package/dist/esm/web.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { WebPlugin } from '@capacitor/core';
2
- import type { DoNotDisturbPlugin, DoNotDisturbState } from './definitions';
1
+ import { WebPlugin } from "@capacitor/core";
2
+ import type { DoNotDisturbPlugin } from "./definitions";
3
3
  export declare class DoNotDisturbWeb extends WebPlugin implements DoNotDisturbPlugin {
4
- private currentState;
5
- monitor(callback: (result: DoNotDisturbState) => void): Promise<void>;
6
- toggleDoNotDisturb(): Promise<void>;
4
+ monitor(): Promise<{
5
+ enabled: boolean;
6
+ }>;
7
7
  }
@@ -1,32 +1,2 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var core = require('@capacitor/core');
6
-
7
- const DoNotDisturb = core.registerPlugin('DoNotDisturb', {
8
- web: () => Promise.resolve().then(function () { return web; }).then(m => new m.DoNotDisturbWeb()),
9
- });
10
-
11
- class DoNotDisturbWeb extends core.WebPlugin {
12
- constructor() {
13
- super(...arguments);
14
- this.currentState = { doNotDisturb: false };
15
- }
16
- monitor(callback) {
17
- callback(this.currentState);
18
- return Promise.resolve();
19
- }
20
- toggleDoNotDisturb() {
21
- Object.assign(this.currentState, { doNotDisturb: !this.currentState.doNotDisturb });
22
- return Promise.resolve();
23
- }
24
- }
25
-
26
- var web = /*#__PURE__*/Object.freeze({
27
- __proto__: null,
28
- DoNotDisturbWeb: DoNotDisturbWeb
29
- });
30
-
31
- exports.DoNotDisturb = DoNotDisturb;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@capacitor/core"),o=t.registerPlugin("DoNotDisturb",{web:()=>Promise.resolve().then(()=>require("./web-BMdZ0HQI.js")).then(e=>new e.DoNotDisturbWeb)});exports.DoNotDisturb=o;
32
2
  //# sourceMappingURL=plugin.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst DoNotDisturb = registerPlugin('DoNotDisturb', {\n web: () => import('./web').then(m => new m.DoNotDisturbWeb()),\n});\nexport * from './definitions';\nexport { DoNotDisturb };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class DoNotDisturbWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.currentState = { doNotDisturb: false };\n }\n monitor(callback) {\n callback(this.currentState);\n return Promise.resolve();\n }\n toggleDoNotDisturb() {\n Object.assign(this.currentState, { doNotDisturb: !this.currentState.doNotDisturb });\n return Promise.resolve();\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;;;AACK,MAAC,YAAY,GAAGA,mBAAc,CAAC,cAAc,EAAE;AACpD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,eAAe,EAAE,CAAC;AACjE,CAAC;;ACFM,MAAM,eAAe,SAASC,cAAS,CAAC;AAC/C,IAAI,WAAW,GAAG;AAClB,QAAQ,KAAK,CAAC,GAAG,SAAS,CAAC,CAAC;AAC5B,QAAQ,IAAI,CAAC,YAAY,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC;AACpD,KAAK;AACL,IAAI,OAAO,CAAC,QAAQ,EAAE;AACtB,QAAQ,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;AACpC,QAAQ,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;AACjC,KAAK;AACL,IAAI,kBAAkB,GAAG;AACzB,QAAQ,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE,YAAY,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,YAAY,EAAE,CAAC,CAAC;AAC5F,QAAQ,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;AACjC,KAAK;AACL;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.cjs.js","sources":["../src/index.ts"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { DoNotDisturbPlugin } from './definitions';\n\nconst DoNotDisturb = registerPlugin<DoNotDisturbPlugin>('DoNotDisturb', {\n web: () => import('./web').then(m => new m.DoNotDisturbWeb()),\n});\n\nexport * from './definitions';\nexport { DoNotDisturb };\n"],"names":["DoNotDisturb","registerPlugin","m"],"mappings":"mHAIMA,EAAeC,iBAAmC,eAAgB,CACtE,IAAK,IAAM,QAAO,QAAA,EAAA,KAAA,IAAA,QAAA,mBAAO,GAAE,KAAUC,GAAA,IAAIA,EAAE,eAAiB,CAC9D,CAAC"}
package/dist/plugin.js CHANGED
@@ -1,35 +1,2 @@
1
- var capacitorDoNotDisturb = (function (exports, core) {
2
- 'use strict';
3
-
4
- const DoNotDisturb = core.registerPlugin('DoNotDisturb', {
5
- web: () => Promise.resolve().then(function () { return web; }).then(m => new m.DoNotDisturbWeb()),
6
- });
7
-
8
- class DoNotDisturbWeb extends core.WebPlugin {
9
- constructor() {
10
- super(...arguments);
11
- this.currentState = { doNotDisturb: false };
12
- }
13
- monitor(callback) {
14
- callback(this.currentState);
15
- return Promise.resolve();
16
- }
17
- toggleDoNotDisturb() {
18
- Object.assign(this.currentState, { doNotDisturb: !this.currentState.doNotDisturb });
19
- return Promise.resolve();
20
- }
21
- }
22
-
23
- var web = /*#__PURE__*/Object.freeze({
24
- __proto__: null,
25
- DoNotDisturbWeb: DoNotDisturbWeb
26
- });
27
-
28
- exports.DoNotDisturb = DoNotDisturb;
29
-
30
- Object.defineProperty(exports, '__esModule', { value: true });
31
-
32
- return exports;
33
-
34
- })({}, capacitorExports);
1
+ var capacitorDoNotDisturb=function(t,e){"use strict";const r=e.registerPlugin("DoNotDisturb",{web:()=>Promise.resolve().then(()=>i).then(o=>new o.DoNotDisturbWeb)});class n extends e.WebPlugin{async monitor(){return{enabled:!1}}}const i=Object.freeze(Object.defineProperty({__proto__:null,DoNotDisturbWeb:n},Symbol.toStringTag,{value:"Module"}));return t.DoNotDisturb=r,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),t}({},capacitorExports);
35
2
  //# sourceMappingURL=plugin.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst DoNotDisturb = registerPlugin('DoNotDisturb', {\n web: () => import('./web').then(m => new m.DoNotDisturbWeb()),\n});\nexport * from './definitions';\nexport { DoNotDisturb };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class DoNotDisturbWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.currentState = { doNotDisturb: false };\n }\n monitor(callback) {\n callback(this.currentState);\n return Promise.resolve();\n }\n toggleDoNotDisturb() {\n Object.assign(this.currentState, { doNotDisturb: !this.currentState.doNotDisturb });\n return Promise.resolve();\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,YAAY,GAAGA,mBAAc,CAAC,cAAc,EAAE;IACpD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,eAAe,EAAE,CAAC;IACjE,CAAC;;ICFM,MAAM,eAAe,SAASC,cAAS,CAAC;IAC/C,IAAI,WAAW,GAAG;IAClB,QAAQ,KAAK,CAAC,GAAG,SAAS,CAAC,CAAC;IAC5B,QAAQ,IAAI,CAAC,YAAY,GAAG,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC;IACpD,KAAK;IACL,IAAI,OAAO,CAAC,QAAQ,EAAE;IACtB,QAAQ,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACpC,QAAQ,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IACjC,KAAK;IACL,IAAI,kBAAkB,GAAG;IACzB,QAAQ,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE,YAAY,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,YAAY,EAAE,CAAC,CAAC;IAC5F,QAAQ,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IACjC,KAAK;IACL;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.js","sources":["../src/index.ts","../src/web.ts"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { DoNotDisturbPlugin } from './definitions';\n\nconst DoNotDisturb = registerPlugin<DoNotDisturbPlugin>('DoNotDisturb', {\n web: () => import('./web').then(m => new m.DoNotDisturbWeb()),\n});\n\nexport * from './definitions';\nexport { DoNotDisturb };\n","import { WebPlugin } from \"@capacitor/core\";\n\nimport type { DoNotDisturbPlugin } from \"./definitions\";\n\nexport class DoNotDisturbWeb extends WebPlugin implements DoNotDisturbPlugin {\n async monitor(): Promise<{ enabled: boolean }> {\n return { enabled: false };\n }\n}\n"],"names":["DoNotDisturb","registerPlugin","web","m","DoNotDisturbWeb","WebPlugin"],"mappings":"qDAIM,MAAAA,EAAeC,iBAAmC,eAAgB,CACtE,IAAK,IAAM,QAAA,QAAA,EAAA,KAAA,IAAAC,CAAA,EAAgB,KAAUC,GAAA,IAAIA,EAAE,eAAiB,CAC9D,CAAC,ECFM,MAAMC,UAAwBC,EAAAA,SAAwC,CAC3E,MAAM,SAAyC,CACtC,MAAA,CAAE,QAAS,EAAM,CAAA,CAE5B"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("@capacitor/core");class t extends e.WebPlugin{async monitor(){return{enabled:!1}}}exports.DoNotDisturbWeb=t;
2
+ //# sourceMappingURL=web-BMdZ0HQI.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web-BMdZ0HQI.js","sources":["../src/web.ts"],"sourcesContent":["import { WebPlugin } from \"@capacitor/core\";\n\nimport type { DoNotDisturbPlugin } from \"./definitions\";\n\nexport class DoNotDisturbWeb extends WebPlugin implements DoNotDisturbPlugin {\n async monitor(): Promise<{ enabled: boolean }> {\n return { enabled: false };\n }\n}\n"],"names":["DoNotDisturbWeb","WebPlugin"],"mappings":"mHAIO,MAAMA,UAAwBC,EAAAA,SAAwC,CAC3E,MAAM,SAAyC,CACtC,MAAA,CAAE,QAAS,EAAM,CAAA,CAE5B"}
@@ -0,0 +1,10 @@
1
+ import { WebPlugin as e } from "@capacitor/core";
2
+ class t extends e {
3
+ async monitor() {
4
+ return { enabled: !1 };
5
+ }
6
+ }
7
+ export {
8
+ t as DoNotDisturbWeb
9
+ };
10
+ //# sourceMappingURL=web-DRkBjitQ.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web-DRkBjitQ.mjs","sources":["../src/web.ts"],"sourcesContent":["import { WebPlugin } from \"@capacitor/core\";\n\nimport type { DoNotDisturbPlugin } from \"./definitions\";\n\nexport class DoNotDisturbWeb extends WebPlugin implements DoNotDisturbPlugin {\n async monitor(): Promise<{ enabled: boolean }> {\n return { enabled: false };\n }\n}\n"],"names":["DoNotDisturbWeb","WebPlugin"],"mappings":";AAIO,MAAMA,UAAwBC,EAAwC;AAAA,EAC3E,MAAM,UAAyC;AACtC,WAAA,EAAE,SAAS,GAAM;AAAA,EAAA;AAE5B;"}
@@ -1,8 +1,28 @@
1
1
  import Foundation
2
2
 
3
3
  @objc public class DoNotDisturb: NSObject {
4
- @objc public func echo(_ value: String) -> String {
5
- print(value)
6
- return value
4
+ private var callback: (() -> Void)?
5
+ private var timer: Timer?
6
+ private var lastState: Bool = false
7
+
8
+ @objc public func isEnabled() -> Bool {
9
+ return false
10
+ }
11
+
12
+ @objc public func startListening(callback: @escaping () -> Void) {
13
+ self.callback = callback
14
+ lastState = isEnabled()
15
+ timer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { _ in
16
+ let currentState = self.isEnabled()
17
+ if currentState != self.lastState {
18
+ self.lastState = currentState
19
+ callback()
20
+ }
21
+ }
22
+ }
23
+
24
+ @objc public func stopListening() {
25
+ timer?.invalidate()
26
+ timer = nil
7
27
  }
8
28
  }
@@ -1,18 +1,25 @@
1
1
  import Foundation
2
2
  import Capacitor
3
3
 
4
- /**
5
- * Please read the Capacitor iOS Plugin Development Guide
6
- * here: https://capacitorjs.com/docs/plugins/ios
7
- */
8
4
  @objc(DoNotDisturbPlugin)
9
5
  public class DoNotDisturbPlugin: CAPPlugin {
10
6
  private let implementation = DoNotDisturb()
11
7
 
12
- @objc func echo(_ call: CAPPluginCall) {
13
- let value = call.getString("value") ?? ""
8
+ public override func load() {
9
+ implementation.startListening {
10
+ self.notifyListeners("monitor", data: [
11
+ "enabled": self.implementation.isEnabled()
12
+ ])
13
+ }
14
+ }
15
+
16
+ @objc func monitor(_ call: CAPPluginCall) {
14
17
  call.resolve([
15
- "value": implementation.echo(value)
18
+ "enabled": implementation.isEnabled()
16
19
  ])
17
20
  }
21
+
22
+ deinit {
23
+ implementation.stopListening()
24
+ }
18
25
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gachlab/capacitor-dnd-plugin",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "description": "A plugin to set and monitor the Do Not Disturb state",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -35,32 +35,33 @@
35
35
  "lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
36
36
  "fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
37
37
  "eslint": "eslint . --ext ts",
38
- "prettier": "prettier \"**/*.{css,html,ts,js,java}\"",
38
+ "prettier": "prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
39
39
  "swiftlint": "node-swiftlint",
40
40
  "docgen": "docgen --api DoNotDisturbPlugin --output-readme README.md --output-json dist/docs.json",
41
- "build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.js",
41
+ "build": "npm run clean && npm run docgen && vite build && npm run build:types",
42
+ "build:types": "tsc --emitDeclarationOnly",
42
43
  "clean": "rimraf ./dist",
43
- "watch": "tsc --watch",
44
+ "watch": "vite build --watch",
44
45
  "prepublishOnly": "npm run build"
45
46
  },
46
47
  "devDependencies": {
47
- "@capacitor/android": "^5.0.0",
48
- "@capacitor/core": "^5.0.0",
49
- "@capacitor/docgen": "^0.0.18",
50
- "@capacitor/ios": "^5.0.0",
51
- "@ionic/eslint-config": "^0.3.0",
52
- "@ionic/prettier-config": "^1.0.1",
53
- "@ionic/swiftlint-config": "^1.1.2",
54
- "eslint": "^7.11.0",
55
- "prettier": "~2.3.0",
56
- "prettier-plugin-java": "~1.0.2",
57
- "rimraf": "^3.0.2",
58
- "rollup": "^2.32.0",
59
- "swiftlint": "^1.0.1",
60
- "typescript": "~4.1.5"
48
+ "@capacitor/android": "7.4.2",
49
+ "@capacitor/core": "7.4.2",
50
+ "@capacitor/docgen": "^0.3.0",
51
+ "@capacitor/ios": "7.4.2",
52
+ "@ionic/eslint-config": "^0.4.0",
53
+ "@ionic/prettier-config": "^4.0.0",
54
+ "@ionic/swiftlint-config": "^2.0.0",
55
+ "eslint": "^8.57.0",
56
+ "prettier": "^3.4.2",
57
+ "prettier-plugin-java": "^2.6.6",
58
+ "rimraf": "^6.0.1",
59
+ "swiftlint": "^2.0.0",
60
+ "typescript": "~5.3.3",
61
+ "vite": "^5.0.0"
61
62
  },
62
63
  "peerDependencies": {
63
- "@capacitor/core": "^5.0.0"
64
+ "@capacitor/core": ">=7.4.2"
64
65
  },
65
66
  "prettier": "@ionic/prettier-config",
66
67
  "swiftlint": "@ionic/swiftlint-config",
package/dist/docs.json DELETED
@@ -1,60 +0,0 @@
1
- {
2
- "api": {
3
- "name": "DoNotDisturbPlugin",
4
- "slug": "donotdisturbplugin",
5
- "docs": "",
6
- "tags": [],
7
- "methods": [
8
- {
9
- "name": "monitor",
10
- "signature": "(callback: (result: DoNotDisturbState) => void) => Promise<void>",
11
- "parameters": [
12
- {
13
- "name": "callback",
14
- "docs": "",
15
- "type": "(result: DoNotDisturbState) => void"
16
- }
17
- ],
18
- "returns": "Promise<void>",
19
- "tags": [],
20
- "docs": "",
21
- "complexTypes": [
22
- "DoNotDisturbState"
23
- ],
24
- "slug": "monitor"
25
- },
26
- {
27
- "name": "toggleDoNotDisturb",
28
- "signature": "() => Promise<void>",
29
- "parameters": [],
30
- "returns": "Promise<void>",
31
- "tags": [],
32
- "docs": "",
33
- "complexTypes": [],
34
- "slug": "toggledonotdisturb"
35
- }
36
- ],
37
- "properties": []
38
- },
39
- "interfaces": [
40
- {
41
- "name": "DoNotDisturbState",
42
- "slug": "donotdisturbstate",
43
- "docs": "",
44
- "tags": [],
45
- "methods": [],
46
- "properties": [
47
- {
48
- "name": "doNotDisturb",
49
- "tags": [],
50
- "docs": "",
51
- "complexTypes": [],
52
- "type": "boolean"
53
- }
54
- ]
55
- }
56
- ],
57
- "enums": [],
58
- "typeAliases": [],
59
- "pluginConfigs": []
60
- }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=definitions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface DoNotDisturbState {\n doNotDisturb: boolean\n}\n\nexport interface DoNotDisturbPlugin {\n monitor(callback: (result: DoNotDisturbState) => void): Promise<void>\n\n toggleDoNotDisturb(): Promise<void>\n}\n"]}
package/dist/esm/web.js DELETED
@@ -1,16 +0,0 @@
1
- import { WebPlugin } from '@capacitor/core';
2
- export class DoNotDisturbWeb extends WebPlugin {
3
- constructor() {
4
- super(...arguments);
5
- this.currentState = { doNotDisturb: false };
6
- }
7
- monitor(callback) {
8
- callback(this.currentState);
9
- return Promise.resolve();
10
- }
11
- toggleDoNotDisturb() {
12
- Object.assign(this.currentState, { doNotDisturb: !this.currentState.doNotDisturb });
13
- return Promise.resolve();
14
- }
15
- }
16
- //# sourceMappingURL=web.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,MAAM,OAAO,eAAgB,SAAQ,SAAS;IAA9C;;QACU,iBAAY,GAAsB,EAAE,YAAY,EAAE,KAAK,EAAE,CAAA;IAUnE,CAAC;IATC,OAAO,CAAC,QAA6C;QACnD,QAAQ,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;QAC3B,OAAO,OAAO,CAAC,OAAO,EAAE,CAAA;IAC1B,CAAC;IACD,kBAAkB;QAChB,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE,YAAY,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,YAAY,EAAE,CAAC,CAAA;QACnF,OAAO,OAAO,CAAC,OAAO,EAAE,CAAA;IAC1B,CAAC;CAEF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type { DoNotDisturbPlugin, DoNotDisturbState } from './definitions';\n\nexport class DoNotDisturbWeb extends WebPlugin implements DoNotDisturbPlugin {\n private currentState: DoNotDisturbState = { doNotDisturb: false }\n monitor(callback: (result: DoNotDisturbState) => void): Promise<void> {\n callback(this.currentState)\n return Promise.resolve()\n }\n toggleDoNotDisturb(): Promise<void> {\n Object.assign(this.currentState, { doNotDisturb: !this.currentState.doNotDisturb })\n return Promise.resolve()\n }\n\n}\n"]}