desktopr 1.2.1 → 1.2.2

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.
@@ -2,3 +2,4 @@ export declare const APP_URL: string;
2
2
  export declare const APP_VERSION: string;
3
3
  export declare const COMAPNION_WINDOW_LABEL_PREFIX: string;
4
4
  export declare const READY_EVENT_NAME: string;
5
+ export declare const WINDOWS_LABELS_TRACKER_VARIABLE_NAME: string;
@@ -3,9 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.READY_EVENT_NAME = exports.COMAPNION_WINDOW_LABEL_PREFIX = exports.APP_VERSION = exports.APP_URL = void 0;
6
+ exports.WINDOWS_LABELS_TRACKER_VARIABLE_NAME = exports.READY_EVENT_NAME = exports.COMAPNION_WINDOW_LABEL_PREFIX = exports.APP_VERSION = exports.APP_URL = void 0;
7
7
  const bridge_constants_json_1 = __importDefault(require("./bridge.constants.json"));
8
8
  exports.APP_URL = bridge_constants_json_1.default.appUrl;
9
9
  exports.APP_VERSION = bridge_constants_json_1.default.appVersion;
10
10
  exports.COMAPNION_WINDOW_LABEL_PREFIX = bridge_constants_json_1.default.companionWindowLabelPrefix;
11
11
  exports.READY_EVENT_NAME = "dtrReady";
12
+ exports.WINDOWS_LABELS_TRACKER_VARIABLE_NAME = "open-windows-labels-tracker-rpkw6kjzxn8bfhj5u74q";
@@ -8,3 +8,6 @@ export declare const newWindow: (core: {
8
8
  fullscreen?: boolean;
9
9
  url?: string;
10
10
  }) => Promise<void>;
11
+ export declare const closeWindow: (core: {
12
+ invoke: DesktoprAPI["invoke"];
13
+ }, label: string) => Promise<void>;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.newWindow = exports.waitTauri = exports.tauriReadyCheck = void 0;
3
+ exports.closeWindow = exports.newWindow = exports.waitTauri = exports.tauriReadyCheck = void 0;
4
+ const sdk_1 = require("../../../sdk");
4
5
  const _constants_1 = require("../../../_constants");
5
6
  const utils_1 = require("suffro-lib/utils");
6
7
  const tauriReadyCheck = () => typeof window !== "undefined" &&
@@ -26,10 +27,36 @@ const newWindow = async (core, options) => {
26
27
  const randomWindowLabel = `w_${Math.random()
27
28
  .toString(36)
28
29
  .substring(2, 2 + 8)}`;
30
+ const labelToSet = (options?.label) ?? randomWindowLabel;
31
+ try {
32
+ const usedLabelsJSON = await sdk_1.Desktopr.globalVariables.get(_constants_1.WINDOWS_LABELS_TRACKER_VARIABLE_NAME);
33
+ let usedLabelsObj = await JSON.parse(usedLabelsJSON);
34
+ usedLabelsObj[labelToSet] = true;
35
+ const updatedUsedLabelsJSON = JSON.stringify(usedLabelsObj);
36
+ await sdk_1.Desktopr.globalVariables.set(_constants_1.WINDOWS_LABELS_TRACKER_VARIABLE_NAME, updatedUsedLabelsJSON);
37
+ }
38
+ catch (error) {
39
+ console.warn("Could not update used windows labels tracker");
40
+ }
29
41
  core.invoke("dtr_win_open", {
30
- label: options?.label ?? randomWindowLabel,
31
- fullscreen: options?.fullscreen || false,
32
- url: options?.url ?? "",
42
+ label: labelToSet,
43
+ fullscreen: (options?.fullscreen) || false,
44
+ url: (options?.url) ?? "",
33
45
  });
34
46
  };
35
47
  exports.newWindow = newWindow;
48
+ const closeWindow = async (core, label) => {
49
+ try {
50
+ const usedLabelsJSON = await sdk_1.Desktopr.globalVariables.get(_constants_1.WINDOWS_LABELS_TRACKER_VARIABLE_NAME);
51
+ let usedLabelsObj = await JSON.parse(usedLabelsJSON);
52
+ if (label)
53
+ delete usedLabelsObj[label];
54
+ const updatedUsedLabelsJSON = JSON.stringify(usedLabelsObj);
55
+ await sdk_1.Desktopr.globalVariables.set(_constants_1.WINDOWS_LABELS_TRACKER_VARIABLE_NAME, updatedUsedLabelsJSON);
56
+ }
57
+ catch (error) {
58
+ console.warn("Could not update used windows labels tracker");
59
+ }
60
+ core.invoke("dtr_win_close", { label });
61
+ };
62
+ exports.closeWindow = closeWindow;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.buildWindow = buildWindow;
4
4
  const _helpers_1 = require("../companion/_helpers");
5
+ const _helpers_2 = require("./_helpers");
5
6
  function buildWindow(core) {
6
7
  const randomWindowLabel = `w_${Math.random().toString(36).substring(2, 2 + 8)}`;
7
8
  return {
@@ -21,13 +22,9 @@ function buildWindow(core) {
21
22
  openFullscreen: options?.fullscreen
22
23
  });
23
24
  else
24
- core.invoke("dtr_win_open", {
25
- label: ((options?.label) ?? randomWindowLabel),
26
- fullscreen: ((options?.fullscreen) || false),
27
- url: ((options?.url) ?? "")
28
- });
25
+ (0, _helpers_2.newWindow)(core, options);
29
26
  },
30
- close: (label) => core.invoke("dtr_win_close", { label }),
27
+ close: (label) => (0, _helpers_2.closeWindow)(core, label),
31
28
  getInfo: (label) => core.invoke("dtr_win_get_info", { label }),
32
29
  state: {}
33
30
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "desktopr",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "Official JS/TS SDK for the Desktopr native bridge",
5
5
  "main": "dist-sdk/sdk/index.js",
6
6
  "types": "dist-sdk/sdk/index.d.ts",