(argv)
| 10 | |
| 11 | // eslint-disable-next-line @typescript-eslint/no-unused-vars |
| 12 | function run(argv) { |
| 13 | const urlToOpen = argv[0] |
| 14 | // Allow requested program to be optional, default to Google Chrome |
| 15 | const programName = argv[1] ?? 'Google Chrome' |
| 16 | |
| 17 | const app = Application(programName) |
| 18 | |
| 19 | if (app.windows.length === 0) { |
| 20 | app.Window().make() |
| 21 | } |
| 22 | |
| 23 | // 1: Looking for tab running debugger then, |
| 24 | // Reload debugging tab if found, then return |
| 25 | const found = lookupTabWithUrl(urlToOpen, app) |
| 26 | if (found) { |
| 27 | found.targetWindow.activeTabIndex = found.targetTabIndex |
| 28 | found.targetTab.reload() |
| 29 | found.targetWindow.index = 1 |
| 30 | app.activate() |
| 31 | return |
| 32 | } |
| 33 | |
| 34 | // 2: Looking for Empty tab |
| 35 | // In case debugging tab was not found |
| 36 | // We try to find an empty tab instead |
| 37 | const emptyTabFound = lookupTabWithUrl('chrome://newtab/', app) |
| 38 | if (emptyTabFound) { |
| 39 | emptyTabFound.targetWindow.activeTabIndex = emptyTabFound.targetTabIndex |
| 40 | emptyTabFound.targetTab.url = urlToOpen |
| 41 | app.activate() |
| 42 | return |
| 43 | } |
| 44 | |
| 45 | // 3: Create new tab |
| 46 | // both debugging and empty tab were not found make a new tab with url |
| 47 | const firstWindow = app.windows[0] |
| 48 | firstWindow.tabs.push(app.Tab({ url: urlToOpen })) |
| 49 | app.activate() |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Lookup tab with given url |
nothing calls this directly
no test coverage detected