-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PROD-1607 import opn and modify for new window (#487)
* import and extend 'open' Signed-off-by: Mason Fish <[email protected]> * fix flow Signed-off-by: Mason Fish <[email protected]> * include src reference Signed-off-by: Mason Fish <[email protected]> * pass args in for pcap Signed-off-by: Mason Fish <[email protected]> * add downloadPcaps flow Signed-off-by: Mason Fish <[email protected]> Co-authored-by: Mason Fish <[email protected]>
- Loading branch information
1 parent
3e6b413
commit 213ed33
Showing
13 changed files
with
177 additions
and
40 deletions.
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 |
---|---|---|
|
@@ -80,3 +80,15 @@ Redistribution and use in source and binary forms, with or without modification, | |
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
# End salesforce/hassh/LICENSE.txt | ||
|
||
# Begin sindresorhus/open/license | ||
MIT License | ||
|
||
Copyright (c) Sindre Sorhus <[email protected]> (sindresorhus.com) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
# End sindresorhus/open/license |
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 was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* @flow */ | ||
import type {Thunk} from "../state/types" | ||
import Packets from "../state/Packets" | ||
import open from "../lib/open" | ||
import Log from "../models/Log" | ||
|
||
export const downloadPcap = (currentLog: Log): Thunk => (dispatch) => { | ||
dispatch(Packets.fetch(currentLog)).then((pcapFile) => | ||
open(pcapFile, {newWindow: true}) | ||
) | ||
} |
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 |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/* @flow */ | ||
// code from https://github.com/sindresorhus/open/releases/tag/v6.0.0 | ||
"use strict" | ||
const {promisify} = require("util") | ||
const path = require("path") | ||
const childProcess = require("child_process") | ||
const isWsl = require("is-wsl") | ||
|
||
const pExecFile = promisify(childProcess.execFile) | ||
|
||
// Convert a path from WSL format to Windows format: | ||
// `/mnt/c/Program Files/Example/MyApp.exe` → `C:\Program Files\Example\MyApp.exe`` | ||
const wslToWindowsPath = async (path) => { | ||
const {stdout} = await pExecFile("wslpath", ["-w", path]) | ||
return stdout.trim() | ||
} | ||
|
||
export default async function open(target: string, options?: Object) { | ||
if (typeof target !== "string") { | ||
throw new TypeError("Expected a `target`") | ||
} | ||
|
||
options = { | ||
wait: false, | ||
newWindow: false, | ||
...options | ||
} | ||
|
||
let command | ||
let appArguments = [] | ||
const cliArguments = [] | ||
const childProcessOptions = {} | ||
|
||
if (Array.isArray(options.app)) { | ||
appArguments = options.app.slice(1) | ||
options.app = options.app[0] | ||
} | ||
|
||
if (process.platform === "darwin") { | ||
command = "open" | ||
|
||
if (options.newWindow) { | ||
cliArguments.push("-n") | ||
} | ||
|
||
if (options.wait) { | ||
cliArguments.push("-W") | ||
} | ||
|
||
if (options.app) { | ||
cliArguments.push("-a", options.app) | ||
} | ||
} else if (process.platform === "win32" || isWsl) { | ||
command = "cmd" + (isWsl ? ".exe" : "") | ||
cliArguments.push("/c", "start", '""', "/b") | ||
target = target.replace(/&/g, "^&") | ||
|
||
if (options.wait) { | ||
cliArguments.push("/wait") | ||
} | ||
|
||
if (options.app) { | ||
if (isWsl && options.app.startsWith("/mnt/")) { | ||
const windowsPath = await wslToWindowsPath(options.app) | ||
options.app = windowsPath | ||
} | ||
|
||
cliArguments.push(options.app) | ||
} | ||
|
||
if (appArguments.length > 0) { | ||
cliArguments.push(...appArguments) | ||
} | ||
} else { | ||
if (options.app) { | ||
command = options.app | ||
} else { | ||
const useSystemXdgOpen = | ||
process.versions.electron || process.platform === "android" | ||
command = useSystemXdgOpen ? "xdg-open" : path.join(__dirname, "xdg-open") | ||
} | ||
|
||
if (appArguments.length > 0) { | ||
cliArguments.push(...appArguments) | ||
} | ||
|
||
if (!options.wait) { | ||
// `xdg-open` will block the process unless stdio is ignored | ||
// and it's detached from the parent even if it's unref'd. | ||
childProcessOptions.stdio = "ignore" | ||
childProcessOptions.detached = true | ||
} | ||
} | ||
|
||
cliArguments.push(target) | ||
|
||
if (process.platform === "darwin" && appArguments.length > 0) { | ||
cliArguments.push("--args", ...appArguments) | ||
} | ||
|
||
const subprocess = childProcess.spawn( | ||
command, | ||
cliArguments, | ||
childProcessOptions | ||
) | ||
|
||
if (options.wait) { | ||
return new Promise((resolve, reject) => { | ||
subprocess.once("error", reject) | ||
|
||
subprocess.once("close", (exitCode) => { | ||
if (exitCode > 0) { | ||
reject(new Error(`Exited with code ${exitCode}`)) | ||
return | ||
} | ||
|
||
resolve(subprocess) | ||
}) | ||
}) | ||
} | ||
|
||
subprocess.unref() | ||
|
||
return subprocess | ||
} |