Skip to content

Commit

Permalink
fix: some incompatible APIs making it unable to run on web
Browse files Browse the repository at this point in the history
  • Loading branch information
w568w committed Mar 7, 2024
1 parent beba7d2 commit d1bdaaa
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
10 changes: 8 additions & 2 deletions lib/common/constant.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,14 @@ class Constant {
/// It is used to identify the client in the HTTP request header.
/// Currently, it is used in the [OpenTreeHoleRepository] to tell the server
/// about the client version.
static String get version =>
"DanXi/${FlutterApp.versionName}b${Pubspec.version.build.single} (${Platform.operatingSystem}; ${Platform.operatingSystemVersion})";
static String get version {
if (PlatformX.isWeb) {
// web does not support [Platform] API
return "DanXi/${FlutterApp.versionName}b${Pubspec.version.build.single} (Web)";
} else {
return "DanXi/${FlutterApp.versionName}b${Pubspec.version.build.single} (${Platform.operatingSystem}; ${Platform.operatingSystemVersion})";
}
}

/// The tips to be shown as hints in the [BBSEditorWidget].
static List<String> fduHoleTips = [];
Expand Down
6 changes: 4 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright (C) 2021 DanXi-Dev
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -105,7 +105,9 @@ void main() {
SettingsProvider.getInstance().init().then((_) {
SettingsProvider.getInstance().isTagSuggestionAvailable().then((value) {
SettingsProvider.getInstance().tagSuggestionAvailable = value;
DeviceIdentity.register().then((value) {
final registerDeviceIdentity =
PlatformX.isAndroid ? DeviceIdentity.register() : Future.value();
registerDeviceIdentity.then((_) {
// This is the entrypoint of a simple Flutter app.
// runApp() is a function that takes a [Widget] and makes it the root
// of the widget tree.
Expand Down
5 changes: 5 additions & 0 deletions lib/page/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,11 @@ class HomePageState extends State<HomePage> with WidgetsBindingObserver {
}
}

// fixme: uni_links *can* handle web, but our web version could have extra path
// by default (e.g. "DanXi/" in "https://danxi.fduhole.com/DanXi/"), which
// is recognized as an invalid path by [dealWithUri] now. Improve it later.
if (PlatformX.isWeb) return;

Uri? initialUri;
initialUri = await getInitialUri();
if (initialUri != null) await dealWithUri(initialUri);
Expand Down
3 changes: 3 additions & 0 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@

<title>旦夕 Web</title>
<link rel="manifest" href="manifest.json">

<script type="application/javascript"
src="/assets/packages/flutter_inappwebview_web/assets/web/web_support.js" defer></script>
</head>

<body>
Expand Down

0 comments on commit d1bdaaa

Please sign in to comment.