scriptable-testlab
Version:
A lightweight, efficient tool designed to manage and update scripts for Scriptable.
215 lines • 5.73 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
var preferences_exports = {};
__export(preferences_exports, {
DEFAULT_PREFERENCES: () => DEFAULT_PREFERENCES,
Preferences: () => Preferences
});
module.exports = __toCommonJS(preferences_exports);
var import_registry = require("./registry");
const DEFAULT_PREFERENCES = {
device: {
name: "iPhone Mock",
systemName: "iOS",
systemVersion: "16.0",
model: "iPhone",
screenSize: {
width: 390,
height: 844
},
screenResolution: {
width: 1170,
height: 2532
},
screenScale: 3,
screenBrightness: 1,
orientation: {
isInPortrait: true,
isInPortraitUpsideDown: false,
isInLandscapeLeft: false,
isInLandscapeRight: false,
isFaceUp: false,
isFaceDown: false
},
battery: {
level: 1,
isDischarging: false,
isCharging: false,
isFullyCharged: true
},
locale: {
preferredLanguages: ["en"],
locale: "en_US",
language: "en"
},
appearance: {
isUsingDarkAppearance: false
},
volume: 0.5
},
config: {
widgetFamily: "small",
runsInWidget: false,
runsInApp: true,
runsWithSiri: false,
runsInActionExtension: false,
runsInNotification: false,
runsFromHomeScreen: false,
runsInAccessoryWidget: false
},
script: {
name: "Test Script"
},
args: {
plainTexts: [],
fileURLs: [],
images: [],
queryParameters: {}
},
location: {
currentLocation: {
latitude: 0,
longitude: 0,
altitude: 0,
horizontalAccuracy: 5,
verticalAccuracy: 5
},
accuracy: "best",
simulatedDelay: 100
}
};
const _Preferences = class _Preferences {
constructor() {
__publicField(this, "current");
this.current = { ...DEFAULT_PREFERENCES };
}
static getInstance() {
if (!_Preferences.instance) {
_Preferences.instance = new _Preferences();
}
return _Preferences.instance;
}
/**
* Get current preferences
*/
get() {
return this.current;
}
/**
* Update preferences
* @param preferences Partial preferences to merge
*/
update(preferences) {
this.current = this.merge(this.current, preferences);
this.syncMocks();
}
/**
* Reset preferences to defaults
*/
reset() {
this.current = { ...DEFAULT_PREFERENCES };
this.syncMocks();
}
/**
* Load preferences from JSON string
*/
loadFromJSON(json) {
try {
const preferences = JSON.parse(json);
this.current = this.merge(DEFAULT_PREFERENCES, preferences);
this.syncMocks();
} catch (error) {
throw new Error(`Failed to parse preferences: ${error}`);
}
}
/**
* Save preferences to JSON string
*/
saveToJSON() {
return JSON.stringify(this.current, null, 2);
}
/**
* Get preferences for specific mock
*/
getMock(mockName) {
return this.current[mockName];
}
/**
* Update preferences for specific mock
*/
updateMock(mockName, preferences) {
this.current = {
...this.current,
[mockName]: {
...this.current[mockName],
...preferences
}
};
this.syncMocks();
}
/**
* Synchronize current preferences with all mocks
*/
syncMocks() {
if (import_registry.GlobalRegistry.has("Device")) {
import_registry.GlobalRegistry.get("Device").setState(this.current.device);
}
if (import_registry.GlobalRegistry.has("config")) {
import_registry.GlobalRegistry.get("config").setState(this.current.config);
}
if (import_registry.GlobalRegistry.has("Script")) {
import_registry.GlobalRegistry.get("Script").setState(this.current.script);
}
if (import_registry.GlobalRegistry.has("args")) {
import_registry.GlobalRegistry.get("args").setState(this.current.args);
}
if (import_registry.GlobalRegistry.has("Location")) {
import_registry.GlobalRegistry.get("Location").setState(this.current.location);
}
}
/**
* Deep merge preferences
*/
merge(target, source) {
const result = { ...target };
for (const key in source) {
if (source.hasOwnProperty(key)) {
const value = source[key];
if (value && typeof value === "object" && !Array.isArray(value)) {
result[key] = {
...result[key],
...value
};
} else {
result[key] = value;
}
}
}
return result;
}
};
__publicField(_Preferences, "instance");
let Preferences = _Preferences;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
DEFAULT_PREFERENCES,
Preferences
});
//# sourceMappingURL=preferences.js.map