@cap-kit/test-plugin 0.1.2 → 1.0.1
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 +63 -31
- package/android/build.gradle +1 -1
- package/android/src/main/java/io/capkit/test/Test.kt +61 -0
- package/android/src/main/java/io/capkit/test/TestConfig.kt +51 -0
- package/android/src/main/java/io/capkit/test/TestPlugin.kt +116 -0
- package/android/src/main/java/io/capkit/test/utils/Logger.kt +85 -0
- package/android/src/main/java/io/capkit/test/utils/TestUtils.kt +14 -0
- package/dist/docs.json +57 -21
- package/dist/esm/definitions.d.ts +137 -35
- package/dist/esm/definitions.js +23 -1
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/index.d.ts +4 -4
- package/dist/esm/index.js +4 -16
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/web.d.ts +16 -27
- package/dist/esm/web.js +25 -28
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +54 -39
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +54 -39
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/TestPlugin/Test.swift +40 -8
- package/ios/Sources/TestPlugin/TestConfig.swift +52 -9
- package/ios/Sources/TestPlugin/TestPlugin.swift +83 -34
- package/ios/Sources/TestPlugin/Utils/Logging.swift +57 -0
- package/ios/Sources/TestPlugin/Utils/TestUtils.swift +12 -0
- package/package.json +9 -9
- package/android/src/main/java/com/capkit/test/Logger.kt +0 -25
- package/android/src/main/java/com/capkit/test/Test.kt +0 -20
- package/android/src/main/java/com/capkit/test/TestConfig.kt +0 -16
- package/android/src/main/java/com/capkit/test/TestPlugin.kt +0 -60
- package/ios/Sources/TestPlugin/Logging.swift +0 -32
package/dist/plugin.cjs.js
CHANGED
|
@@ -2,6 +2,31 @@
|
|
|
2
2
|
|
|
3
3
|
var core = require('@capacitor/core');
|
|
4
4
|
|
|
5
|
+
/// <reference types="@capacitor/cli" />
|
|
6
|
+
/**
|
|
7
|
+
* Standardized error codes used by the Test plugin.
|
|
8
|
+
*
|
|
9
|
+
* These codes are returned as part of structured error objects
|
|
10
|
+
* and allow consumers to implement programmatic error handling.
|
|
11
|
+
*
|
|
12
|
+
* Note:
|
|
13
|
+
* On iOS (Swift Package Manager), errors are returned as data
|
|
14
|
+
* objects rather than rejected Promises.
|
|
15
|
+
*
|
|
16
|
+
* @since 1.0.0
|
|
17
|
+
*/
|
|
18
|
+
exports.TestErrorCode = void 0;
|
|
19
|
+
(function (TestErrorCode) {
|
|
20
|
+
/** The device does not have the requested hardware. */
|
|
21
|
+
TestErrorCode["UNAVAILABLE"] = "UNAVAILABLE";
|
|
22
|
+
/** The user denied the permission or the feature is disabled in settings. */
|
|
23
|
+
TestErrorCode["PERMISSION_DENIED"] = "PERMISSION_DENIED";
|
|
24
|
+
/** The test plugin failed to initialize (e.g., runtime error or Looper failure). */
|
|
25
|
+
TestErrorCode["INIT_FAILED"] = "INIT_FAILED";
|
|
26
|
+
/** The requested test plugin type is not valid or not supported by the plugin. */
|
|
27
|
+
TestErrorCode["UNKNOWN_TYPE"] = "UNKNOWN_TYPE";
|
|
28
|
+
})(exports.TestErrorCode || (exports.TestErrorCode = {}));
|
|
29
|
+
|
|
5
30
|
/**
|
|
6
31
|
* @file index.ts
|
|
7
32
|
* This file exports the TestPlugin and registers it with Capacitor.
|
|
@@ -9,34 +34,29 @@ var core = require('@capacitor/core');
|
|
|
9
34
|
* across different platforms, including web.
|
|
10
35
|
*/
|
|
11
36
|
/**
|
|
12
|
-
* Test Capacitor plugin
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
37
|
+
* Main entry point for the Test Capacitor plugin.
|
|
38
|
+
*
|
|
39
|
+
* This file registers the plugin with Capacitor and exports
|
|
40
|
+
* both the runtime instance and the public TypeScript types.
|
|
16
41
|
*/
|
|
17
42
|
const Test = core.registerPlugin('Test', {
|
|
18
|
-
/**
|
|
19
|
-
* Dynamically imports the web implementation of the plugin.
|
|
20
|
-
* The `web` option provides a fallback for web environments,
|
|
21
|
-
* ensuring platform-specific implementations can be used seamlessly.
|
|
22
|
-
*
|
|
23
|
-
* @returns A promise resolving to the web implementation of the plugin.
|
|
24
|
-
*/
|
|
25
43
|
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.TestWeb()),
|
|
26
44
|
});
|
|
27
45
|
|
|
28
46
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
*
|
|
36
|
-
* This class extends the WebPlugin class and implements the TestPlugin interface.
|
|
37
|
-
* It provides a base implementation for web-based functionality of the plugin.
|
|
47
|
+
* Web implementation of the Test plugin.
|
|
48
|
+
*
|
|
49
|
+
* This implementation exists primarily to satisfy Capacitor's
|
|
50
|
+
* multi-platform contract and to allow usage in browser-based
|
|
51
|
+
* environments.
|
|
52
|
+
*
|
|
53
|
+
* Native-only features may be unavailable on Web.
|
|
38
54
|
*/
|
|
39
55
|
class TestWeb extends core.WebPlugin {
|
|
56
|
+
constructor() {
|
|
57
|
+
super();
|
|
58
|
+
}
|
|
59
|
+
// --- Echo Method ---
|
|
40
60
|
/**
|
|
41
61
|
* Echoes a value back for the web platform.
|
|
42
62
|
* This method is a basic implementation example, primarily for testing
|
|
@@ -44,14 +64,6 @@ class TestWeb extends core.WebPlugin {
|
|
|
44
64
|
*
|
|
45
65
|
* @param options - An object containing a `value` property to be echoed back.
|
|
46
66
|
* @returns A promise resolving to an object containing the echoed `value`.
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* ```typescript
|
|
50
|
-
* import { Test } from '@cap-kit/test-plugin';
|
|
51
|
-
*
|
|
52
|
-
* const result = await Test.echo({ value: 'Hello, World!' });
|
|
53
|
-
* console.log(result.value); // Output: 'Hello, World!'
|
|
54
|
-
* ```
|
|
55
67
|
*/
|
|
56
68
|
async echo(options) {
|
|
57
69
|
console.log('ECHO', options);
|
|
@@ -60,22 +72,25 @@ class TestWeb extends core.WebPlugin {
|
|
|
60
72
|
// from a global config object if your app exposes one.
|
|
61
73
|
return options;
|
|
62
74
|
}
|
|
75
|
+
// --- App Settings ---
|
|
63
76
|
/**
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* @returns Promise that resolves with the plugin version
|
|
67
|
-
* @throws Error if getting the version fails
|
|
77
|
+
* Opens the app settings page.
|
|
78
|
+
* On Web, this is not applicable.
|
|
68
79
|
*
|
|
69
|
-
* @
|
|
70
|
-
|
|
71
|
-
|
|
80
|
+
* @returns A promise that resolves when the operation is complete.
|
|
81
|
+
*/
|
|
82
|
+
async openAppSettings() {
|
|
83
|
+
console.warn('Test: openAppSettings is not available on Web.');
|
|
84
|
+
return this.unimplemented('Not implemented on Web.');
|
|
85
|
+
}
|
|
86
|
+
// --- Plugin Info ---
|
|
87
|
+
/**
|
|
88
|
+
* Returns the plugin version.
|
|
72
89
|
*
|
|
73
|
-
*
|
|
74
|
-
* console.log(version.version); // Output: 'web'
|
|
75
|
-
* ```
|
|
90
|
+
* @returns The current plugin version.
|
|
76
91
|
*/
|
|
77
92
|
async getPluginVersion() {
|
|
78
|
-
return { version: 'web' };
|
|
93
|
+
return { version: 'web-1.0.0' };
|
|
79
94
|
}
|
|
80
95
|
}
|
|
81
96
|
|
package/dist/plugin.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["/// <reference types=\"@capacitor/cli\" />\n/**\n * Standardized error codes used by the Test plugin.\n *\n * These codes are returned as part of structured error objects\n * and allow consumers to implement programmatic error handling.\n *\n * Note:\n * On iOS (Swift Package Manager), errors are returned as data\n * objects rather than rejected Promises.\n *\n * @since 1.0.0\n */\nexport var TestErrorCode;\n(function (TestErrorCode) {\n /** The device does not have the requested hardware. */\n TestErrorCode[\"UNAVAILABLE\"] = \"UNAVAILABLE\";\n /** The user denied the permission or the feature is disabled in settings. */\n TestErrorCode[\"PERMISSION_DENIED\"] = \"PERMISSION_DENIED\";\n /** The test plugin failed to initialize (e.g., runtime error or Looper failure). */\n TestErrorCode[\"INIT_FAILED\"] = \"INIT_FAILED\";\n /** The requested test plugin type is not valid or not supported by the plugin. */\n TestErrorCode[\"UNKNOWN_TYPE\"] = \"UNKNOWN_TYPE\";\n})(TestErrorCode || (TestErrorCode = {}));\n//# sourceMappingURL=definitions.js.map","/**\n * @file index.ts\n * This file exports the TestPlugin and registers it with Capacitor.\n * It acts as the main entry point for accessing the plugin's functionality\n * across different platforms, including web.\n */\nimport { registerPlugin } from '@capacitor/core';\n/**\n * Main entry point for the Test Capacitor plugin.\n *\n * This file registers the plugin with Capacitor and exports\n * both the runtime instance and the public TypeScript types.\n */\nconst Test = registerPlugin('Test', {\n web: () => import('./web').then((m) => new m.TestWeb()),\n});\nexport * from './definitions';\nexport { Test };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\n/**\n * Web implementation of the Test plugin.\n *\n * This implementation exists primarily to satisfy Capacitor's\n * multi-platform contract and to allow usage in browser-based\n * environments.\n *\n * Native-only features may be unavailable on Web.\n */\nexport class TestWeb extends WebPlugin {\n constructor() {\n super();\n }\n // --- Echo Method ---\n /**\n * Echoes a value back for the web platform.\n * This method is a basic implementation example, primarily for testing\n * or validating communication with the plugin.\n *\n * @param options - An object containing a `value` property to be echoed back.\n * @returns A promise resolving to an object containing the echoed `value`.\n */\n async echo(options) {\n console.log('ECHO', options);\n // Note: On the web, reading 'capacitor.config.ts' requires specific build setups.\n // We pass the value through as-is for parity, or you can implement logic to read\n // from a global config object if your app exposes one.\n return options;\n }\n // --- App Settings ---\n /**\n * Opens the app settings page.\n * On Web, this is not applicable.\n *\n * @returns A promise that resolves when the operation is complete.\n */\n async openAppSettings() {\n console.warn('Test: openAppSettings is not available on Web.');\n return this.unimplemented('Not implemented on Web.');\n }\n // --- Plugin Info ---\n /**\n * Returns the plugin version.\n *\n * @returns The current plugin version.\n */\n async getPluginVersion() {\n return { version: 'web-1.0.0' };\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["TestErrorCode","registerPlugin","WebPlugin"],"mappings":";;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACWA;AACX,CAAC,UAAU,aAAa,EAAE;AAC1B;AACA,IAAI,aAAa,CAAC,aAAa,CAAC,GAAG,aAAa;AAChD;AACA,IAAI,aAAa,CAAC,mBAAmB,CAAC,GAAG,mBAAmB;AAC5D;AACA,IAAI,aAAa,CAAC,aAAa,CAAC,GAAG,aAAa;AAChD;AACA,IAAI,aAAa,CAAC,cAAc,CAAC,GAAG,cAAc;AAClD,CAAC,EAAEA,qBAAa,KAAKA,qBAAa,GAAG,EAAE,CAAC,CAAC;;ACvBzC;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACK,MAAC,IAAI,GAAGC,mBAAc,CAAC,MAAM,EAAE;AACpC,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;AAC3D,CAAC;;ACdD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,OAAO,SAASC,cAAS,CAAC;AACvC,IAAI,WAAW,GAAG;AAClB,QAAQ,KAAK,EAAE;AACf,IAAI;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,MAAM,IAAI,CAAC,OAAO,EAAE;AACxB,QAAQ,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;AACpC;AACA;AACA;AACA,QAAQ,OAAO,OAAO;AACtB,IAAI;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,MAAM,eAAe,GAAG;AAC5B,QAAQ,OAAO,CAAC,IAAI,CAAC,gDAAgD,CAAC;AACtE,QAAQ,OAAO,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;AAC5D,IAAI;AACJ;AACA;AACA;AACA;AACA;AACA;AACA,IAAI,MAAM,gBAAgB,GAAG;AAC7B,QAAQ,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE;AACvC,IAAI;AACJ;;;;;;;;;"}
|
package/dist/plugin.js
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
var capacitorTest = (function (exports, core) {
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
+
/// <reference types="@capacitor/cli" />
|
|
5
|
+
/**
|
|
6
|
+
* Standardized error codes used by the Test plugin.
|
|
7
|
+
*
|
|
8
|
+
* These codes are returned as part of structured error objects
|
|
9
|
+
* and allow consumers to implement programmatic error handling.
|
|
10
|
+
*
|
|
11
|
+
* Note:
|
|
12
|
+
* On iOS (Swift Package Manager), errors are returned as data
|
|
13
|
+
* objects rather than rejected Promises.
|
|
14
|
+
*
|
|
15
|
+
* @since 1.0.0
|
|
16
|
+
*/
|
|
17
|
+
exports.TestErrorCode = void 0;
|
|
18
|
+
(function (TestErrorCode) {
|
|
19
|
+
/** The device does not have the requested hardware. */
|
|
20
|
+
TestErrorCode["UNAVAILABLE"] = "UNAVAILABLE";
|
|
21
|
+
/** The user denied the permission or the feature is disabled in settings. */
|
|
22
|
+
TestErrorCode["PERMISSION_DENIED"] = "PERMISSION_DENIED";
|
|
23
|
+
/** The test plugin failed to initialize (e.g., runtime error or Looper failure). */
|
|
24
|
+
TestErrorCode["INIT_FAILED"] = "INIT_FAILED";
|
|
25
|
+
/** The requested test plugin type is not valid or not supported by the plugin. */
|
|
26
|
+
TestErrorCode["UNKNOWN_TYPE"] = "UNKNOWN_TYPE";
|
|
27
|
+
})(exports.TestErrorCode || (exports.TestErrorCode = {}));
|
|
28
|
+
|
|
4
29
|
/**
|
|
5
30
|
* @file index.ts
|
|
6
31
|
* This file exports the TestPlugin and registers it with Capacitor.
|
|
@@ -8,34 +33,29 @@ var capacitorTest = (function (exports, core) {
|
|
|
8
33
|
* across different platforms, including web.
|
|
9
34
|
*/
|
|
10
35
|
/**
|
|
11
|
-
* Test Capacitor plugin
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
36
|
+
* Main entry point for the Test Capacitor plugin.
|
|
37
|
+
*
|
|
38
|
+
* This file registers the plugin with Capacitor and exports
|
|
39
|
+
* both the runtime instance and the public TypeScript types.
|
|
15
40
|
*/
|
|
16
41
|
const Test = core.registerPlugin('Test', {
|
|
17
|
-
/**
|
|
18
|
-
* Dynamically imports the web implementation of the plugin.
|
|
19
|
-
* The `web` option provides a fallback for web environments,
|
|
20
|
-
* ensuring platform-specific implementations can be used seamlessly.
|
|
21
|
-
*
|
|
22
|
-
* @returns A promise resolving to the web implementation of the plugin.
|
|
23
|
-
*/
|
|
24
42
|
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.TestWeb()),
|
|
25
43
|
});
|
|
26
44
|
|
|
27
45
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
*
|
|
35
|
-
* This class extends the WebPlugin class and implements the TestPlugin interface.
|
|
36
|
-
* It provides a base implementation for web-based functionality of the plugin.
|
|
46
|
+
* Web implementation of the Test plugin.
|
|
47
|
+
*
|
|
48
|
+
* This implementation exists primarily to satisfy Capacitor's
|
|
49
|
+
* multi-platform contract and to allow usage in browser-based
|
|
50
|
+
* environments.
|
|
51
|
+
*
|
|
52
|
+
* Native-only features may be unavailable on Web.
|
|
37
53
|
*/
|
|
38
54
|
class TestWeb extends core.WebPlugin {
|
|
55
|
+
constructor() {
|
|
56
|
+
super();
|
|
57
|
+
}
|
|
58
|
+
// --- Echo Method ---
|
|
39
59
|
/**
|
|
40
60
|
* Echoes a value back for the web platform.
|
|
41
61
|
* This method is a basic implementation example, primarily for testing
|
|
@@ -43,14 +63,6 @@ var capacitorTest = (function (exports, core) {
|
|
|
43
63
|
*
|
|
44
64
|
* @param options - An object containing a `value` property to be echoed back.
|
|
45
65
|
* @returns A promise resolving to an object containing the echoed `value`.
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* ```typescript
|
|
49
|
-
* import { Test } from '@cap-kit/test-plugin';
|
|
50
|
-
*
|
|
51
|
-
* const result = await Test.echo({ value: 'Hello, World!' });
|
|
52
|
-
* console.log(result.value); // Output: 'Hello, World!'
|
|
53
|
-
* ```
|
|
54
66
|
*/
|
|
55
67
|
async echo(options) {
|
|
56
68
|
console.log('ECHO', options);
|
|
@@ -59,22 +71,25 @@ var capacitorTest = (function (exports, core) {
|
|
|
59
71
|
// from a global config object if your app exposes one.
|
|
60
72
|
return options;
|
|
61
73
|
}
|
|
74
|
+
// --- App Settings ---
|
|
62
75
|
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* @returns Promise that resolves with the plugin version
|
|
66
|
-
* @throws Error if getting the version fails
|
|
76
|
+
* Opens the app settings page.
|
|
77
|
+
* On Web, this is not applicable.
|
|
67
78
|
*
|
|
68
|
-
* @
|
|
69
|
-
|
|
70
|
-
|
|
79
|
+
* @returns A promise that resolves when the operation is complete.
|
|
80
|
+
*/
|
|
81
|
+
async openAppSettings() {
|
|
82
|
+
console.warn('Test: openAppSettings is not available on Web.');
|
|
83
|
+
return this.unimplemented('Not implemented on Web.');
|
|
84
|
+
}
|
|
85
|
+
// --- Plugin Info ---
|
|
86
|
+
/**
|
|
87
|
+
* Returns the plugin version.
|
|
71
88
|
*
|
|
72
|
-
*
|
|
73
|
-
* console.log(version.version); // Output: 'web'
|
|
74
|
-
* ```
|
|
89
|
+
* @returns The current plugin version.
|
|
75
90
|
*/
|
|
76
91
|
async getPluginVersion() {
|
|
77
|
-
return { version: 'web' };
|
|
92
|
+
return { version: 'web-1.0.0' };
|
|
78
93
|
}
|
|
79
94
|
}
|
|
80
95
|
|
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["/// <reference types=\"@capacitor/cli\" />\n/**\n * Standardized error codes used by the Test plugin.\n *\n * These codes are returned as part of structured error objects\n * and allow consumers to implement programmatic error handling.\n *\n * Note:\n * On iOS (Swift Package Manager), errors are returned as data\n * objects rather than rejected Promises.\n *\n * @since 1.0.0\n */\nexport var TestErrorCode;\n(function (TestErrorCode) {\n /** The device does not have the requested hardware. */\n TestErrorCode[\"UNAVAILABLE\"] = \"UNAVAILABLE\";\n /** The user denied the permission or the feature is disabled in settings. */\n TestErrorCode[\"PERMISSION_DENIED\"] = \"PERMISSION_DENIED\";\n /** The test plugin failed to initialize (e.g., runtime error or Looper failure). */\n TestErrorCode[\"INIT_FAILED\"] = \"INIT_FAILED\";\n /** The requested test plugin type is not valid or not supported by the plugin. */\n TestErrorCode[\"UNKNOWN_TYPE\"] = \"UNKNOWN_TYPE\";\n})(TestErrorCode || (TestErrorCode = {}));\n//# sourceMappingURL=definitions.js.map","/**\n * @file index.ts\n * This file exports the TestPlugin and registers it with Capacitor.\n * It acts as the main entry point for accessing the plugin's functionality\n * across different platforms, including web.\n */\nimport { registerPlugin } from '@capacitor/core';\n/**\n * Main entry point for the Test Capacitor plugin.\n *\n * This file registers the plugin with Capacitor and exports\n * both the runtime instance and the public TypeScript types.\n */\nconst Test = registerPlugin('Test', {\n web: () => import('./web').then((m) => new m.TestWeb()),\n});\nexport * from './definitions';\nexport { Test };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\n/**\n * Web implementation of the Test plugin.\n *\n * This implementation exists primarily to satisfy Capacitor's\n * multi-platform contract and to allow usage in browser-based\n * environments.\n *\n * Native-only features may be unavailable on Web.\n */\nexport class TestWeb extends WebPlugin {\n constructor() {\n super();\n }\n // --- Echo Method ---\n /**\n * Echoes a value back for the web platform.\n * This method is a basic implementation example, primarily for testing\n * or validating communication with the plugin.\n *\n * @param options - An object containing a `value` property to be echoed back.\n * @returns A promise resolving to an object containing the echoed `value`.\n */\n async echo(options) {\n console.log('ECHO', options);\n // Note: On the web, reading 'capacitor.config.ts' requires specific build setups.\n // We pass the value through as-is for parity, or you can implement logic to read\n // from a global config object if your app exposes one.\n return options;\n }\n // --- App Settings ---\n /**\n * Opens the app settings page.\n * On Web, this is not applicable.\n *\n * @returns A promise that resolves when the operation is complete.\n */\n async openAppSettings() {\n console.warn('Test: openAppSettings is not available on Web.');\n return this.unimplemented('Not implemented on Web.');\n }\n // --- Plugin Info ---\n /**\n * Returns the plugin version.\n *\n * @returns The current plugin version.\n */\n async getPluginVersion() {\n return { version: 'web-1.0.0' };\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["TestErrorCode","registerPlugin","WebPlugin"],"mappings":";;;IAAA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;AACWA;IACX,CAAC,UAAU,aAAa,EAAE;IAC1B;IACA,IAAI,aAAa,CAAC,aAAa,CAAC,GAAG,aAAa;IAChD;IACA,IAAI,aAAa,CAAC,mBAAmB,CAAC,GAAG,mBAAmB;IAC5D;IACA,IAAI,aAAa,CAAC,aAAa,CAAC,GAAG,aAAa;IAChD;IACA,IAAI,aAAa,CAAC,cAAc,CAAC,GAAG,cAAc;IAClD,CAAC,EAAEA,qBAAa,KAAKA,qBAAa,GAAG,EAAE,CAAC,CAAC;;ICvBzC;IACA;IACA;IACA;IACA;IACA;IAEA;IACA;IACA;IACA;IACA;IACA;AACK,UAAC,IAAI,GAAGC,mBAAc,CAAC,MAAM,EAAE;IACpC,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,OAAO,EAAE,CAAC;IAC3D,CAAC;;ICdD;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACO,MAAM,OAAO,SAASC,cAAS,CAAC;IACvC,IAAI,WAAW,GAAG;IAClB,QAAQ,KAAK,EAAE;IACf,IAAI;IACJ;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,IAAI,MAAM,IAAI,CAAC,OAAO,EAAE;IACxB,QAAQ,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;IACpC;IACA;IACA;IACA,QAAQ,OAAO,OAAO;IACtB,IAAI;IACJ;IACA;IACA;IACA;IACA;IACA;IACA;IACA,IAAI,MAAM,eAAe,GAAG;IAC5B,QAAQ,OAAO,CAAC,IAAI,CAAC,gDAAgD,CAAC;IACtE,QAAQ,OAAO,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;IAC5D,IAAI;IACJ;IACA;IACA;IACA;IACA;IACA;IACA,IAAI,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE;IACvC,IAAI;IACJ;;;;;;;;;;;;;;;"}
|
|
@@ -1,19 +1,51 @@
|
|
|
1
1
|
import Foundation
|
|
2
|
+
import Capacitor
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
Native implementation for the Test Capacitor plugin.
|
|
6
|
+
|
|
7
|
+
This class contains platform-specific logic only and MUST NOT:
|
|
8
|
+
- access CAPPluginCall
|
|
9
|
+
- interact directly with the Capacitor bridge
|
|
10
|
+
- depend on JavaScript concepts
|
|
11
|
+
|
|
12
|
+
The Capacitor plugin class is responsible for delegating work to this class.
|
|
7
13
|
*/
|
|
8
14
|
@objc public class Test: NSObject {
|
|
15
|
+
|
|
16
|
+
// Properties
|
|
17
|
+
private var config: TestConfig?
|
|
18
|
+
|
|
19
|
+
// Initializer
|
|
20
|
+
override init() {
|
|
21
|
+
super.init()
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// MARK: - Configuration
|
|
25
|
+
|
|
9
26
|
/**
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
27
|
+
Applies the plugin configuration.
|
|
28
|
+
|
|
29
|
+
This method should be called exactly once during plugin initialization.
|
|
30
|
+
Its responsibility is to translate configuration values into runtime
|
|
31
|
+
behavior (e.g. enabling verbose logging).
|
|
32
|
+
*/
|
|
33
|
+
func applyConfig(_ config: TestConfig) {
|
|
34
|
+
self.config = config
|
|
35
|
+
TestLogger.verbose = config.verboseLogging
|
|
36
|
+
TestLogger.debug("Configuration applied. Verbose logging enabled.")
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// MARK: - Echo Method
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
Returns the provided value unchanged.
|
|
43
|
+
|
|
44
|
+
This method represents a simple synchronous native operation
|
|
45
|
+
and is intentionally side-effect free.
|
|
14
46
|
*/
|
|
15
47
|
@objc public func echo(_ value: String) -> String {
|
|
16
|
-
|
|
48
|
+
TestLogger.debug("Echoing value:", value)
|
|
17
49
|
return value
|
|
18
50
|
}
|
|
19
51
|
}
|
|
@@ -1,29 +1,72 @@
|
|
|
1
1
|
import Foundation
|
|
2
|
+
import Capacitor
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
Plugin configuration container.
|
|
6
|
+
|
|
7
|
+
This struct is responsible for reading and exposing static configuration
|
|
8
|
+
values defined under the `Test` key in `capacitor.config.ts`.
|
|
9
|
+
|
|
10
|
+
Configuration is:
|
|
11
|
+
- read once during plugin initialization
|
|
12
|
+
- treated as immutable runtime input
|
|
13
|
+
- consumed only by native code (never by JavaScript)
|
|
6
14
|
*/
|
|
7
15
|
public struct TestConfig {
|
|
8
16
|
|
|
17
|
+
// MARK: - Configuration Keys
|
|
18
|
+
|
|
9
19
|
// Define configuration keys for consistency
|
|
10
20
|
private struct Keys {
|
|
21
|
+
static let verboseLogging = "verboseLogging"
|
|
11
22
|
static let customMessage = "customMessage"
|
|
12
23
|
}
|
|
13
24
|
|
|
25
|
+
// MARK: - Public Config Values
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
Enables verbose native logging.
|
|
29
|
+
|
|
30
|
+
When enabled, additional debug information is printed
|
|
31
|
+
to the Xcode console via the plugin logger.
|
|
32
|
+
|
|
33
|
+
Default: false
|
|
34
|
+
*/
|
|
35
|
+
public let verboseLogging: Bool
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
Custom message appended to echoed values.
|
|
39
|
+
|
|
40
|
+
This property exists primarily for demonstration purposes and
|
|
41
|
+
shows how to pass static configuration values from JavaScript
|
|
42
|
+
to native code.
|
|
43
|
+
|
|
44
|
+
Default: " (from config)"
|
|
45
|
+
*/
|
|
46
|
+
public let customMessage: String?
|
|
47
|
+
|
|
48
|
+
// MARK: - Private Defaults
|
|
49
|
+
|
|
14
50
|
// Default values
|
|
51
|
+
private let defaultVerboseLogging = false
|
|
15
52
|
private let defaultCustomMessage = " (from config)"
|
|
16
53
|
|
|
17
|
-
//
|
|
18
|
-
public var customMessage: String
|
|
54
|
+
// MARK: - Init
|
|
19
55
|
|
|
20
56
|
/**
|
|
21
|
-
|
|
57
|
+
Initializes the configuration by reading values from the Capacitor bridge.
|
|
58
|
+
|
|
59
|
+
- Parameter plugin: The CAPPlugin instance used to access typed configuration.
|
|
22
60
|
*/
|
|
23
|
-
init(
|
|
24
|
-
let config =
|
|
61
|
+
init(plugin: CAPPlugin) {
|
|
62
|
+
let config = plugin.getConfig()
|
|
63
|
+
|
|
64
|
+
// Bool
|
|
65
|
+
verboseLogging =
|
|
66
|
+
(config.value(forKey: Keys.verboseLogging) as? Bool) ?? defaultVerboseLogging
|
|
25
67
|
|
|
26
|
-
//
|
|
27
|
-
|
|
68
|
+
// String
|
|
69
|
+
customMessage =
|
|
70
|
+
(config.value(forKey: Keys.customMessage) as? String) ?? defaultCustomMessage
|
|
28
71
|
}
|
|
29
72
|
}
|
|
@@ -2,33 +2,22 @@ import Foundation
|
|
|
2
2
|
import Capacitor
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
|
|
6
|
-
*
|
|
7
|
-
* Documentation reference:
|
|
8
|
-
* https://capacitorjs.com/docs/plugins/ios
|
|
9
|
-
*/
|
|
5
|
+
Capacitor bridge for the Test plugin.
|
|
10
6
|
|
|
7
|
+
This class represents the boundary between JavaScript and native iOS code.
|
|
8
|
+
Responsibilities include:
|
|
9
|
+
- reading plugin configuration
|
|
10
|
+
- handling CAPPluginCall objects
|
|
11
|
+
- delegating logic to the native implementation
|
|
12
|
+
*/
|
|
11
13
|
@objc(TestPlugin)
|
|
12
14
|
public class TestPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
13
15
|
|
|
14
16
|
// Configuration instance
|
|
15
17
|
private var config: TestConfig?
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
*/
|
|
20
|
-
override public func load() {
|
|
21
|
-
log("Loading plugin")
|
|
22
|
-
self.config = TestConfig(
|
|
23
|
-
config: self.getConfig() as? [String: Any] ?? [:]
|
|
24
|
-
)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/// Plugin version (Dynamic read from the Bundle Info.plist)
|
|
28
|
-
private var pluginVersion: String {
|
|
29
|
-
let bundle = Bundle(for: type(of: self))
|
|
30
|
-
return bundle.infoDictionary?["CFBundleShortVersionString"] as? String ?? "0.0.1"
|
|
31
|
-
}
|
|
19
|
+
/// An instance of the implementation class that contains the plugin's core functionality.
|
|
20
|
+
private let implementation = Test()
|
|
32
21
|
|
|
33
22
|
/// The unique identifier for the plugin.
|
|
34
23
|
public let identifier = "TestPlugin"
|
|
@@ -37,26 +26,49 @@ public class TestPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
37
26
|
public let jsName = "Test"
|
|
38
27
|
|
|
39
28
|
/**
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
29
|
+
A list of methods exposed by this plugin. These methods can be called from the JavaScript side.
|
|
30
|
+
- `echo`: A method that accepts a string and returns the same string.
|
|
31
|
+
- `getPluginVersion`: A method that returns the version of the plugin.
|
|
32
|
+
- `openAppSettings`: A method that opens the app's settings page.
|
|
43
33
|
*/
|
|
44
34
|
public let pluginMethods: [CAPPluginMethod] = [
|
|
45
35
|
CAPPluginMethod(name: "echo", returnType: CAPPluginReturnPromise),
|
|
46
|
-
CAPPluginMethod(name: "getPluginVersion", returnType: CAPPluginReturnPromise)
|
|
36
|
+
CAPPluginMethod(name: "getPluginVersion", returnType: CAPPluginReturnPromise),
|
|
37
|
+
CAPPluginMethod(name: "openAppSettings", returnType: CAPPluginReturnPromise)
|
|
47
38
|
]
|
|
48
39
|
|
|
49
|
-
|
|
50
|
-
|
|
40
|
+
/**
|
|
41
|
+
Plugin lifecycle entry point.
|
|
42
|
+
|
|
43
|
+
Called once when the plugin is loaded by the Capacitor bridge.
|
|
44
|
+
This is the correct place to:
|
|
45
|
+
- read configuration values
|
|
46
|
+
- initialize native resources
|
|
47
|
+
- configure the implementation instance
|
|
48
|
+
*/
|
|
49
|
+
override public func load() {
|
|
50
|
+
// Initialize TestConfig with the correct type
|
|
51
|
+
let cfg = TestConfig(plugin: self)
|
|
52
|
+
self.config = cfg
|
|
53
|
+
implementation.applyConfig(cfg)
|
|
54
|
+
|
|
55
|
+
// Log if verbose logging is enabled
|
|
56
|
+
TestLogger.debug("Test plugin loaded with config:", cfg)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// MARK: - Echo
|
|
51
60
|
|
|
52
61
|
/**
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
62
|
+
Echoes a string back to JavaScript.
|
|
63
|
+
|
|
64
|
+
This method validates input, applies configuration-derived behavior,
|
|
65
|
+
and delegates the core logic to the native implementation.
|
|
56
66
|
*/
|
|
57
67
|
@objc func echo(_ call: CAPPluginCall) {
|
|
58
68
|
var value = call.getString("value", "")
|
|
59
|
-
|
|
69
|
+
|
|
70
|
+
// Log input only if verbose logging is enabled
|
|
71
|
+
TestLogger.debug("Echoing value:", value)
|
|
60
72
|
|
|
61
73
|
// Append the custom message from the configuration
|
|
62
74
|
if let configMessage = config?.customMessage {
|
|
@@ -68,10 +80,47 @@ public class TestPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
68
80
|
])
|
|
69
81
|
}
|
|
70
82
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
83
|
+
// MARK: - Version
|
|
84
|
+
|
|
85
|
+
/// Retrieves the plugin version from the bundle.
|
|
74
86
|
@objc func getPluginVersion(_ call: CAPPluginCall) {
|
|
75
|
-
|
|
87
|
+
let version = Bundle(for: type(of: self)).infoDictionary?["CFBundleShortVersionString"] as? String ?? "0.0.1"
|
|
88
|
+
call.resolve(["version": version])
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// MARK: - Settings
|
|
92
|
+
|
|
93
|
+
/// Opens the iOS Settings app specifically for this application.
|
|
94
|
+
@objc func openAppSettings(_ call: CAPPluginCall) {
|
|
95
|
+
DispatchQueue.main.async(execute: DispatchWorkItem {
|
|
96
|
+
guard let settingsUrl = URL(string: UIApplication.openSettingsURLString) else {
|
|
97
|
+
call.resolve([
|
|
98
|
+
"success": false,
|
|
99
|
+
"error": "Cannot open settings URL",
|
|
100
|
+
"code": "UNAVAILABLE"
|
|
101
|
+
])
|
|
102
|
+
return
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if UIApplication.shared.canOpenURL(settingsUrl) {
|
|
106
|
+
UIApplication.shared.open(settingsUrl, options: [:]) { success in
|
|
107
|
+
if success {
|
|
108
|
+
call.resolve()
|
|
109
|
+
} else {
|
|
110
|
+
call.resolve([
|
|
111
|
+
"success": false,
|
|
112
|
+
"error": "Failed to open settings",
|
|
113
|
+
"code": "UNAVAILABLE"
|
|
114
|
+
])
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
} else {
|
|
118
|
+
call.resolve([
|
|
119
|
+
"success": false,
|
|
120
|
+
"error": "Cannot open settings URL",
|
|
121
|
+
"code": "UNAVAILABLE"
|
|
122
|
+
])
|
|
123
|
+
}
|
|
124
|
+
})
|
|
76
125
|
}
|
|
77
126
|
}
|