Skip to content

Commit b883be6

Browse files
committed
Merge package:os_detect into the core monorepo
2 parents 279afbc + d61649d commit b883be6

20 files changed

+851
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Set update schedule for GitHub Actions
2+
# See https://docs.github.com/en/code-security/supply-chain-security/keeping-your-dependencies-updated-automatically/keeping-your-actions-up-to-date-with-dependabot
3+
4+
version: 2
5+
updates:
6+
7+
- package-ecosystem: github-actions
8+
directory: /
9+
schedule:
10+
interval: monthly
11+
labels:
12+
- autosubmit
13+
groups:
14+
github-actions:
15+
patterns:
16+
- "*"
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Dart CI
2+
3+
on:
4+
# Run on PRs and pushes to the default branch.
5+
push:
6+
branches: [ master ]
7+
pull_request:
8+
branches: [ master ]
9+
schedule:
10+
- cron: "0 0 * * 0"
11+
12+
env:
13+
PUB_ENVIRONMENT: bot.github
14+
15+
jobs:
16+
# Check code formatting and static analysis on a single OS (linux)
17+
# against Dart dev.
18+
analyze:
19+
runs-on: ubuntu-latest
20+
strategy:
21+
fail-fast: false
22+
matrix:
23+
sdk: [dev]
24+
steps:
25+
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938
26+
- uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672
27+
with:
28+
sdk: ${{ matrix.sdk }}
29+
- id: install
30+
name: Install dependencies
31+
run: dart pub get
32+
- name: Check formatting
33+
run: dart format --output=none --set-exit-if-changed .
34+
if: always() && steps.install.outcome == 'success'
35+
- name: Analyze code
36+
run: dart analyze --fatal-infos
37+
if: always() && steps.install.outcome == 'success'
38+
39+
# Run tests on a matrix consisting of two dimensions:
40+
# 1. OS: ubuntu-latest, (macos-latest, windows-latest)
41+
# 2. release channel: dev
42+
test:
43+
needs: analyze
44+
runs-on: ${{ matrix.os }}
45+
strategy:
46+
fail-fast: false
47+
matrix:
48+
# Add macos-latest and/or windows-latest if relevant for this package.
49+
os: [ubuntu-latest, windows-latest, macos-latest]
50+
sdk: [3.0.0, dev]
51+
steps:
52+
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938
53+
- uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672
54+
with:
55+
sdk: ${{ matrix.sdk }}
56+
- id: install
57+
name: Install dependencies
58+
run: dart pub get
59+
- name: Run VM tests
60+
run: dart test --platform vm
61+
if: always() && steps.install.outcome == 'success'
62+
- name: Run Chrome tests
63+
run: dart test --platform chrome
64+
if: always() && steps.install.outcome == 'success'

pkgs/os_detect/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.dart_tool/
2+
.packages
3+
pubspec.lock

pkgs/os_detect/AUTHORS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Below is a list of people and organizations that have contributed
2+
# to the Dart project. Names should be added to the list like so:
3+
#
4+
# Name/Organization <email address>
5+
6+
Google LLC

pkgs/os_detect/CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
## 2.0.2-wip
2+
3+
- Require Dart 3.0
4+
- Make work with VM's platform-constants.
5+
6+
## 2.0.1
7+
8+
- Populate the pubspec `repository` field.
9+
10+
## 2.0.0
11+
12+
- Stable null safety release.
13+
14+
## 1.0.0
15+
16+
- Initial release

pkgs/os_detect/LICENSE

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Copyright 2020, the Dart project authors.
2+
3+
Redistribution and use in source and binary forms, with or without
4+
modification, are permitted provided that the following conditions are
5+
met:
6+
7+
* Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
* Redistributions in binary form must reproduce the above
10+
copyright notice, this list of conditions and the following
11+
disclaimer in the documentation and/or other materials provided
12+
with the distribution.
13+
* Neither the name of Google LLC nor the names of its
14+
contributors may be used to endorse or promote products derived
15+
from this software without specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

pkgs/os_detect/README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
[![Build Status](https://github.com/dart-lang/os_detect/workflows/Dart%20CI/badge.svg)](https://github.com/dart-lang/os_detect/actions?query=workflow%3A"Dart+CI"+branch%3Amaster)
2+
[![pub package](https://img.shields.io/pub/v/os_detect.svg)](https://pub.dev/packages/os_detect)
3+
[![package publisher](https://img.shields.io/pub/publisher/os_detect.svg)](https://pub.dev/packages/os_detect/publisher)
4+
5+
Platform independent access to information about the current operating system.
6+
7+
## Querying the current OS
8+
9+
Exposes `operatingSystem` and `operatingSystemVersion` strings similar to those
10+
of the `Platform` class in `dart:io`, but also works on the web. The
11+
`operatingSystem` of a browser is the string "browser". Also exposes convenience
12+
getters like `isLinux`, `isAndroid` and `isBrowser` based on the
13+
`operatingSystem` string.
14+
15+
To use this package instead of `dart:io`, replace the import of `dart:io` with:
16+
17+
```dart
18+
import 'package:os_detect/os_detect.dart' as os_detect;
19+
```
20+
21+
That should keep the code working if the only functionality used from `dart:io`
22+
is operating system detection. You should then use your IDE to rename the import
23+
prefix from `Platform` to something lower-cased which follows the style guide
24+
for import prefixes.
25+
26+
Any new platform which supports neither `dart:io` nor `dart:html` can make
27+
itself recognizable by configuring the `dart.os.name` and `dart.os.version`
28+
environment settings, so that `const String.fromEnvironment` can access them.
29+
30+
## Overriding the current OS string
31+
32+
It's possible to override the current operating system string, as exposed by
33+
`operatingSystem` and `operatingSystemVersion` in
34+
`package:os_detect/os_detect.dart`. To do so, import the
35+
`package:os_detect/override.dart` library and use the `overrideOperatingSystem`
36+
function to run code in a zone where the operating system and version values are
37+
set to whatever values are desired.
38+
39+
The class `OperatingSystemID` can also be used directly to abstract over the
40+
operating system name and version. The `OperatingSystemID.current` defaults to
41+
the values provided by the platform when not overridden using
42+
`overrideOperatingSystem`.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# https://dart.dev/tools/analysis#the-analysis-options-file
2+
include: package:dart_flutter_team_lints/analysis_options.yaml
3+
4+
analyzer:
5+
language:
6+
strict-casts: true
7+
strict-inference: true
8+
strict-raw-types: true
9+
10+
linter:
11+
rules:
12+
- avoid_bool_literals_in_conditional_expressions
13+
- avoid_classes_with_only_static_members
14+
- avoid_private_typedef_functions
15+
- avoid_redundant_argument_values
16+
- avoid_returning_this
17+
- avoid_unused_constructor_parameters
18+
- avoid_void_async
19+
- literal_only_boolean_expressions
20+
- missing_whitespace_between_adjacent_strings
21+
- no_adjacent_strings_in_list
22+
- no_runtimeType_toString
23+
- package_api_docs
24+
- prefer_const_declarations
25+
- use_raw_strings
26+
27+

pkgs/os_detect/bin/os_detect.dart

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// Prints the operating system detected by the current compilation environment.
6+
library pkg.os_detect.run;
7+
8+
import 'package:os_detect/os_detect.dart' as os_detect;
9+
10+
void main() {
11+
final knownName = knownOSName();
12+
print('OS name : ${os_detect.operatingSystem} '
13+
'${knownName != null ? '($knownName)' : ''}');
14+
print('OS version : ${os_detect.operatingSystemVersion}');
15+
}
16+
17+
String? knownOSName() {
18+
if (os_detect.isAndroid) {
19+
return 'Android';
20+
}
21+
if (os_detect.isBrowser) {
22+
return 'Browser';
23+
}
24+
if (os_detect.isFuchsia) {
25+
return 'Fuchsia';
26+
}
27+
if (os_detect.isIOS) {
28+
return 'iOS';
29+
}
30+
if (os_detect.isLinux) {
31+
return 'Linux';
32+
}
33+
if (os_detect.isMacOS) {
34+
return 'MacOS';
35+
}
36+
if (os_detect.isWindows) {
37+
return 'Windows';
38+
}
39+
return null;
40+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:os_detect/os_detect.dart' as os_detect;
6+
7+
void main() {
8+
print('''
9+
OS ID: ${os_detect.operatingSystem}
10+
OS Version: ${os_detect.operatingSystemVersion}''');
11+
if (os_detect.isAndroid) {
12+
print(' OS Type: Android');
13+
} else if (os_detect.isBrowser) {
14+
print(' OS Type: Browser');
15+
} else if (os_detect.isFuchsia) {
16+
print(' OS Type: Fuchsia');
17+
} else if (os_detect.isIOS) {
18+
print(' OS Type: iOS');
19+
} else if (os_detect.isLinux) {
20+
print(' OS Type: Linux');
21+
} else if (os_detect.isMacOS) {
22+
print(' OS Type: MacOS');
23+
} else if (os_detect.isWindows) {
24+
print(' OS Type: Windows');
25+
}
26+
}

0 commit comments

Comments
 (0)