Skip to content

Commit

Permalink
feat: 🎸 add version check
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Jan 5, 2024
1 parent c182711 commit 6f517ee
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"dependencies": {
"axios": "^1.6.0",
"bignumber.js": "^9.0.1",
"dayjs": "^1.10.4"
"dayjs": "^1.10.4",
"semver": "^7.5.4"
}
}
29 changes: 29 additions & 0 deletions packages/utils/src/mixin.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { gte } from "semver";

export function getMixinContext() {
let ctx: any = {};
const win: any = window;
Expand All @@ -19,6 +21,33 @@ export function isMixin() {
return platform === "iOS" || platform === "Android";
}

export function getFallbackMixinContext() {
const ua = navigator.userAgent;
const platform = /iPhone/i.test(ua)
? "iOS"
: isMixin()
? "Android"
: undefined;
const appVersion =
/Mixin\/(?<version>[\d | .]+)/.exec(ua)?.groups?.version ?? undefined;

return { app_version: appVersion, platform };
}

export function checkMixinVersion(supportVersion: {
Android?: string;
iOS?: string;
}) {
const mixinContext = getMixinContext();
const fallbackMixinContext = getFallbackMixinContext();
const platform =
(mixinContext?.platform || fallbackMixinContext.platform) ?? "";
const appVersion =
(mixinContext?.app_version || fallbackMixinContext.app_version) ?? "0.0.0";

return gte(appVersion, supportVersion[platform]);
}

export function setMixinTheme(color: string) {
document
.querySelectorAll("[name='theme-color']")
Expand Down
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1555,6 +1555,7 @@ __metadata:
axios: ^1.6.0
bignumber.js: ^9.0.1
dayjs: ^1.10.4
semver: ^7.5.4
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -9407,6 +9408,17 @@ resolve@^2.0.0-next.3:
languageName: node
linkType: hard

"semver@npm:^7.5.4":
version: 7.5.4
resolution: "semver@npm:7.5.4"
dependencies:
lru-cache: ^6.0.0
bin:
semver: bin/semver.js
checksum: 9bc02fd8e2b3c9e5dea66f0d733a3c801c67f3c7f0190efa03112a7b516e39845456ae107214d7972c4be9c67bbc50c0f27bbaf49a79a0234de83717cdaf2058
languageName: node
linkType: hard

"set-blocking@npm:^2.0.0, set-blocking@npm:~2.0.0":
version: 2.0.0
resolution: "set-blocking@npm:2.0.0"
Expand Down

0 comments on commit 6f517ee

Please sign in to comment.