@etsoo/appscript 1.2.50 → 1.2.51

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.
@@ -3,11 +3,6 @@ import { IBridgeHost } from './IBridgeHost';
3
3
  * Bridge utils
4
4
  */
5
5
  export declare namespace BridgeUtils {
6
- /**
7
- * Is electron client
8
- * @returns Result
9
- */
10
- function isElectronClient(): boolean;
11
6
  /**
12
7
  * Bridge host
13
8
  */
@@ -1,41 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.BridgeUtils = void 0;
4
+ const FlutterHost_1 = require("./FlutterHost");
4
5
  /**
5
6
  * Bridge utils
6
7
  */
7
8
  var BridgeUtils;
8
9
  (function (BridgeUtils) {
9
- /**
10
- * Is electron client
11
- * @returns Result
12
- */
13
- function isElectronClient() {
14
- // Renderer process
15
- if (typeof window !== 'undefined' &&
16
- typeof window.process === 'object' &&
17
- window.process.type === 'renderer') {
18
- return true;
19
- }
20
- // Main process
21
- if (typeof process !== 'undefined' &&
22
- typeof process.versions === 'object' &&
23
- !!process.versions.electron) {
24
- return true;
25
- }
26
- // Detect the user agent when the `nodeIntegration` option is set to true
27
- if (typeof navigator === 'object' &&
28
- typeof navigator.userAgent === 'string' &&
29
- navigator.userAgent.indexOf('Electron') >= 0) {
30
- return true;
31
- }
32
- return false;
33
- }
34
- BridgeUtils.isElectronClient = isElectronClient;
10
+ var _a;
11
+ const g = globalThis;
35
12
  /**
36
13
  * Bridge host
37
14
  */
38
- BridgeUtils.host = isElectronClient()
39
- ? globalThis.electron
40
- : undefined;
15
+ BridgeUtils.host = typeof ((_a = g.flutter_inappwebview) === null || _a === void 0 ? void 0 : _a.callHandler) === 'function'
16
+ ? new FlutterHost_1.FlutterHost(g.flutter_inappwebview.callHandler)
17
+ : typeof g.electron === 'object'
18
+ ? g.electron
19
+ : undefined;
41
20
  })(BridgeUtils = exports.BridgeUtils || (exports.BridgeUtils = {}));
@@ -0,0 +1,21 @@
1
+ import { IBridgeHost } from './IBridgeHost';
2
+ /**
3
+ * Flutter JavaScript Host
4
+ * https://inappwebview.dev/docs/javascript/communication/
5
+ */
6
+ export declare class FlutterHost implements IBridgeHost {
7
+ callHandler: (name: string, ...args: unknown[]) => PromiseLike<{} | void>;
8
+ /**
9
+ * Start Url
10
+ */
11
+ private startUrl;
12
+ /**
13
+ * Constructor
14
+ * @param callHandler Call handler
15
+ */
16
+ constructor(callHandler: (name: string, ...args: unknown[]) => PromiseLike<{} | void>);
17
+ changeCulture(locale: string): void;
18
+ exit(): void;
19
+ getStartUrl(): string | null | undefined;
20
+ loadApp(name: string, startUrl?: string): void;
21
+ }
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FlutterHost = void 0;
4
+ /**
5
+ * Flutter JavaScript Host
6
+ * https://inappwebview.dev/docs/javascript/communication/
7
+ */
8
+ class FlutterHost {
9
+ /**
10
+ * Constructor
11
+ * @param callHandler Call handler
12
+ */
13
+ constructor(callHandler) {
14
+ this.callHandler = callHandler;
15
+ }
16
+ changeCulture(locale) {
17
+ this.callHandler('changeCulture', locale);
18
+ }
19
+ exit() {
20
+ this.callHandler('exit');
21
+ }
22
+ getStartUrl() {
23
+ return this.startUrl;
24
+ }
25
+ loadApp(name, startUrl) {
26
+ this.startUrl = startUrl;
27
+ this.callHandler('loadApp', name, startUrl);
28
+ }
29
+ }
30
+ exports.FlutterHost = FlutterHost;
@@ -3,11 +3,6 @@ import { IBridgeHost } from './IBridgeHost';
3
3
  * Bridge utils
4
4
  */
5
5
  export declare namespace BridgeUtils {
6
- /**
7
- * Is electron client
8
- * @returns Result
9
- */
10
- function isElectronClient(): boolean;
11
6
  /**
12
7
  * Bridge host
13
8
  */
@@ -1,38 +1,17 @@
1
+ import { FlutterHost } from './FlutterHost';
1
2
  /**
2
3
  * Bridge utils
3
4
  */
4
5
  export var BridgeUtils;
5
6
  (function (BridgeUtils) {
6
- /**
7
- * Is electron client
8
- * @returns Result
9
- */
10
- function isElectronClient() {
11
- // Renderer process
12
- if (typeof window !== 'undefined' &&
13
- typeof window.process === 'object' &&
14
- window.process.type === 'renderer') {
15
- return true;
16
- }
17
- // Main process
18
- if (typeof process !== 'undefined' &&
19
- typeof process.versions === 'object' &&
20
- !!process.versions.electron) {
21
- return true;
22
- }
23
- // Detect the user agent when the `nodeIntegration` option is set to true
24
- if (typeof navigator === 'object' &&
25
- typeof navigator.userAgent === 'string' &&
26
- navigator.userAgent.indexOf('Electron') >= 0) {
27
- return true;
28
- }
29
- return false;
30
- }
31
- BridgeUtils.isElectronClient = isElectronClient;
7
+ var _a;
8
+ const g = globalThis;
32
9
  /**
33
10
  * Bridge host
34
11
  */
35
- BridgeUtils.host = isElectronClient()
36
- ? globalThis.electron
37
- : undefined;
12
+ BridgeUtils.host = typeof ((_a = g.flutter_inappwebview) === null || _a === void 0 ? void 0 : _a.callHandler) === 'function'
13
+ ? new FlutterHost(g.flutter_inappwebview.callHandler)
14
+ : typeof g.electron === 'object'
15
+ ? g.electron
16
+ : undefined;
38
17
  })(BridgeUtils || (BridgeUtils = {}));
@@ -0,0 +1,21 @@
1
+ import { IBridgeHost } from './IBridgeHost';
2
+ /**
3
+ * Flutter JavaScript Host
4
+ * https://inappwebview.dev/docs/javascript/communication/
5
+ */
6
+ export declare class FlutterHost implements IBridgeHost {
7
+ callHandler: (name: string, ...args: unknown[]) => PromiseLike<{} | void>;
8
+ /**
9
+ * Start Url
10
+ */
11
+ private startUrl;
12
+ /**
13
+ * Constructor
14
+ * @param callHandler Call handler
15
+ */
16
+ constructor(callHandler: (name: string, ...args: unknown[]) => PromiseLike<{} | void>);
17
+ changeCulture(locale: string): void;
18
+ exit(): void;
19
+ getStartUrl(): string | null | undefined;
20
+ loadApp(name: string, startUrl?: string): void;
21
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Flutter JavaScript Host
3
+ * https://inappwebview.dev/docs/javascript/communication/
4
+ */
5
+ export class FlutterHost {
6
+ /**
7
+ * Constructor
8
+ * @param callHandler Call handler
9
+ */
10
+ constructor(callHandler) {
11
+ this.callHandler = callHandler;
12
+ }
13
+ changeCulture(locale) {
14
+ this.callHandler('changeCulture', locale);
15
+ }
16
+ exit() {
17
+ this.callHandler('exit');
18
+ }
19
+ getStartUrl() {
20
+ return this.startUrl;
21
+ }
22
+ loadApp(name, startUrl) {
23
+ this.startUrl = startUrl;
24
+ this.callHandler('loadApp', name, startUrl);
25
+ }
26
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/appscript",
3
- "version": "1.2.50",
3
+ "version": "1.2.51",
4
4
  "description": "Applications shared TypeScript framework",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -1,48 +1,19 @@
1
+ import { FlutterHost } from './FlutterHost';
1
2
  import { IBridgeHost } from './IBridgeHost';
2
3
 
3
4
  /**
4
5
  * Bridge utils
5
6
  */
6
7
  export namespace BridgeUtils {
7
- /**
8
- * Is electron client
9
- * @returns Result
10
- */
11
- export function isElectronClient() {
12
- // Renderer process
13
- if (
14
- typeof window !== 'undefined' &&
15
- typeof window.process === 'object' &&
16
- (window.process as any).type === 'renderer'
17
- ) {
18
- return true;
19
- }
20
-
21
- // Main process
22
- if (
23
- typeof process !== 'undefined' &&
24
- typeof process.versions === 'object' &&
25
- !!process.versions.electron
26
- ) {
27
- return true;
28
- }
29
-
30
- // Detect the user agent when the `nodeIntegration` option is set to true
31
- if (
32
- typeof navigator === 'object' &&
33
- typeof navigator.userAgent === 'string' &&
34
- navigator.userAgent.indexOf('Electron') >= 0
35
- ) {
36
- return true;
37
- }
38
-
39
- return false;
40
- }
8
+ const g: any = globalThis;
41
9
 
42
10
  /**
43
11
  * Bridge host
44
12
  */
45
- export const host = isElectronClient()
46
- ? ((globalThis as any).electron as IBridgeHost)
47
- : undefined;
13
+ export const host =
14
+ typeof g.flutter_inappwebview?.callHandler === 'function'
15
+ ? new FlutterHost(g.flutter_inappwebview.callHandler)
16
+ : typeof g.electron === 'object'
17
+ ? (g.electron as IBridgeHost)
18
+ : undefined;
48
19
  }
@@ -0,0 +1,40 @@
1
+ import { IBridgeHost } from './IBridgeHost';
2
+
3
+ /**
4
+ * Flutter JavaScript Host
5
+ * https://inappwebview.dev/docs/javascript/communication/
6
+ */
7
+ export class FlutterHost implements IBridgeHost {
8
+ /**
9
+ * Start Url
10
+ */
11
+ private startUrl: string | null | undefined;
12
+
13
+ /**
14
+ * Constructor
15
+ * @param callHandler Call handler
16
+ */
17
+ constructor(
18
+ public callHandler: (
19
+ name: string,
20
+ ...args: unknown[]
21
+ ) => PromiseLike<{} | void>
22
+ ) {}
23
+
24
+ changeCulture(locale: string): void {
25
+ this.callHandler('changeCulture', locale);
26
+ }
27
+
28
+ exit(): void {
29
+ this.callHandler('exit');
30
+ }
31
+
32
+ getStartUrl(): string | null | undefined {
33
+ return this.startUrl;
34
+ }
35
+
36
+ loadApp(name: string, startUrl?: string): void {
37
+ this.startUrl = startUrl;
38
+ this.callHandler('loadApp', name, startUrl);
39
+ }
40
+ }