Skip to content

Commit

Permalink
4.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
PlugFox committed Jun 30, 2023
1 parent 5ca5a9b commit 52c24c9
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 115 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 4.0.1 - 2023-06-30

- Update README.md
- Refactoring

## 4.0.0 - 2023-05-13

### Changed
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ analyze: get format
@dart analyze --fatal-infos --fatal-warnings

check: analyze
@dart pub publish --dry-run
@dart pub global activate pana
@pana --json --no-warning --line-length 80 > log.pana.json

pana: check

deploy:
@echo "Publish"
@dart pub publish
Expand All @@ -37,3 +40,6 @@ coverage: get
# @mv coverage/lcov.base.info coverage/lcov.info
@lcov --list coverage/lcov.info
@genhtml -o coverage coverage/lcov.info

test: get
@dart test --debug --coverage=.coverage --platform chrome,vm
55 changes: 15 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# platform_info

[![](https://github.com/PlugFox/platform_info/raw/master/.img/logo.png)](https://github.com/PlugFox/platform_info)

[![platform_info](https://img.shields.io/pub/v/platform_info.svg)](https://pub.dev/packages/platform_info)
[![Actions Status](https://github.com/PlugFox/platform_info/actions/workflows/checkout.yml/badge.svg)](https://github.com/PlugFox/platform_info/actions)
[![Checkout](https://github.com/PlugFox/platform_info/actions/workflows/checkout.yml/badge.svg)](https://github.com/PlugFox/platform_info/actions/workflows/checkout.yml)
[![Coverage](https://codecov.io/gh/PlugFox/platform_info/branch/master/graph/badge.svg)](https://codecov.io/gh/PlugFox/platform_info)
[![License: MIT](https://img.shields.io/badge/license-MIT-purple.svg)](https://opensource.org/licenses/MIT)
[![Linter](https://img.shields.io/badge/style-effective_dart-40c4ff.svg)](https://github.com/tenhobi/effective_dart)
[![Linter](https://img.shields.io/badge/style-linter-40c4ff.svg)](https://pub.dev/packages/linter)
[![GitHub stars](https://img.shields.io/github/stars/plugfox/platform_info?style=social)](https://github.com/plugfox/platform_info/)

## About

Expand Down Expand Up @@ -79,7 +78,7 @@ Provides platform information such as:

- `when` method allowing to compose a complex condition

## platform.when
## Pattern matching

Run functions that satisfy the current state of the platform.
You can use nested methods to compose more complex queries.
Expand Down Expand Up @@ -127,59 +126,35 @@ You can use nested methods to compose more complex queries.

## For example

```dart
import 'package:platform_info/platform_info.dart';
void main(List<String> args) {
// Use [Platform.instance] or [Platform.I] or [platform] getter
print(Platform.instance.version);
print(Platform.I.operatingSystem);
print(platform.numberOfProcessors.gcd(1));
final string = platform.when(
io: () => platform.when(
fuchsia: () => 'io fuchsia',
windows: () => 'io windows',
android: () => 'io android',
iOS: () => 'io iOS',
macOS: () => 'io macOS',
linux: () => 'io linux',
unknown: () => 'io unknown',
),
web: () => platform.when(
material: () => 'web Android or Fuchsia',
cupertino: () => 'web macOS or iOS',
orElse: () => 'web Windows or Linux or unknown',
),
);
print(string);
}
```
![](example.png)
[Example of using the library](https://pub.dev/packages/platform_info/example) to get the current platform info

## Coverage

[![](https://codecov.io/gh/PlugFox/platform_info/branch/master/graphs/sunburst.svg)](https://codecov.io/gh/PlugFox/platform_info/branch/master)

---

## Changelog

Refer to the [Changelog](https://github.com/plugfox/platform_info/blob/master/CHANGELOG.md) to get all release notes.

---

## Maintainers

[Plague Fox](https://plugfox.dev)

---
## Funding

If you want to support the development of our library, there are several ways you can do it:

- [Buy me a coffee](https://www.buymeacoffee.com/plugfox)
- [Support on Patreon](https://www.patreon.com/plugfox)
- [Subscribe through Boosty](https://boosty.to/plugfox)

We appreciate any form of support, whether it's a financial donation or just a star on GitHub. It helps us to continue developing and improving our library. Thank you for your support!

## License

[MIT](https://opensource.org/licenses/MIT)

---

## Tags

cross, platform, info
Binary file added example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 28 additions & 19 deletions example/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,33 @@ void main(List<String> args) {
// Use [Platform.instance] or [Platform.I] or [platform] getter
print(Platform.instance.version);
print(Platform.I.operatingSystem);
print(platform.numberOfProcessors.gcd(1));
print(platform.numberOfProcessors);

final string = platform.when(
io: () => platform.when(
fuchsia: () => 'io fuchsia',
windows: () => 'io windows',
android: () => 'io android',
iOS: () => 'io iOS',
macOS: () => 'io macOS',
linux: () => 'io linux',
unknown: () => 'io unknown',
),
web: () => platform.when(
material: () => 'web Android or Fuchsia',
cupertino: () => 'web macOS or iOS',
orElse: () => 'web Windows or Linux or unknown',
),
) ??
'<unknown platform>';
print(string);
final design = platform.when<String?>(
io: () => platform.when<String>(
material: () => 'Android or Fuchsia',
cupertino: () => 'macOS or iOS',
orElse: () => 'Windows or Linux',
),
web: () => 'Web',
);
print(design);

final operatingSystem = switch (platform.operatingSystem) {
OperatingSystem.android => 'Android',
OperatingSystem.fuchsia => 'Fuchsia',
OperatingSystem.iOS => 'iOS',
OperatingSystem.linux => 'Linux',
OperatingSystem.macOS => 'macOS',
OperatingSystem.windows => 'Windows',
OperatingSystem.unknown => 'Unknown',
};
print(operatingSystem);

final buildMode = switch (platform.buildMode) {
BuildMode.debug => 'Debug',
BuildMode.profile => 'Profile',
BuildMode.release => 'Release',
};
print(buildMode);
}
31 changes: 19 additions & 12 deletions lib/src/constants.dart
Original file line number Diff line number Diff line change
@@ -1,32 +1,39 @@
import 'package:meta/meta.dart';

import 'base_host_platform.dart' show HostPlatform;
import 'default_host_platform.dart';
import 'enums.dart';

/// List of all mobile phone operating systems
const List<OperatingSystem> kListOSForMobile = <OperatingSystem>[
/// Set of all mobile phone operating systems
@internal
const Set<OperatingSystem> kListOSForMobile = <OperatingSystem>{
OperatingSystem.android,
OperatingSystem.iOS,
];
};

/// List of all operating systems with material design
const List<OperatingSystem> kListOSWithMaterialDesign = <OperatingSystem>[
/// Set of all operating systems with material design
@internal
const Set<OperatingSystem> kListOSWithMaterialDesign = <OperatingSystem>{
OperatingSystem.android,
OperatingSystem.fuchsia,
];
};

/// List of all operating systems with cupertino design
const List<OperatingSystem> kListOSWithCupertinoDesign = <OperatingSystem>[
/// Set of all operating systems with cupertino design
@internal
const Set<OperatingSystem> kListOSWithCupertinoDesign = <OperatingSystem>{
OperatingSystem.macOS,
OperatingSystem.iOS,
];
};

/// List of all desktop operating systems
const List<OperatingSystem> kListOSForDesktop = <OperatingSystem>[
/// Set of all desktop operating systems
@internal
const Set<OperatingSystem> kListOSForDesktop = <OperatingSystem>{
OperatingSystem.windows,
OperatingSystem.macOS,
OperatingSystem.fuchsia,
OperatingSystem.linux,
];
};

/// Unknown host platform with default values
@internal
const HostPlatform kDefaultHostPlatform = DefaultHostPlatform();
46 changes: 16 additions & 30 deletions lib/src/enums.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,12 @@ enum BuildMode {
required BuildModeResult Function() release,
required BuildModeResult Function() profile,
required BuildModeResult Function() debug,
}) {
switch (this) {
case BuildMode.profile:
return profile();
case BuildMode.debug:
return debug();
case BuildMode.release:
default:
return release();
}
}
}) =>
switch (this) {
BuildMode.profile => profile(),
BuildMode.debug => debug(),
BuildMode.release => release(),
};

/// Run callback on specific build mode,
/// if not specified run orElse
Expand Down Expand Up @@ -149,25 +144,16 @@ enum OperatingSystem {
required OperatingSystemResult Function() macOS,
required OperatingSystemResult Function() windows,
required OperatingSystemResult Function() unknown,
}) {
switch (this) {
case OperatingSystem.windows:
return windows();
case OperatingSystem.linux:
return linux();
case OperatingSystem.macOS:
return macOS();
case OperatingSystem.iOS:
return iOS();
case OperatingSystem.android:
return android();
case OperatingSystem.fuchsia:
return fuchsia();
case OperatingSystem.unknown:
default:
return unknown();
}
}
}) =>
switch (this) {
OperatingSystem.android => android(),
OperatingSystem.fuchsia => fuchsia(),
OperatingSystem.iOS => iOS(),
OperatingSystem.linux => linux(),
OperatingSystem.macOS => macOS(),
OperatingSystem.windows => windows(),
OperatingSystem.unknown => unknown(),
};

/// Run callback on specific operation system,
/// if not specified run orElse
Expand Down
18 changes: 6 additions & 12 deletions lib/src/io_host_platform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,13 @@ final class _HostPlatform$IO extends HostPlatform {
return kDefaultHostPlatform.operatingSystem;
}

static String _getVersion() {
if (_isKnownEnvironment) {
return io.Platform.operatingSystemVersion;
}
return kDefaultHostPlatform.version;
}
static String _getVersion() => _isKnownEnvironment
? io.Platform.operatingSystemVersion
: kDefaultHostPlatform.version;

static int _numberOfProcessors() {
if (_isKnownEnvironment) {
return io.Platform.numberOfProcessors;
}
return kDefaultHostPlatform.numberOfProcessors;
}
static int _numberOfProcessors() => _isKnownEnvironment
? io.Platform.numberOfProcessors
: kDefaultHostPlatform.numberOfProcessors;

static String _getLocale() {
final lang = io.Platform.localeName
Expand Down
27 changes: 25 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,43 @@ name: platform_info
description: >
Contains info about current platform
such as Build mode and Operating system.
version: 4.0.0
version: 4.0.1
repository: https://github.com/PlugFox/platform_info/tree/master
issue_tracker: https://github.com/PlugFox/platform_info/issues
homepage: https://github.com/PlugFox/platform_info
#author: Plague Fox <plugfox@gmail.com>
#documentation: https://pub.dev/documentation/platform_info/latest

funding:
- https://www.buymeacoffee.com/plugfox
- https://www.patreon.com/plugfox
- https://boosty.to/plugfox

topics:
- ws
- websocket
- cross-platform
- reconnect
- socket

platforms:
android:
ios:
linux:
macos:
web:
windows:

screenshots:
- description: 'Example of using the library to get the current platform info'
path: example.png

environment:
sdk: '>=3.0.0 <4.0.0'

dependencies:
meta: ^1.9.1

dev_dependencies:
coverage: ^1.2.0
lints: ^2.0.1
test: ^1.24.2

1 comment on commit 52c24c9

@vercel
Copy link

@vercel vercel bot commented on 52c24c9 Jun 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

platform-info – ./

platform-info-plugfox.vercel.app
platform-info-git-master-plugfox.vercel.app
platform-info.vercel.app

Please sign in to comment.