-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add support for chromium browsers #5
Merged
michaellzc
merged 4 commits into
michaellzc:master
from
yannbf:feat/support-chromium-browsers
Apr 6, 2020
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
dist/ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,93 @@ | ||
(* | ||
Copyright (c) 2015-present, Facebook, Inc. | ||
|
||
This source code is licensed under the MIT license found in the | ||
LICENSE file in the root directory of this source tree. | ||
*) | ||
|
||
property targetTab: null | ||
property targetTabIndex: -1 | ||
property targetWindow: null | ||
property theProgram: "Google Chrome" | ||
|
||
on run argv | ||
set theURL to item 1 of argv | ||
|
||
tell application "Chrome" | ||
-- Allow requested program to be optional, | ||
-- default to Google Chrome | ||
if (count of argv) > 1 then | ||
set theProgram to item 2 of argv | ||
end if | ||
|
||
using terms from application "Google Chrome" | ||
tell application theProgram | ||
|
||
if (count every window) = 0 then | ||
make new window | ||
end if | ||
if (count every window) = 0 then | ||
make new window | ||
end if | ||
|
||
-- 1: Looking for tab running debugger | ||
-- then, Reload debugging tab if found | ||
-- then return | ||
set found to my lookupTabWithUrl(theURL) | ||
if found then | ||
set targetWindow's active tab index to targetTabIndex | ||
tell targetTab to reload | ||
tell targetWindow to activate | ||
set index of targetWindow to 1 | ||
return | ||
end if | ||
-- 1: Looking for tab running debugger | ||
-- then, Reload debugging tab if found | ||
-- then return | ||
set found to my lookupTabWithUrl(theURL) | ||
if found then | ||
set targetWindow's active tab index to targetTabIndex | ||
tell targetTab to reload | ||
tell targetWindow to activate | ||
set index of targetWindow to 1 | ||
return | ||
end if | ||
|
||
-- 2: Looking for Empty tab | ||
-- In case debugging tab was not found | ||
-- We try to find an empty tab instead | ||
set found to my lookupTabWithUrl("chrome://newtab/") | ||
if found then | ||
set targetWindow's active tab index to targetTabIndex | ||
set URL of targetTab to theURL | ||
tell targetWindow to activate | ||
return | ||
end if | ||
-- 2: Looking for Empty tab | ||
-- In case debugging tab was not found | ||
-- We try to find an empty tab instead | ||
set found to my lookupTabWithUrl("chrome://newtab/") | ||
if found then | ||
set targetWindow's active tab index to targetTabIndex | ||
set URL of targetTab to theURL | ||
tell targetWindow to activate | ||
return | ||
end if | ||
|
||
-- 3: Create new tab | ||
-- both debugging and empty tab were not found | ||
-- make a new tab with url | ||
tell window 1 | ||
activate | ||
make new tab with properties {URL:theURL} | ||
-- 3: Create new tab | ||
-- both debugging and empty tab were not found | ||
-- make a new tab with url | ||
tell window 1 | ||
activate | ||
make new tab with properties {URL:theURL} | ||
end tell | ||
end tell | ||
end tell | ||
end using terms from | ||
end run | ||
|
||
-- Function: | ||
-- Lookup tab with given url | ||
-- if found, store tab, index, and window in properties | ||
-- (properties were declared on top of file) | ||
on lookupTabWithUrl(lookupUrl) | ||
tell application "Chrome" | ||
-- Find a tab with the given url | ||
set found to false | ||
set theTabIndex to -1 | ||
repeat with theWindow in every window | ||
set theTabIndex to 0 | ||
repeat with theTab in every tab of theWindow | ||
set theTabIndex to theTabIndex + 1 | ||
if (theTab's URL as string) contains lookupUrl then | ||
-- assign tab, tab index, and window to properties | ||
set targetTab to theTab | ||
set targetTabIndex to theTabIndex | ||
set targetWindow to theWindow | ||
set found to true | ||
using terms from application "Google Chrome" | ||
tell application theProgram | ||
-- Find a tab with the given url | ||
set found to false | ||
set theTabIndex to -1 | ||
repeat with theWindow in every window | ||
set theTabIndex to 0 | ||
repeat with theTab in every tab of theWindow | ||
set theTabIndex to theTabIndex + 1 | ||
if (theTab's URL as string) contains lookupUrl then | ||
-- assign tab, tab index, and window to properties | ||
set targetTab to theTab | ||
set targetTabIndex to theTabIndex | ||
set targetWindow to theWindow | ||
set found to true | ||
exit repeat | ||
end if | ||
end repeat | ||
|
||
if found then | ||
exit repeat | ||
end if | ||
end repeat | ||
|
||
if found then | ||
exit repeat | ||
end if | ||
end repeat | ||
end tell | ||
end tell | ||
end using terms from | ||
return found | ||
end lookupTabWithUrl | ||
end lookupTabWithUrl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1605,6 +1605,11 @@ is-descriptor@^1.0.0, is-descriptor@^1.0.2: | |
is-data-descriptor "^1.0.0" | ||
kind-of "^6.0.2" | ||
|
||
is-docker@^2.0.0: | ||
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/is-docker/-/is-docker-2.0.0.tgz#2cb0df0e75e2d064fe1864c37cdeacb7b2dcf25b" | ||
integrity sha512-pJEdRugimx4fBMra5z2/5iRdZ63OhYV0vr0Dwm5+xtW4D1FvRkB8hamMIhnWfyJeDdyr/aa7BDyNbtG38VxgoQ== | ||
|
||
is-extendable@^0.1.0, is-extendable@^0.1.1: | ||
version "0.1.1" | ||
resolved "https://registry.yarnpkg.com/is-extendable/-/is-extendable-0.1.1.tgz#62b110e289a471418e3ec36a617d472e301dfc89" | ||
|
@@ -1677,10 +1682,10 @@ is-windows@^1.0.2: | |
resolved "https://registry.yarnpkg.com/is-windows/-/is-windows-1.0.2.tgz#d1850eb9791ecd18e6182ce12a30f396634bb19d" | ||
integrity sha512-eXK1UInq2bPmjyX6e3VHIzMLobc4J94i4AWn+Hpq3OU5KkrRC96OAcR3PRJ/pGu6m8TRnBHP9dkXQVsT/COVIA== | ||
|
||
is-wsl@^1.1.0: | ||
version "1.1.0" | ||
resolved "https://registry.yarnpkg.com/is-wsl/-/is-wsl-1.1.0.tgz#1f16e4aa22b04d1336b66188a66af3c600c3a66d" | ||
integrity sha1-HxbkqiKwTRM2tmGIpmrzxgDDpm0= | ||
is-wsl@^2.1.1: | ||
version "2.1.1" | ||
resolved "https://registry.yarnpkg.com/is-wsl/-/is-wsl-2.1.1.tgz#4a1c152d429df3d441669498e2486d3596ebaf1d" | ||
integrity sha512-umZHcSrwlDHo2TGMXv0DZ8dIUGunZ2Iv68YZnrmCiBPkZ4aaOhtv7pXJKeki9k3qJ3RJr0cDyitcl5wEH3AYog== | ||
|
||
[email protected], isarray@~1.0.0: | ||
version "1.0.0" | ||
|
@@ -2060,12 +2065,13 @@ onetime@^2.0.0: | |
dependencies: | ||
mimic-fn "^1.0.0" | ||
|
||
open@^6.4.0: | ||
version "6.4.0" | ||
resolved "https://registry.yarnpkg.com/open/-/open-6.4.0.tgz#5c13e96d0dc894686164f18965ecfe889ecfc8a9" | ||
integrity sha512-IFenVPgF70fSm1keSd2iDBIDIBZkroLeuffXq+wKTzTJlBpesFWojV9lb8mzOfaAzM1sr7HQHuO0vtV0zYekGg== | ||
open@^7.0.3: | ||
version "7.0.3" | ||
resolved "https://registry.yarnpkg.com/open/-/open-7.0.3.tgz#db551a1af9c7ab4c7af664139930826138531c48" | ||
integrity sha512-sP2ru2v0P290WFfv49Ap8MF6PkzGNnGlAwHweB4WR4mr5d2d0woiCluUeJ218w7/+PmoBy9JmYgD5A4mLcWOFA== | ||
dependencies: | ||
is-wsl "^1.1.0" | ||
is-docker "^2.0.0" | ||
is-wsl "^2.1.1" | ||
|
||
optionator@^0.8.2: | ||
version "0.8.2" | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CRA also takes care in case it runs on node scripts as you can see here. I left all that part out because I imagined there was a reason you didn't have it. Wanted to know your point of view about it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some background story, gatsbyjs/gatsby#6550
I guess my intention was the
script
option is not a use case ingatsby
, so I ended up excluding it. Also, I wasn't expecting people besidesgatsby
who would actually use this library.I don't mind adding the
script
option back tobetter-opn
, it should be done in a separate PR tho.