webbrowser-0.8.10/.cargo_vcs_info.json 0000644 00000000136 00000000001 0013303 0 ustar {
"git": {
"sha1": "322bc6132072368cf0ef96bd9217762c64f06514"
},
"path_in_vcs": ""
} webbrowser-0.8.10/.github/workflows/android.yaml 0000644 0000000 0000000 00000007025 10461020230 0020000 0 ustar 0000000 0000000 name: Android
on:
push:
branches-ignore: [ '**win**', '**linux**', '**macos**', '**bsd**', '**haiku**', '**wasm**', '**ios**' ]
pull_request:
branches: [ main ]
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
RUST_LOG: webbrowser=TRACE,tests=TRACE
CARGO_APK_VERSION: '0.9.7'
ANDROID_ARCH: x86_64
ANDROID_TARGET: x86_64-linux-android
jobs:
build:
name: Build
runs-on: macos-latest
if: ${{ !contains(github.event.head_commit.message, '#build-') || contains(github.event.head_commit.message, '#build-android') }}
strategy:
matrix:
rust: [ stable ]
api-level: [ 30 ]
ndk-version: [ '25.1.8937393' ]
cmake-version: [ '3.22.1' ]
continue-on-error: ${{ matrix.rust != 'stable' && matrix.rust != 'beta' }}
steps:
- uses: actions/checkout@v3
name: Checkout
- name: Install rust version
run: |
rustup install ${{ matrix.rust }} --profile minimal
rustup component add --toolchain ${{ matrix.rust }} rustfmt clippy
rustup target add ${{ env.ANDROID_TARGET }}
# Install cargo-apk
- uses: actions/cache@v3
name: Fetch cargo-apk from cache
id: cargo-apk-cache
with:
path: ~/.cargo/bin/cargo-apk
key: cargo-apk-${{ env.CARGO_APK_VERSION }}
- name: Install cargo-apk
if: steps.cargo-apk-cache.outputs.cache-hit != 'true'
run: cargo install cargo-apk --version ${{ env.CARGO_APK_VERSION }}
# Pre-build
- name: Compile
run: rustup run ${{ matrix.rust }} cargo apk build --target ${{ env.ANDROID_TARGET }}
working-directory: tests/test-android-app
- name: Compile tests
run: rustup run ${{ matrix.rust }} cargo build --test test_android
# Check if AVD is in cache, else create AVD
- name: AVD cache
uses: actions/cache@v3
id: avd-cache
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-${{ matrix.api-level }}
- name: Create AVD
if: steps.avd-cache.outputs.cache-hit != 'true'
uses: reactivecircus/android-emulator-runner@v2
with:
arch: ${{ env.ANDROID_ARCH }}
api-level: ${{ matrix.api-level }}
force-avd-creation: false
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: false
script: echo "Generated AVD snapshot for caching."
# Run tests on emulator
- name: Run tests
uses: reactivecircus/android-emulator-runner@v2
with:
arch: ${{ env.ANDROID_ARCH }}
api-level: ${{ matrix.api-level }}
ndk: ${{ matrix.ndk-version }}
cmake: ${{ matrix.cmake-version }}
force-avd-creation: false
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: true
script: bash -c 'ANDROID_TARGET=${{ env.ANDROID_TARGET }} ANDROID_NDK_ROOT=$ANDROID_SDK_ROOT/ndk/${{ matrix.ndk-version }} rustup run ${{ matrix.rust }} cargo test --test test_android -- --ignored'
# Code format, linting etc.
- name: Check Code Formatting
if: ${{ matrix.rust == 'stable' || matrix.rust == 'beta' }}
run: cargo +${{ matrix.rust }} fmt --all -- --check
- name: Lints
if: ${{ matrix.rust == 'stable' || matrix.rust == 'beta' }}
run: cargo +${{ matrix.rust }} clippy --target ${{ env.ANDROID_TARGET }} -- -D warnings
webbrowser-0.8.10/.github/workflows/ios.yaml 0000644 0000000 0000000 00000003753 10461020230 0017156 0 ustar 0000000 0000000 name: iOS
on:
push:
branches-ignore: [ '**win**', '**android**', '**linux**', '**bsd**', '**haiku**', '**wasm**', '**macos**' ]
pull_request:
branches: [ main ]
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
RUST_LOG: webbrowser=TRACE
IOS_TARGET: x86_64-apple-ios
jobs:
build:
name: Build
runs-on: macos-latest
if: ${{ !contains(github.event.head_commit.message, '#build-') || contains(github.event.head_commit.message, '#build-ios') }}
strategy:
matrix:
rust: [stable]
continue-on-error: ${{ matrix.rust != 'stable' && matrix.rust != 'beta' }}
steps:
- uses: actions/checkout@v3
name: Checkout
- name: Install rust version
run: |
rustup install ${{ matrix.rust }} --profile minimal
rustup component add --toolchain ${{ matrix.rust }} rustfmt clippy
rustup target add ${{ env.IOS_TARGET }}
- name: Configure and start iOS Simulator
run: |
set -e
open -a Simulator
sleep 5
IOSRUNTIME=$(xcrun simctl list 2>&1 | egrep '^iOS' | head -n 1 | awk '{ print $NF }')
IOSDEV=$(xcrun simctl list 2>&1 | grep com.apple.CoreSimulator.SimDeviceType.iPhone | grep -v ' SE ' | tail -n 1 | tr -d '()' | awk '{ print $NF }')
DEVID=$(xcrun simctl create iphone-latest $IOSDEV $IOSRUNTIME)
echo "==== using device $IOSDEV, $IOSRUNTIME ===="
xcrun simctl boot $DEVID
sleep 5
xcrun simctl list 2>&1
# Run tests
- name: Run tests
run: cargo +${{ matrix.rust }} test --verbose --test test_ios -- --include-ignored
# Code format, linting etc.
- name: Check Code Formatting
if: ${{ matrix.rust == 'stable' || matrix.rust == 'beta' }}
run: cargo +${{ matrix.rust }} fmt --all -- --check
- name: Lints
if: ${{ matrix.rust == 'stable' || matrix.rust == 'beta' }}
run: cargo +${{ matrix.rust }} clippy --target ${{ env.IOS_TARGET }} -- -D warnings
webbrowser-0.8.10/.github/workflows/linux.yaml 0000644 0000000 0000000 00000003235 10461020230 0017516 0 ustar 0000000 0000000 name: Linux
on:
push:
branches-ignore: [ '**win**', '**android**', '**macos**', '**bsd**', '**haiku**', '**wasm**', '**ios**' ]
pull_request:
branches: [ main ]
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
RUST_LOG: webbrowser=TRACE
jobs:
build:
name: Build
runs-on: ubuntu-latest
if: ${{ !contains(github.event.head_commit.message, '#build-') || contains(github.event.head_commit.message, '#build-linux') }}
strategy:
max-parallel: 1
matrix:
rust: [stable, beta, nightly]
continue-on-error: ${{ matrix.rust != 'stable' && matrix.rust != 'beta' }}
steps:
- uses: actions/checkout@v3
name: Checkout
- name: Install rust version
run: |
rustup install ${{ matrix.rust }} --profile minimal
rustup component add --toolchain ${{ matrix.rust }} rustfmt clippy
- name: Compile
run: cargo +${{ matrix.rust }} build
- name: Run Tests
env:
BROWSER: firefox --screenshot %s
run: cargo +${{ matrix.rust }} test --all --locked --verbose
- name: Run Tests (hardened)
run: cargo +${{ matrix.rust }} test --features hardened --locked --verbose --test test_unix tests::test_hardened_mode
- name: Check compilation with WSL disabled
run: cargo +${{ matrix.rust }} build --features disable-wsl
- name: Check Code Formatting
if: ${{ matrix.rust == 'stable' || matrix.rust == 'beta' }}
run: cargo +${{ matrix.rust }} fmt --all -- --check
- name: Lints
if: ${{ matrix.rust == 'stable' || matrix.rust == 'beta' }}
run: cargo +${{ matrix.rust }} clippy --all-targets -- -D warnings
webbrowser-0.8.10/.github/workflows/macos.yaml 0000644 0000000 0000000 00000002764 10461020230 0017467 0 ustar 0000000 0000000 name: MacOS
on:
push:
branches-ignore: [ '**win**', '**android**', '**linux**', '**bsd**', '**haiku**', '**wasm**', '**ios**' ]
pull_request:
branches: [ main ]
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
RUST_LOG: webbrowser=TRACE
jobs:
build:
name: Build
runs-on: macos-latest
if: ${{ !contains(github.event.head_commit.message, '#build-') || contains(github.event.head_commit.message, '#build-macos') }}
strategy:
matrix:
rust: [stable]
continue-on-error: ${{ matrix.rust != 'stable' && matrix.rust != 'beta' }}
steps:
- uses: actions/checkout@v3
name: Checkout
- name: Install specific rust version
run: |
rustup install ${{ matrix.rust }} --profile minimal
rustup component add --toolchain ${{ matrix.rust }} rustfmt clippy
- name: Compile
run: cargo +${{ matrix.rust }} build
- name: Run Tests
run: cargo +${{ matrix.rust }} test --locked --verbose --test test_macos -- --include-ignored
- name: Run Tests (hardened)
run: cargo +${{ matrix.rust }} test --features hardened --locked --verbose --test test_macos tests::test_hardened_mode
- name: Check Code Formatting
if: ${{ matrix.rust == 'stable' || matrix.rust == 'beta' }}
run: cargo +${{ matrix.rust }} fmt --all -- --check
- name: Lints
if: ${{ matrix.rust == 'stable' || matrix.rust == 'beta' }}
run: cargo +${{ matrix.rust }} clippy --all-targets -- -D warnings
webbrowser-0.8.10/.github/workflows/release.yaml 0000644 0000000 0000000 00000002537 10461020230 0020003 0 ustar 0000000 0000000 name: Release
on:
release:
types: [ created ]
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
RUST_LOG: webbrowser=TRACE
jobs:
crates:
name: Crates Publish
runs-on: ubuntu-latest
strategy:
matrix:
rust: [stable]
continue-on-error: ${{ matrix.rust != 'stable' && matrix.rust != 'beta' }}
steps:
- uses: actions/checkout@v3
name: Checkout
- name: Install rust version
run: |
rustup install ${{ matrix.rust }} --profile minimal
rustup component add --toolchain ${{ matrix.rust }} rustfmt clippy
# Check compilation
- name: Compile
run: cargo +${{ matrix.rust }} build
# Run tests
- name: Run Tests
env:
BROWSER: firefox --screenshot %s
run: cargo +${{ matrix.rust }} test --all --locked --verbose
# Code format and lints
- name: Check Code Formatting
if: ${{ matrix.rust == 'stable' || matrix.rust == 'beta' }}
run: cargo +${{ matrix.rust }} fmt --all -- --check
- name: Lints
if: ${{ matrix.rust == 'stable' || matrix.rust == 'beta' }}
run: cargo +${{ matrix.rust }} clippy --all-targets -- -D warnings
# Publish to crates.io
- name: Publish
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_TOKEN }}
run: cargo publish --no-verify
webbrowser-0.8.10/.github/workflows/wasm.yaml 0000644 0000000 0000000 00000004320 10461020230 0017322 0 ustar 0000000 0000000 name: WASM
on:
push:
branches-ignore: [ '**win**', '**android**', '**linux**', '**bsd**', '**haiku**', '**macos**', '**ios**' ]
pull_request:
branches: [ main ]
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
RUST_LOG: webbrowser=TRACE
WASM_PACK_VERSION: '0.10.3'
WASM_TARGET: wasm32-unknown-unknown
jobs:
build:
name: Build
runs-on: ubuntu-latest
if: ${{ !contains(github.event.head_commit.message, '#build-') || contains(github.event.head_commit.message, '#build-wasm') }}
strategy:
max-parallel: 1
matrix:
rust: [stable, beta]
continue-on-error: ${{ matrix.rust != 'stable' && matrix.rust != 'beta' }}
steps:
- uses: actions/checkout@v3
name: Checkout
- name: Install rust version
run: |
rustup install ${{ matrix.rust }} --profile minimal
rustup component add --toolchain ${{ matrix.rust }} rustfmt clippy
rustup target add ${{ env.WASM_TARGET }}
# Install wasm-pack
- uses: actions/cache@v3
name: Fetch wasm-pack from cache
id: wasm-pack-cache
with:
path: ~/.cargo/bin/wasm-pack
key: wasm-pack-${{ env.WASM_PACK_VERSION }}
- name: Install wasm-pack
if: steps.wasm-pack-cache.outputs.cache-hit != 'true'
run: cargo install wasm-pack --version ${{ env.WASM_PACK_VERSION }}
# Compile using WEBBROWSER_WASM_TARGET=_self so that we don't encounter popup blockers
- name: Compile
env:
RUST_LOG: info
WEBBROWSER_WASM_TARGET: _self
run: rustup run ${{ matrix.rust }} wasm-pack build --target web --dev
working-directory: tests/test-wasm-app
# Run tests
- name: Run tests
env:
BROWSER: firefox --screenshot %s
run: cargo +${{ matrix.rust }} test --test test_wasm -- --ignored
# Code format, linting etc.
- name: Check Code Formatting
if: ${{ matrix.rust == 'stable' || matrix.rust == 'beta' }}
run: cargo +${{ matrix.rust }} fmt --all -- --check
- name: Lints
if: ${{ matrix.rust == 'stable' || matrix.rust == 'beta' }}
run: cargo +${{ matrix.rust }} clippy --target ${{ env.WASM_TARGET }} -- -D warnings
webbrowser-0.8.10/.github/workflows/windows.yaml 0000644 0000000 0000000 00000002771 10461020230 0020055 0 ustar 0000000 0000000 name: Windows
on:
push:
branches-ignore: [ '**wasm**', '**android**', '**linux**', '**bsd**', '**haiku**', '**macos**', '**ios**' ]
pull_request:
branches: [ main ]
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
RUST_LOG: webbrowser=TRACE
jobs:
build:
name: Build
runs-on: windows-latest
if: ${{ !contains(github.event.head_commit.message, '#build-') || contains(github.event.head_commit.message, '#build-windows') }}
strategy:
max-parallel: 1
matrix:
rust: [stable, beta]
continue-on-error: ${{ matrix.rust != 'stable' && matrix.rust != 'beta' }}
steps:
- uses: actions/checkout@v3
name: Checkout
- name: Install specific rust version
run: |
rustup install ${{ matrix.rust }} --profile minimal
rustup component add --toolchain ${{ matrix.rust }} rustfmt clippy
- name: Compile
run: cargo +${{ matrix.rust }} build
- name: Run Tests
run: cargo +${{ matrix.rust }} test --all --locked --verbose
- name: Run Tests (hardened)
run: cargo +${{ matrix.rust }} test --features hardened --locked --verbose --test test_windows tests::test_hardened_mode
- name: Check Code Formatting
if: ${{ matrix.rust == 'stable' || matrix.rust == 'beta' }}
run: cargo +${{ matrix.rust }} fmt --all -- --check
- name: Lints
if: ${{ matrix.rust == 'stable' || matrix.rust == 'beta' }}
run: cargo +${{ matrix.rust }} clippy --all-targets -- -D warnings
webbrowser-0.8.10/.gitignore 0000644 0000000 0000000 00000000126 10461020230 0014062 0 ustar 0000000 0000000 /target/
/Cargo.lock
/.idea/
/*.code-workspace
/screenshot.png
**/.DS_Store
/.vscode/
webbrowser-0.8.10/CHANGELOG.md 0000644 0000000 0000000 00000023772 10461020230 0013717 0 ustar 0000000 0000000 # Changelog
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
## [0.8.10] - 2023-04-12
### Changed
- Linux: move to `home` as a dependency, instead of `dirs`
## [0.8.9] - 2023-04-12
### Added
- Linux: add support for running under Flatpak sandboxes. See issue #67 and PR #70
### Fixed
- Windows: fix a bug where browser command parsing failed. See issue #68 and PR #69
## [0.8.8] - 2023-01-30
### Changed
- Android: bumped `jni` dependency version to `0.21`
## [0.8.7] - 2023-01-30
### Fixed
- Fixes a bug on WSL, when `xdg-settings` executes successfully but returns no default browser name. Thanks to [@krsh732](https://github.com/krsh732). See #64.
## [0.8.6] - 2023-01-26
### Fixed
- For Windows 32-bit, fix ABI to be used, which was broken in v0.8.5. Thanks to [@alula](https://github.com/alula). See #62 and #63.
## [0.8.5] - 2022-12-31
### Fixed
- For Windows platform, removes the `windows` crate dependency, relying on selective FFI bindings instead, thus avoiding the large dependency.
See #62. Thanks to [@Jake-Shadle](https://github.com/Jake-Shadle).
## [0.8.4] - 2022-12-31
### Fixed
- Urgent bug fix for windows, where rendering broke on Firefox & Chrome. See #60
## [0.8.3] - 2022-12-30
### Added
- Web browser is guaranteed to open for local files even if local file association was to a non-browser app (say an editor). This now is formally
incorporated as part of this crate's [Consistent Behaviour](https://github.com/amodm/webbrowser-rs/blob/main/README.md#consistent-behaviour)
- WSL support, thanks to [@Nachtalb](https://github.com/Nachtalb). This works even if `wslu` is not installed in WSL environments.
- A new feature `hardened` now available for applications which require only http(s) urls to be opened. This acts as a security feature.
### Changed
- On macOS, we now use `CoreFoundation` library instead of `open` command.
- On Linux/*BSD, we now parse xdg configuration to execute the command directly, instead of using `xdg-open` command. This allows us to open the
browser for local html files, even if the `.html` extension was associated with an edit (see #55)
### Fixed
- The guarantee of web browser being opened (instead of local file association), now solves for the scenario where the URL is crafted to be an
executable. This was reported privately by [@offalltn](https://github.com/offalltn).
## [0.8.2] - 2022-11-08
### Fixed
- Fix app crashes when running under termux on Android. See #53 and #54.
## [0.8.1] - 2022-11-01
### Fixed
- On Android, app crashes due to ndk-glue dependency. See #51 and #52. Thanks to [@rib](https://github.com/rib) for the fix.
## [0.8.0] - 2022-09-09
### Added
- Support for iOS is finally here. Thanks to [hakolao](https://github.com/hakolao) for this. See [PR #48](https://github.com/amodm/webbrowser-rs/pull/48)
### Changed
- Updated all dependencies to current versions
## [0.7.1] - 2022-04-27
### Added
- Introduce `Browser::is_available()` and `Browser::exists(&self)` to check availability of browsers without opening a URL
### Changed
- Modify `BrowserOptions` to be constructable only via the builder pattern, to prevent future API compatibility issues
## [0.7.0] - 2022-04-24
### Added
- Introduce way to provide a target hint to the browser via `BrowserOptions::target_hint` [PR #45](https://github.com/amodm/webbrowser-rs/pull/45)
### Changed
- Breaking API change for users of `BrowserOptions`. We've now shifted to a non-consuming builder pattern to avoid future breakages, as more items get added to `BrowserOptions`
## [0.6.0] - 2022-02-19
### Changed
- Define consistent non-blocking behaviour on all UNIX platforms. Now, unless it's specifically a text browser (like lynx etc.), we make sure that the browser is launched in a non-blocking way. See #18 and https://github.com/amodm/webbrowser-rs/commit/614cacf4a67ae0a75323768a1d70c16d792a760d
- Define default behaviour on all UNIX platforms to make sure that stdout/stderr are suppressed. See #20 and https://github.com/amodm/webbrowser-rs/commit/ecfbf66daa0cc139bd557bd7899a183bd6575990
- (Low probability) breaking change: All public functions now return a `Result<()>`. As almost all the uses of this library do a `.is_ok()` or equivalent, there should not be any breaks, but please report a bug if you do. See #42 and #43
- @VZout modified Android implementation to use JNI instead of `am start` because of permission issues in more recent Android.
- Define consistent behaviour for non-ascii URLs, where they're now encoded automatically before being invoked. See #34 and https://github.com/amodm/webbrowser-rs/commit/11789ddfe36264bbbe7d596ab61e3fff855c3adb
- Richer set of underlying commands used for UNIX to cater to different scenarios at runtime. See https://github.com/amodm/webbrowser-rs/commit/d09eeae4f2ab5664fc01f4dba4a409e1bc11f10e
### Fixed
- On WASM, by default URLs are opened with a target of `_blank`. See #39. Thanks to @vbeffa for pointing out the issue.
- @tokusumi fixed #41 where addition of `open` command (done for Haiku) was breaking things in some places.
## [0.5.5] - 2020-07-20
### Added
- Support for WASM [PR #26](https://github.com/amodm/webbrowser-rs/pull/26)
## [0.5.4] - 2020-06-09
### Fixed
- Fix README to reflect platform support for Android and Haiku
## [0.5.3] - 2020-06-09
### Changed
- Added support for Haiku (Untested right now!) [PR #21](https://github.com/amodm/webbrowser-rs/pull/21)
- Added support for Android [PR #19](https://github.com/amodm/webbrowser-rs/pull/19)
- Added support for kioclient and x-www-browser [PR #17](https://github.com/amodm/webbrowser-rs/pull/17)
## [0.5.2] - 2019-08-22
### Fixed
- Fix a COM leak bug on Windows [PR #15](https://github.com/amodm/webbrowser-rs/pull/15)
## [0.5.1] - 2019-04-01
### Fixed
- Fix the behaviour that open() was blocking on Linux and BSD family. [Issue #13](https://github.com/amodm/webbrowser-rs/issues/13)
- Fix tests on macos
## [0.5.0] - 2019-03-31
### Added
- Add BSD family to supported platforms. [PR #12](https://github.com/amodm/webbrowser-rs/pull/12)
## [0.4.0] - 2018-12-18
### Changed
- Use `ShellExecuteW` on Windows as the earlier approach of using cmd.exe was breaking on
special characters. [PR #11](https://github.com/amodm/webbrowser-rs/pull/11)
### Fixed
- Fixed Apache Licensing format
## [0.3.1] - 2018-06-22
### Fixed
- Fix broken examples header. [PR #7](https://github.com/amodm/webbrowser-rs/pull/7)
- Fix undeclared reference to `env` that breaks Linux. [PR #8](https://github.com/amodm/webbrowser-rs/pull/8)
## [0.3.0] - 2018-06-18
### Changed
- Change the OS test to use conditional complication and raise a compile error if the target OS is unsupported.
[PR #6](https://github.com/amodm/webbrowser-rs/pull/6)
- Implement useful trait from StdLib for Browser such as `Display`, `Default` and `FromStr`.
[PR #6](https://github.com/amodm/webbrowser-rs/pull/6)
### Fixed
- Fix the command in `open_on_windows` to use `cmd.exe` instead of `start`. [PR #5](https://github.com/amodm/webbrowser-rs/pull/5)
## [0.2.2] - 2017-01-23
### Fixed
- Honour the right syntax for `$BROWSER`. Closes [#3](https://github.com/amodm/webbrowser-rs/issues/3)
- Include `gvfs-open` and `gnome-open` for [#2](https://github.com/amodm/webbrowser-rs/issues/2)
## [0.2.1] - 2017-01-22
### Changed
- Honour `$BROWSER` env var on Linux, before choosing to fallback to `xdg-open`. [Issue #2](https://github.com/amodm/webbrowser-rs/issues/2)
## [0.1.3] - 2016-01-11
### Added
- Add Apache license [Issue #1](https://github.com/amodm/webbrowser-rs/issues/1)
## [0.1.2] - 2015-12-09
### Added
- Initial release.
[Unreleased]: https://github.com/amodm/webbrowser-rs/compare/v0.8.10...HEAD
[0.8.10]: https://github.com/amodm/webbrowser-rs/compare/v0.8.9...v0.8.10
[0.8.9]: https://github.com/amodm/webbrowser-rs/compare/v0.8.8...v0.8.9
[0.8.8]: https://github.com/amodm/webbrowser-rs/compare/v0.8.7...v0.8.8
[0.8.7]: https://github.com/amodm/webbrowser-rs/compare/v0.8.6...v0.8.7
[0.8.6]: https://github.com/amodm/webbrowser-rs/compare/v0.8.5...v0.8.6
[0.8.5]: https://github.com/amodm/webbrowser-rs/compare/v0.8.4...v0.8.5
[0.8.4]: https://github.com/amodm/webbrowser-rs/compare/v0.8.3...v0.8.4
[0.8.3]: https://github.com/amodm/webbrowser-rs/compare/v0.8.2...v0.8.3
[0.8.2]: https://github.com/amodm/webbrowser-rs/compare/v0.8.1...v0.8.2
[0.8.1]: https://github.com/amodm/webbrowser-rs/compare/v0.8.0...v0.8.1
[0.8.0]: https://github.com/amodm/webbrowser-rs/compare/v0.7.1...v0.8.0
[0.7.1]: https://github.com/amodm/webbrowser-rs/compare/v0.7.0...v0.7.1
[0.7.0]: https://github.com/amodm/webbrowser-rs/compare/v0.6.0...v0.7.0
[0.6.0]: https://github.com/amodm/webbrowser-rs/compare/v0.5.5...v0.6.0
[0.5.5]: https://github.com/amodm/webbrowser-rs/compare/v0.5.4...v0.5.5
[0.5.4]: https://github.com/amodm/webbrowser-rs/compare/v0.5.3...v0.5.4
[0.5.3]: https://github.com/amodm/webbrowser-rs/compare/v0.5.2...v0.5.3
[0.5.2]: https://github.com/amodm/webbrowser-rs/compare/v0.5.1...v0.5.2
[0.5.1]: https://github.com/amodm/webbrowser-rs/compare/v0.5.0...v0.5.1
[0.5.0]: https://github.com/amodm/webbrowser-rs/compare/v0.4.0...v0.5.0
[0.4.0]: https://github.com/amodm/webbrowser-rs/compare/v0.3.1...v0.4.0
[0.3.1]: https://github.com/amodm/webbrowser-rs/compare/v0.3.0...v0.3.1
[0.3.0]: https://github.com/amodm/webbrowser-rs/compare/v0.2.2...v0.3.0
[0.2.2]: https://github.com/amodm/webbrowser-rs/compare/v0.2.1...v0.2.2
[0.2.1]: https://github.com/amodm/webbrowser-rs/compare/v0.1.3...v0.2.1
[0.1.3]: https://github.com/amodm/webbrowser-rs/compare/v0.1.2...v0.1.3
webbrowser-0.8.10/Cargo.toml 0000644 00000004222 00000000001 0011301 0 ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies.
#
# If you are reading this file be aware that the original Cargo.toml
# will likely look very different (and much more reasonable).
# See Cargo.toml.orig for the original contents.
[package]
edition = "2018"
name = "webbrowser"
version = "0.8.10"
authors = ["Amod Malviya @amodm"]
description = "Open URLs in web browsers available on a platform"
homepage = "https://github.com/amodm/webbrowser-rs"
documentation = "https://docs.rs/webbrowser"
readme = "README.md"
keywords = [
"webbrowser",
"browser",
]
license = "MIT OR Apache-2.0"
repository = "https://github.com/amodm/webbrowser-rs"
[dependencies.log]
version = "0.4"
[dependencies.url]
version = "2"
[dev-dependencies.actix-files]
version = "0.6"
[dev-dependencies.actix-web]
version = "4"
[dev-dependencies.crossbeam-channel]
version = "0.5"
[dev-dependencies.env_logger]
version = "0.9.0"
[dev-dependencies.rand]
version = "0.8"
[dev-dependencies.serial_test]
version = "0.10"
[dev-dependencies.tokio]
version = "1"
features = ["full"]
[dev-dependencies.urlencoding]
version = "2.1"
[features]
disable-wsl = []
hardened = []
wasm-console = ["web-sys/console"]
[target."cfg(any(target_os = \"linux\", target_os = \"freebsd\", target_os = \"netbsd\", target_os = \"openbsd\", target_os = \"haiku\"))".dependencies.home]
version = "0.5"
[target."cfg(target_arch = \"wasm32\")".dependencies.web-sys]
version = "0.3"
features = ["Window"]
[target."cfg(target_os = \"android\")".dependencies.jni]
version = "0.21"
[target."cfg(target_os = \"android\")".dependencies.ndk-context]
version = "0.1"
[target."cfg(target_os = \"android\")".dev-dependencies.ndk-glue]
version = ">= 0.3, <= 0.7"
[target."cfg(target_os = \"ios\")".dependencies.objc]
version = "0.2.7"
[target."cfg(target_os = \"ios\")".dependencies.raw-window-handle]
version = "0.5.0"
[target."cfg(target_os = \"macos\")".dependencies.core-foundation]
version = "0.9"
webbrowser-0.8.10/Cargo.toml.orig 0000644 0000000 0000000 00000002461 10461020230 0014765 0 ustar 0000000 0000000 [package]
name = "webbrowser"
description = "Open URLs in web browsers available on a platform"
version = "0.8.10"
authors = ["Amod Malviya @amodm"]
documentation = "https://docs.rs/webbrowser"
homepage = "https://github.com/amodm/webbrowser-rs"
repository = "https://github.com/amodm/webbrowser-rs"
readme = "README.md"
keywords = ["webbrowser", "browser"]
license = "MIT OR Apache-2.0"
edition = "2018"
[dependencies]
log = "0.4"
url = "2"
[target.'cfg(target_arch = "wasm32")'.dependencies.web-sys]
version = "0.3"
features = ['Window']
[features]
hardened = []
disable-wsl = []
wasm-console = ["web-sys/console"]
[target.'cfg(any(target_os = "linux", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd", target_os = "haiku"))'.dependencies]
home = "0.5"
[target.'cfg(target_os = "macos")'.dependencies]
core-foundation = "0.9"
[target.'cfg(target_os = "android")'.dependencies]
jni = "0.21"
ndk-context = "0.1"
[target.'cfg(target_os = "ios")'.dependencies]
raw-window-handle = "0.5.0"
objc = "0.2.7"
[dev-dependencies]
actix-web = "4"
actix-files = "0.6"
crossbeam-channel = "0.5"
env_logger = "0.9.0"
rand = "0.8"
serial_test = "0.10"
tokio = { version = "1", features = ["full"] }
urlencoding = "2.1"
[target.'cfg(target_os = "android")'.dev-dependencies]
ndk-glue = { version = ">= 0.3, <= 0.7" }
webbrowser-0.8.10/LICENSE-APACHE 0000644 0000000 0000000 00000024053 10461020230 0014023 0 ustar 0000000 0000000 Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
Copyright (c) 2015-2022 Amod Malviya
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
webbrowser-0.8.10/LICENSE-MIT 0000644 0000000 0000000 00000002074 10461020230 0013532 0 ustar 0000000 0000000 The MIT License (MIT)
Copyright (c) 2015-2022 Amod Malviya
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.
webbrowser-0.8.10/README.md 0000644 0000000 0000000 00000007674 10461020230 0013370 0 ustar 0000000 0000000 # webbrowser
[](https://crates.io/crates/webbrowser)
[](https://crates.io/crates/webbrowser)
[](#license)






Rust library to open URLs and local files in the web browsers available on a platform, with guarantees of [Consistent Behaviour](#consistent-behaviour).
Inspired by the [webbrowser](https://docs.python.org/2/library/webbrowser.html) python library
## Documentation
- [API Reference](https://docs.rs/webbrowser)
- [Release Notes](CHANGELOG.md)
## Examples
```rust
use webbrowser;
if webbrowser::open("http://github.com").is_ok() {
// ...
}
```
## Platform Support
| Platform | Supported | Browsers | Test status |
|----------|-----------|----------|-------------|
| macos | ✅ | default + [others](https://docs.rs/webbrowser/latest/webbrowser/enum.Browser.html) | ✅ |
| windows | ✅ | default only | ✅ |
| linux/wsl/*bsd | ✅ | default only (respects $BROWSER env var, so can be used with other browsers) | ✅ |
| android | ✅ | default only | ✅ |
| ios | ✅ | default only | ✅ |
| wasm | ✅ | default only | ✅ |
| haiku | ✅ (experimental) | default only | ❌ |
## Consistent Behaviour
`webbrowser` defines consistent behaviour on all platforms as follows:
* **Browser guarantee** - This library guarantees that the browser is opened, even for local files - the only crate to make such guarantees
at the time of this writing. Alternative libraries rely on existing system commands, which may lead to an editor being opened (instead
of the browser) for local html files, leading to an inconsistent behaviour for users.
* **Non-Blocking** for GUI based browsers (e.g. Firefox, Chrome etc.), while **Blocking** for text based browser (e.g. lynx etc.)
* **Suppressed output** by default for GUI based browsers, so that their stdout/stderr don't pollute the main program's output. This can be
overridden by `webbrowser::open_browser_with_options`.
## Crate Features
`webbrowser` optionally allows the following features to be configured:
* `hardened` - this disables handling of non-http(s) urls (e.g. `file:///`) as a hard security precaution
* `disable-wsl` - this disables WSL `file` implementation (`http` still works)
* `wasm-console` - this enables logging to wasm console (valid only on wasm platform)
## Looking to contribute?
PRs invited for
* Bugs
* Supporting non-default browser invocation on any platform
Important note (while testing):
* This library requires availability of browsers and a graphical environment during runtime
* `cargo test` will actually open the browser locally
When contributing, please note that your work will be dual licensed as MIT + Apache-2.0 (see below).
## License
`SPDX-License-Identifier: Apache-2.0 OR MIT`
Licensed under either of
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
at your option.
### Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any
additional terms or conditions.
webbrowser-0.8.10/SECURITY.md 0000644 0000000 0000000 00000001050 10461020230 0013660 0 ustar 0000000 0000000 # Security Policy
If you're looking to report a security vulnerability, please go to the
[Security -> Advisories](https://github.com/amodm/webbrowser-rs/security/advisories) section, and click on
the `Report a vulnerability` button
What to expect:
* 48hr turnaround to acknowledge the issue
* The closure ETA can be varied depending on the degree of severity and complexity of resolution
* I have nothing to offer as a reward, except a virtual hug :hugs: as thanks for your selfless effort, and
acknowledging your contribution on the release notes.
webbrowser-0.8.10/clippy.toml 0000644 0000000 0000000 00000000016 10461020230 0014265 0 ustar 0000000 0000000 msrv = "1.45"
webbrowser-0.8.10/src/android.rs 0000644 0000000 0000000 00000010516 10461020230 0014653 0 ustar 0000000 0000000 use crate::{Browser, BrowserOptions, Error, ErrorKind, Result, TargetType};
use jni::objects::{JObject, JValue};
use std::process::{Command, Stdio};
/// Deal with opening of browsers on Android. Only [Browser::Default] is supported, and
/// in options, only [BrowserOptions::dry_run] is honoured.
pub(super) fn open_browser_internal(
browser: Browser,
target: &TargetType,
options: &BrowserOptions,
) -> Result<()> {
// ensure we're opening only http/https urls, failing otherwise
let url = target.get_http_url()?;
match browser {
Browser::Default => open_browser_default(url, options),
_ => Err(Error::new(
ErrorKind::NotFound,
"only default browser supported",
)),
}
}
/// Open the default browser
fn open_browser_default(url: &str, options: &BrowserOptions) -> Result<()> {
// always return true for a dry run
if options.dry_run {
return Ok(());
}
// first we try to see if we're in a termux env, because if we are, then
// the android context may not have been initialized, and it'll panic
if try_for_termux(url, options).is_ok() {
return Ok(());
}
// Create a VM for executing Java calls
let ctx = ndk_context::android_context();
let vm = unsafe { jni::JavaVM::from_raw(ctx.vm() as _) }.map_err(|_| {
Error::new(
ErrorKind::NotFound,
"Expected to find JVM via ndk_context crate",
)
})?;
let activity = unsafe { jni::objects::JObject::from_raw(ctx.context() as _) };
let mut env = vm
.attach_current_thread()
.map_err(|_| Error::new(ErrorKind::Other, "Failed to attach current thread"))?;
// Create ACTION_VIEW object
let intent_class = env
.find_class("android/content/Intent")
.map_err(|_| Error::new(ErrorKind::NotFound, "Failed to find Intent class"))?;
let action_view = env
.get_static_field(&intent_class, "ACTION_VIEW", "Ljava/lang/String;")
.map_err(|_| Error::new(ErrorKind::NotFound, "Failed to get intent.ACTION_VIEW"))?;
// Create Uri object
let uri_class = env
.find_class("android/net/Uri")
.map_err(|_| Error::new(ErrorKind::NotFound, "Failed to find Uri class"))?;
let url = env
.new_string(url)
.map_err(|_| Error::new(ErrorKind::Other, "Failed to create JNI string"))?;
let uri = env
.call_static_method(
&uri_class,
"parse",
"(Ljava/lang/String;)Landroid/net/Uri;",
&[JValue::Object(&JObject::from(url))],
)
.map_err(|_| Error::new(ErrorKind::Other, "Failed to parse JNI Uri"))?;
// Create new ACTION_VIEW intent with the uri
let intent = env
.alloc_object(&intent_class)
.map_err(|_| Error::new(ErrorKind::Other, "Failed to allocate intent"))?;
env.call_method(
&intent,
"",
"(Ljava/lang/String;Landroid/net/Uri;)V",
&[action_view.borrow(), uri.borrow()],
)
.map_err(|_| Error::new(ErrorKind::Other, "Failed to initialize intent"))?;
// Start the intent activity.
env.call_method(
&activity,
"startActivity",
"(Landroid/content/Intent;)V",
&[JValue::Object(&intent)],
)
.map_err(|_| Error::new(ErrorKind::Other, "Failed to start activity"))?;
Ok(())
}
/// Attemps to open a browser assuming a termux environment
///
/// See [issue #53](https://github.com/amodm/webbrowser-rs/issues/53)
fn try_for_termux(url: &str, options: &BrowserOptions) -> Result<()> {
use std::env;
if env::var("TERMUX_VERSION").is_ok() {
// return true on dry-run given that termux-open command is guaranteed to be present
if options.dry_run {
return Ok(());
}
let mut cmd = Command::new("termux-open");
cmd.arg(url);
if options.suppress_output {
cmd.stdin(Stdio::null())
.stdout(Stdio::null())
.stderr(Stdio::null());
}
cmd.status().and_then(|status| {
if status.success() {
Ok(())
} else {
Err(Error::new(
ErrorKind::Other,
"command present but exited unsuccessfully",
))
}
})
} else {
Err(Error::new(ErrorKind::Other, "Not a termux environment"))
}
}
webbrowser-0.8.10/src/common.rs 0000644 0000000 0000000 00000005217 10461020230 0014525 0 ustar 0000000 0000000 use super::{BrowserOptions, Error, ErrorKind, Result};
use log::debug;
use std::process::{Command, Stdio};
/// Parses `line` to find tokens (including quoted strings), and invokes `op`
/// on each token
pub(crate) fn for_each_token(line: &str, mut op: F)
where
F: FnMut(&str),
{
let mut start: Option = None;
let mut in_quotes = false;
let mut idx = 0;
for ch in line.chars() {
idx += 1;
match ch {
'"' => {
if let Some(start_idx) = start {
op(&line[start_idx..idx - 1]);
start = None;
in_quotes = false;
} else {
start = Some(idx);
in_quotes = true;
}
}
' ' => {
if !in_quotes {
if let Some(start_idx) = start {
op(&line[start_idx..idx - 1]);
start = None;
}
}
}
_ => {
if start.is_none() {
start = Some(idx - 1);
}
}
}
}
if let Some(start_idx) = start {
op(&line[start_idx..idx]);
}
}
/// Run the specified command in foreground/background
pub(crate) fn run_command(
cmd: &mut Command,
background: bool,
options: &BrowserOptions,
) -> Result<()> {
// if dry_run, we return a true, as executable existence check has
// already been done
if options.dry_run {
debug!("dry-run enabled, so not running: {:?}", &cmd);
return Ok(());
}
if background {
debug!("background spawn: {:?}", &cmd);
// if we're in background, set stdin/stdout to null and spawn a child, as we're
// not supposed to have any interaction.
if options.suppress_output {
cmd.stdin(Stdio::null())
.stdout(Stdio::null())
.stderr(Stdio::null())
} else {
cmd
}
.spawn()
.map(|_| ())
} else {
debug!("foreground exec: {:?}", &cmd);
// if we're in foreground, use status() instead of spawn(), as we'd like to wait
// till completion.
// We also specifically don't suppress anything here, because we're running here
// most likely because of a text browser
cmd.status().and_then(|status| {
if status.success() {
Ok(())
} else {
Err(Error::new(
ErrorKind::Other,
"command present but exited unsuccessfully",
))
}
})
}
}
webbrowser-0.8.10/src/ios.rs 0000644 0000000 0000000 00000002525 10461020230 0014026 0 ustar 0000000 0000000 use crate::{Browser, BrowserOptions, Error, ErrorKind, Result, TargetType};
use objc::{class, msg_send, runtime::Object, sel, sel_impl};
/// Deal with opening of browsers on iOS
pub(super) fn open_browser_internal(
_browser: Browser,
target: &TargetType,
options: &BrowserOptions,
) -> Result<()> {
// ensure we're opening only http/https urls, failing otherwise
let url = target.get_http_url()?;
// always return true for a dry run
if options.dry_run {
return Ok(());
}
unsafe {
let app: *mut Object = msg_send![class!(UIApplication), sharedApplication];
if app.is_null() {
return Err(Error::new(
ErrorKind::Other,
"UIApplication is null, can't open url",
));
}
let url_cstr = std::ffi::CString::new(url).unwrap();
// Create ns string class from our string
let url_string: *mut Object = msg_send![class!(NSString), stringWithUTF8String: url_cstr];
// Create NSURL object with given string
let url_object: *mut Object = msg_send![class!(NSURL), URLWithString: url_string];
// No completion handler
let null_ptr = std::ptr::null_mut::