@midscene/ios 0.30.6-beta-20251021121032.0 → 0.30.6-beta-20251022061949.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/dist/es/bin.mjs CHANGED
@@ -11540,6 +11540,24 @@ class PlaygroundServer {
11540
11540
  writeFileSync(tmpFile, context);
11541
11541
  return tmpFile;
11542
11542
  }
11543
+ async recreateAgent() {
11544
+ if (!this.pageFactory || !this.agentFactory) return void console.warn('Cannot recreate agent: factory functions not provided. Agent recreation is only available when using factory mode.');
11545
+ console.log('Recreating agent to cancel current task...');
11546
+ try {
11547
+ if (this.agent && 'function' == typeof this.agent.destroy) await this.agent.destroy();
11548
+ if (this.page && 'function' == typeof this.page.destroy) await this.page.destroy();
11549
+ } catch (error) {
11550
+ console.warn('Failed to destroy old agent/page:', error);
11551
+ }
11552
+ try {
11553
+ this.page = await this.pageFactory();
11554
+ this.agent = this.agentFactory(this.page);
11555
+ console.log('Agent recreated successfully');
11556
+ } catch (error) {
11557
+ console.error('Failed to recreate agent:', error);
11558
+ throw error;
11559
+ }
11560
+ }
11543
11561
  setupRoutes() {
11544
11562
  this._app.get('/status', async (req, res)=>{
11545
11563
  res.send({
@@ -11616,7 +11634,12 @@ class PlaygroundServer {
11616
11634
  if (!type) return res.status(400).json({
11617
11635
  error: 'type is required'
11618
11636
  });
11637
+ if (this.currentTaskId) return res.status(409).json({
11638
+ error: 'Another task is already running',
11639
+ currentTaskId: this.currentTaskId
11640
+ });
11619
11641
  if (requestId) {
11642
+ this.currentTaskId = requestId;
11620
11643
  this.taskProgressTips[requestId] = '';
11621
11644
  this.agent.onTaskStartTip = (tip)=>{
11622
11645
  this.taskProgressTips[requestId] = tip;
@@ -11658,7 +11681,10 @@ class PlaygroundServer {
11658
11681
  const timeCost = Date.now() - startTime;
11659
11682
  if (response.error) console.error(`handle request failed after ${timeCost}ms: requestId: ${requestId}, ${response.error}`);
11660
11683
  else console.log(`handle request done after ${timeCost}ms: requestId: ${requestId}`);
11661
- if (requestId) delete this.taskProgressTips[requestId];
11684
+ if (requestId) {
11685
+ delete this.taskProgressTips[requestId];
11686
+ if (this.currentTaskId === requestId) this.currentTaskId = null;
11687
+ }
11662
11688
  });
11663
11689
  this._app.post('/cancel/:requestId', async (req, res)=>{
11664
11690
  const { requestId } = req.params;
@@ -11666,9 +11692,17 @@ class PlaygroundServer {
11666
11692
  error: 'requestId is required'
11667
11693
  });
11668
11694
  try {
11669
- if (this.taskProgressTips[requestId]) delete this.taskProgressTips[requestId];
11695
+ if (this.currentTaskId !== requestId) return res.json({
11696
+ status: 'not_found',
11697
+ message: 'Task not found or already completed'
11698
+ });
11699
+ console.log(`Cancelling task: ${requestId}`);
11700
+ await this.recreateAgent();
11701
+ delete this.taskProgressTips[requestId];
11702
+ this.currentTaskId = null;
11670
11703
  res.json({
11671
- status: 'cancelled'
11704
+ status: 'cancelled',
11705
+ message: 'Task cancelled successfully by recreating agent'
11672
11706
  });
11673
11707
  } catch (error) {
11674
11708
  const errorMessage = error instanceof Error ? error.message : 'Unknown error';
@@ -11768,6 +11802,12 @@ class PlaygroundServer {
11768
11802
  }
11769
11803
  }
11770
11804
  async launch(port) {
11805
+ if (this.pageFactory && this.agentFactory) {
11806
+ console.log('Initializing page and agent from factory functions...');
11807
+ this.page = await this.pageFactory();
11808
+ this.agent = this.agentFactory(this.page);
11809
+ console.log('Page and agent initialized successfully');
11810
+ }
11771
11811
  this.initializeApp();
11772
11812
  this.port = port || defaultPort;
11773
11813
  return new Promise((resolve)=>{
@@ -11807,13 +11847,28 @@ class PlaygroundServer {
11807
11847
  _define_property(this, "taskProgressTips", void 0);
11808
11848
  _define_property(this, "id", void 0);
11809
11849
  _define_property(this, "_initialized", false);
11850
+ _define_property(this, "pageFactory", void 0);
11851
+ _define_property(this, "agentFactory", void 0);
11852
+ _define_property(this, "currentTaskId", null);
11810
11853
  this._app = express_default()();
11811
11854
  this.tmpDir = getTmpDir();
11812
- this.page = page;
11813
- this.agent = agent;
11814
11855
  this.staticPath = staticPath;
11815
11856
  this.taskProgressTips = {};
11816
11857
  this.id = id || utils_uuid();
11858
+ if ('function' == typeof page) {
11859
+ this.pageFactory = page;
11860
+ this.page = null;
11861
+ } else {
11862
+ this.page = page;
11863
+ this.pageFactory = null;
11864
+ }
11865
+ if ('function' == typeof agent) {
11866
+ this.agentFactory = agent;
11867
+ this.agent = null;
11868
+ } else {
11869
+ this.agent = agent;
11870
+ this.agentFactory = null;
11871
+ }
11817
11872
  }
11818
11873
  }
11819
11874
  __webpack_require__("../../node_modules/.pnpm/cors@2.8.5/node_modules/cors/lib/index.js");
@@ -12161,11 +12216,7 @@ class device_IOSDevice {
12161
12216
  }),
12162
12217
  defineActionKeyboardPress(async (param)=>{
12163
12218
  const key = param.keyName;
12164
- if (Array.isArray(key)) {
12165
- const keyToPress = key[key.length - 1];
12166
- console.warn(`[iOS] Key combinations are not supported. Using last key: "${keyToPress}"`, 'Original input:', key);
12167
- await this.pressKey(keyToPress);
12168
- } else await this.pressKey(key);
12219
+ await this.pressKey(key);
12169
12220
  }),
12170
12221
  defineAction({
12171
12222
  name: 'IOSHomeButton',
@@ -12720,17 +12771,14 @@ const main = async ()=>{
12720
12771
  host: 'localhost',
12721
12772
  port: DEFAULT_WDA_PORT
12722
12773
  };
12723
- let device;
12724
- let agent;
12725
12774
  let connected = false;
12726
12775
  while(!connected)try {
12727
- device = new device_IOSDevice({
12776
+ const device = new device_IOSDevice({
12728
12777
  wdaHost: wdaConfig.host,
12729
12778
  wdaPort: wdaConfig.port
12730
12779
  });
12731
12780
  console.log(`\u{1F50C} Connecting to WebDriverAgent at ${wdaConfig.host}:${wdaConfig.port}...`);
12732
12781
  await device.connect();
12733
- agent = new IOSAgent(device);
12734
12782
  connected = true;
12735
12783
  const deviceInfo = await device.getConnectedDeviceInfo();
12736
12784
  console.log("\u2705 Connected to WebDriverAgent successfully!");
@@ -12782,7 +12830,16 @@ const main = async ()=>{
12782
12830
  `);
12783
12831
  else if ('configure' === action) wdaConfig = await configureWebDriverAgent();
12784
12832
  }
12785
- const playgroundServer = new PlaygroundServer(device, agent, staticDir);
12833
+ const deviceFactory = async ()=>{
12834
+ const newDevice = new device_IOSDevice({
12835
+ wdaHost: wdaConfig.host,
12836
+ wdaPort: wdaConfig.port
12837
+ });
12838
+ await newDevice.connect();
12839
+ return newDevice;
12840
+ };
12841
+ const agentFactory = (device)=>new IOSAgent(device);
12842
+ const playgroundServer = new PlaygroundServer(deviceFactory, agentFactory, staticDir);
12786
12843
  console.log("\uD83D\uDE80 Starting server...");
12787
12844
  const availablePlaygroundPort = await findAvailablePort(constants_PLAYGROUND_SERVER_PORT);
12788
12845
  if (availablePlaygroundPort !== constants_PLAYGROUND_SERVER_PORT) console.log(`\u{26A0}\u{FE0F} Port ${constants_PLAYGROUND_SERVER_PORT} is busy, using port ${availablePlaygroundPort} instead`);
package/dist/es/index.mjs CHANGED
@@ -355,11 +355,7 @@ class IOSDevice {
355
355
  }),
356
356
  defineActionKeyboardPress(async (param)=>{
357
357
  const key = param.keyName;
358
- if (Array.isArray(key)) {
359
- const keyToPress = key[key.length - 1];
360
- console.warn(`[iOS] Key combinations are not supported. Using last key: "${keyToPress}"`, 'Original input:', key);
361
- await this.pressKey(keyToPress);
362
- } else await this.pressKey(key);
358
+ await this.pressKey(key);
363
359
  }),
364
360
  defineAction({
365
361
  name: 'IOSHomeButton',
package/dist/lib/bin.js CHANGED
@@ -11669,6 +11669,24 @@ var __webpack_exports__ = {};
11669
11669
  (0, external_node_fs_namespaceObject.writeFileSync)(tmpFile, context);
11670
11670
  return tmpFile;
11671
11671
  }
11672
+ async recreateAgent() {
11673
+ if (!this.pageFactory || !this.agentFactory) return void console.warn('Cannot recreate agent: factory functions not provided. Agent recreation is only available when using factory mode.');
11674
+ console.log('Recreating agent to cancel current task...');
11675
+ try {
11676
+ if (this.agent && 'function' == typeof this.agent.destroy) await this.agent.destroy();
11677
+ if (this.page && 'function' == typeof this.page.destroy) await this.page.destroy();
11678
+ } catch (error) {
11679
+ console.warn('Failed to destroy old agent/page:', error);
11680
+ }
11681
+ try {
11682
+ this.page = await this.pageFactory();
11683
+ this.agent = this.agentFactory(this.page);
11684
+ console.log('Agent recreated successfully');
11685
+ } catch (error) {
11686
+ console.error('Failed to recreate agent:', error);
11687
+ throw error;
11688
+ }
11689
+ }
11672
11690
  setupRoutes() {
11673
11691
  this._app.get('/status', async (req, res)=>{
11674
11692
  res.send({
@@ -11745,7 +11763,12 @@ var __webpack_exports__ = {};
11745
11763
  if (!type) return res.status(400).json({
11746
11764
  error: 'type is required'
11747
11765
  });
11766
+ if (this.currentTaskId) return res.status(409).json({
11767
+ error: 'Another task is already running',
11768
+ currentTaskId: this.currentTaskId
11769
+ });
11748
11770
  if (requestId) {
11771
+ this.currentTaskId = requestId;
11749
11772
  this.taskProgressTips[requestId] = '';
11750
11773
  this.agent.onTaskStartTip = (tip)=>{
11751
11774
  this.taskProgressTips[requestId] = tip;
@@ -11787,7 +11810,10 @@ var __webpack_exports__ = {};
11787
11810
  const timeCost = Date.now() - startTime;
11788
11811
  if (response.error) console.error(`handle request failed after ${timeCost}ms: requestId: ${requestId}, ${response.error}`);
11789
11812
  else console.log(`handle request done after ${timeCost}ms: requestId: ${requestId}`);
11790
- if (requestId) delete this.taskProgressTips[requestId];
11813
+ if (requestId) {
11814
+ delete this.taskProgressTips[requestId];
11815
+ if (this.currentTaskId === requestId) this.currentTaskId = null;
11816
+ }
11791
11817
  });
11792
11818
  this._app.post('/cancel/:requestId', async (req, res)=>{
11793
11819
  const { requestId } = req.params;
@@ -11795,9 +11821,17 @@ var __webpack_exports__ = {};
11795
11821
  error: 'requestId is required'
11796
11822
  });
11797
11823
  try {
11798
- if (this.taskProgressTips[requestId]) delete this.taskProgressTips[requestId];
11824
+ if (this.currentTaskId !== requestId) return res.json({
11825
+ status: 'not_found',
11826
+ message: 'Task not found or already completed'
11827
+ });
11828
+ console.log(`Cancelling task: ${requestId}`);
11829
+ await this.recreateAgent();
11830
+ delete this.taskProgressTips[requestId];
11831
+ this.currentTaskId = null;
11799
11832
  res.json({
11800
- status: 'cancelled'
11833
+ status: 'cancelled',
11834
+ message: 'Task cancelled successfully by recreating agent'
11801
11835
  });
11802
11836
  } catch (error) {
11803
11837
  const errorMessage = error instanceof Error ? error.message : 'Unknown error';
@@ -11897,6 +11931,12 @@ var __webpack_exports__ = {};
11897
11931
  }
11898
11932
  }
11899
11933
  async launch(port) {
11934
+ if (this.pageFactory && this.agentFactory) {
11935
+ console.log('Initializing page and agent from factory functions...');
11936
+ this.page = await this.pageFactory();
11937
+ this.agent = this.agentFactory(this.page);
11938
+ console.log('Page and agent initialized successfully');
11939
+ }
11900
11940
  this.initializeApp();
11901
11941
  this.port = port || defaultPort;
11902
11942
  return new Promise((resolve)=>{
@@ -11936,13 +11976,28 @@ var __webpack_exports__ = {};
11936
11976
  _define_property(this, "taskProgressTips", void 0);
11937
11977
  _define_property(this, "id", void 0);
11938
11978
  _define_property(this, "_initialized", false);
11979
+ _define_property(this, "pageFactory", void 0);
11980
+ _define_property(this, "agentFactory", void 0);
11981
+ _define_property(this, "currentTaskId", null);
11939
11982
  this._app = express_default()();
11940
11983
  this.tmpDir = (0, utils_namespaceObject.getTmpDir)();
11941
- this.page = page;
11942
- this.agent = agent;
11943
11984
  this.staticPath = staticPath;
11944
11985
  this.taskProgressTips = {};
11945
11986
  this.id = id || (0, shared_utils_namespaceObject.uuid)();
11987
+ if ('function' == typeof page) {
11988
+ this.pageFactory = page;
11989
+ this.page = null;
11990
+ } else {
11991
+ this.page = page;
11992
+ this.pageFactory = null;
11993
+ }
11994
+ if ('function' == typeof agent) {
11995
+ this.agentFactory = agent;
11996
+ this.agent = null;
11997
+ } else {
11998
+ this.agent = agent;
11999
+ this.agentFactory = null;
12000
+ }
11946
12001
  }
11947
12002
  }
11948
12003
  const external_node_child_process_namespaceObject = require("node:child_process");
@@ -12299,11 +12354,7 @@ var __webpack_exports__ = {};
12299
12354
  }),
12300
12355
  (0, device_namespaceObject.defineActionKeyboardPress)(async (param)=>{
12301
12356
  const key = param.keyName;
12302
- if (Array.isArray(key)) {
12303
- const keyToPress = key[key.length - 1];
12304
- console.warn(`[iOS] Key combinations are not supported. Using last key: "${keyToPress}"`, 'Original input:', key);
12305
- await this.pressKey(keyToPress);
12306
- } else await this.pressKey(key);
12357
+ await this.pressKey(key);
12307
12358
  }),
12308
12359
  (0, device_namespaceObject.defineAction)({
12309
12360
  name: 'IOSHomeButton',
@@ -12860,17 +12911,14 @@ ScreenSize: ${size.width}x${size.height} (DPR: ${size.scale})
12860
12911
  host: 'localhost',
12861
12912
  port: constants_namespaceObject.DEFAULT_WDA_PORT
12862
12913
  };
12863
- let device;
12864
- let agent;
12865
12914
  let connected = false;
12866
12915
  while(!connected)try {
12867
- device = new device_IOSDevice({
12916
+ const device = new device_IOSDevice({
12868
12917
  wdaHost: wdaConfig.host,
12869
12918
  wdaPort: wdaConfig.port
12870
12919
  });
12871
12920
  console.log(`\u{1F50C} Connecting to WebDriverAgent at ${wdaConfig.host}:${wdaConfig.port}...`);
12872
12921
  await device.connect();
12873
- agent = new IOSAgent(device);
12874
12922
  connected = true;
12875
12923
  const deviceInfo = await device.getConnectedDeviceInfo();
12876
12924
  console.log("\u2705 Connected to WebDriverAgent successfully!");
@@ -12922,7 +12970,16 @@ ScreenSize: ${size.width}x${size.height} (DPR: ${size.scale})
12922
12970
  `);
12923
12971
  else if ('configure' === action) wdaConfig = await configureWebDriverAgent();
12924
12972
  }
12925
- const playgroundServer = new PlaygroundServer(device, agent, staticDir);
12973
+ const deviceFactory = async ()=>{
12974
+ const newDevice = new device_IOSDevice({
12975
+ wdaHost: wdaConfig.host,
12976
+ wdaPort: wdaConfig.port
12977
+ });
12978
+ await newDevice.connect();
12979
+ return newDevice;
12980
+ };
12981
+ const agentFactory = (device)=>new IOSAgent(device);
12982
+ const playgroundServer = new PlaygroundServer(deviceFactory, agentFactory, staticDir);
12926
12983
  console.log("\uD83D\uDE80 Starting server...");
12927
12984
  const availablePlaygroundPort = await findAvailablePort(constants_namespaceObject.PLAYGROUND_SERVER_PORT);
12928
12985
  if (availablePlaygroundPort !== constants_namespaceObject.PLAYGROUND_SERVER_PORT) console.log(`\u{26A0}\u{FE0F} Port ${constants_namespaceObject.PLAYGROUND_SERVER_PORT} is busy, using port ${availablePlaygroundPort} instead`);
package/dist/lib/index.js CHANGED
@@ -393,11 +393,7 @@ class IOSDevice {
393
393
  }),
394
394
  (0, device_namespaceObject.defineActionKeyboardPress)(async (param)=>{
395
395
  const key = param.keyName;
396
- if (Array.isArray(key)) {
397
- const keyToPress = key[key.length - 1];
398
- console.warn(`[iOS] Key combinations are not supported. Using last key: "${keyToPress}"`, 'Original input:', key);
399
- await this.pressKey(keyToPress);
400
- } else await this.pressKey(key);
396
+ await this.pressKey(key);
401
397
  }),
402
398
  (0, device_namespaceObject.defineAction)({
403
399
  name: 'IOSHomeButton',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midscene/ios",
3
- "version": "0.30.6-beta-20251021121032.0",
3
+ "version": "0.30.6-beta-20251022061949.0",
4
4
  "description": "iOS automation library for Midscene",
5
5
  "keywords": [
6
6
  "iOS UI automation",
@@ -38,9 +38,9 @@
38
38
  "dependencies": {
39
39
  "@inquirer/prompts": "^7.8.6",
40
40
  "open": "10.1.0",
41
- "@midscene/core": "0.30.6-beta-20251021121032.0",
42
- "@midscene/webdriver": "0.30.6-beta-20251021121032.0",
43
- "@midscene/shared": "0.30.6-beta-20251021121032.0"
41
+ "@midscene/shared": "0.30.6-beta-20251022061949.0",
42
+ "@midscene/core": "0.30.6-beta-20251022061949.0",
43
+ "@midscene/webdriver": "0.30.6-beta-20251022061949.0"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@rslib/core": "^0.11.2",
@@ -49,7 +49,7 @@
49
49
  "typescript": "^5.8.3",
50
50
  "tsx": "^4.19.2",
51
51
  "vitest": "3.0.5",
52
- "@midscene/playground": "0.30.6-beta-20251021121032.0"
52
+ "@midscene/playground": "0.30.6-beta-20251022061949.0"
53
53
  },
54
54
  "license": "MIT",
55
55
  "scripts": {
package/static/index.html CHANGED
@@ -1 +1 @@
1
- <!doctype html><html><head><link rel="icon" href="/favicon.ico"><title>Midscene Playground</title><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><script defer src="/static/js/lib-react.f566a9ed.js"></script><script defer src="/static/js/657.5a5fe47b.js"></script><script defer src="/static/js/index.b9367b66.js"></script><link href="/static/css/index.44466eb4.css" rel="stylesheet"></head><body><div id="root"></div></body></html>
1
+ <!doctype html><html><head><link rel="icon" href="/favicon.ico"><title>Midscene Playground</title><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><script defer src="/static/js/lib-react.f566a9ed.js"></script><script defer src="/static/js/657.5a5fe47b.js"></script><script defer src="/static/js/index.5c3c93e4.js"></script><link href="/static/css/index.44466eb4.css" rel="stylesheet"></head><body><div id="root"></div></body></html>