Skip to content

Commit

Permalink
feat: add startup bulletin; switch to edit mode when click text on md…
Browse files Browse the repository at this point in the history
… preview.
  • Loading branch information
debuggerx01 committed Feb 21, 2022
1 parent 49ec2a6 commit 0c87b71
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 20 deletions.
3 changes: 3 additions & 0 deletions api/lib/apis.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ class Apis {

static const appNewVersionUrl = 'https://www.debuggerx.com/2022/01/21/dgm-changelog?from=app';

static appBulletinUrl(bool isWeb) =>
'https://www.debuggerx.com/dgm_web/bulletin.json?from=app_${isWeb ? 'web' : 'linux'}';

static appManualUrl(bool isWeb) =>
'https://www.debuggerx.com/2022/01/21/dgm-manual?from=app_${isWeb ? 'web' : 'linux'}';

Expand Down
3 changes: 3 additions & 0 deletions app/3rd_party/markdown_core/lib/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class MarkdownBuilder implements md.NodeVisitor {
this.defaultTextStyle, {
this.tagTextStyle = defaultTagTextStyle,
required this.onCodeCopied,
this.richTap,
});

final _widgets = <Widget>[];
Expand All @@ -30,6 +31,7 @@ class MarkdownBuilder implements md.NodeVisitor {

final BuildContext context;
final LinkTap linkTap;
final VoidCallback? richTap;
final WidgetImage widgetImage;
final double maxWidth;
final Function onCodeCopied;
Expand Down Expand Up @@ -125,6 +127,7 @@ class MarkdownBuilder implements md.NodeVisitor {
children: last.textSpans,
style: last.textStyle,
),
onTap: richTap,
);
}
}
Expand Down
4 changes: 4 additions & 0 deletions app/3rd_party/markdown_core/lib/markdown.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Markdown extends StatefulWidget {
required this.onCodeCopied,
this.maxWidth,
this.textStyle,
this.richTap,
}) : super(key: key);

final String data;
Expand All @@ -28,6 +29,8 @@ class Markdown extends StatefulWidget {

final Function onCodeCopied;

final VoidCallback? richTap;

@override
MarkdownState createState() => MarkdownState();
}
Expand Down Expand Up @@ -62,6 +65,7 @@ class MarkdownState extends State<Markdown> {
widget.maxWidth ?? MediaQuery.of(context).size.width,
widget.textStyle ?? defaultTextStyle(context),
onCodeCopied: widget.onCodeCopied,
richTap: widget.richTap,
).build(nodes);
}
}
4 changes: 4 additions & 0 deletions app/3rd_party/markdown_editor_ot/lib/src/preview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class MdPreview extends StatefulWidget {
required this.widgetImage,
required this.onCodeCopied,
this.textStyle,
this.richTap,
}) : super(key: key);

final String text;
Expand All @@ -24,6 +25,8 @@ class MdPreview extends StatefulWidget {
/// If [onTapLink] is null,it will open the link with your default browser.
final TapLinkCallback? onTapLink;

final VoidCallback? richTap;

@override
State<StatefulWidget> createState() => MdPreviewState();
}
Expand All @@ -50,6 +53,7 @@ class MdPreviewState extends State<MdPreview>
image: widget.widgetImage,
textStyle: widget.textStyle,
onCodeCopied: widget.onCodeCopied,
richTap: widget.richTap,
);
},
),
Expand Down
3 changes: 3 additions & 0 deletions app/build_web.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ sed -i -e "s!$wasmLocation!.!" \
-e "s!https://fonts.googleapis.com/css2?family=Noto+Sans+Symbols!./assets/assets/css/Noto-Sans-Symbols.css!" \
-e "s!https://fonts.googleapis.com/css2?family=Noto+Color+Emoji+Compat!./assets/assets/css/Noto-Color-Emoji-Compat.css!" \
build/web/main.dart.js


# git init && git add . && git commit -m 'update' && git remote add origin git@github.com:debuggerx01/dgm_web.git && git push --set-upstream origin master -f
1 change: 1 addition & 0 deletions app/lib/constants/sp_keys.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ class SPKeys {
static final String accessToken = 'USER_ACCESS_TOKEN';
static final String loginEmail = 'USER_LOGIN_EMAIL';
static final String ignoredUpdateVersion = 'IGNORED_UPDATE_VERSION';
static final String readBulletinId = 'READ_BULLETIN_ID';
}
52 changes: 39 additions & 13 deletions app/lib/http/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class Api {
return res;
};

static final _fullPathRegExp = RegExp('http(s?)://');

static Future<T?> _get<T>(
String path,
BeanBuilder<T> builder, {
Expand All @@ -72,13 +74,15 @@ class Api {
}) =>
http
.get(
Uri(
scheme: Apis.apiScheme,
host: Apis.apiHost,
port: Apis.apiPort,
queryParameters: queryParams,
path: path,
),
path.startsWith(_fullPathRegExp)
? Uri.parse(path)
: Uri(
scheme: Apis.apiScheme,
host: Apis.apiHost,
port: Apis.apiPort,
queryParameters: queryParams,
path: path,
),
headers: <String, String>{
HttpHeaders.contentTypeHeader: ContentType.json.toString(),
}..addAll(
Expand All @@ -103,12 +107,14 @@ class Api {
}) =>
http
.post(
Uri(
scheme: Apis.apiScheme,
host: Apis.apiHost,
port: Apis.apiPort,
path: path,
),
path.startsWith(_fullPathRegExp)
? Uri.parse(path)
: Uri(
scheme: Apis.apiScheme,
host: Apis.apiHost,
port: Apis.apiPort,
path: path,
),
body: jsonEncode(body),
headers: <String, String>{
HttpHeaders.contentTypeHeader: ContentType.json.toString(),
Expand Down Expand Up @@ -199,6 +205,26 @@ class Api {
Apis.scheme.userLikes,
(e) => (e['list'] as List).cast<int>(),
);

static Future<AppBulletinResp?> checkBulletin(bool isWeb) => _get(
Apis.appBulletinUrl(isWeb),
AppBulletinResp.fromMap,
ignoreErrorHandle: true,
ignoreToken: true,
).catchError((_) {});
}

class AppBulletinResp {
int? id;
bool? once;
String? title;
String? content;

AppBulletinResp.fromMap(Map map)
: id = map['id'],
once = map['once'],
title = map['title'],
content = map['content'];
}

class MarketSchemeTransMetaDataResp {
Expand Down
13 changes: 13 additions & 0 deletions app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:dde_gesture_manager/themes/dark.dart';
import 'package:dde_gesture_manager/themes/light.dart';
import 'package:dde_gesture_manager/utils/helper.dart';
import 'package:dde_gesture_manager/utils/init.dart';
import 'package:dde_gesture_manager/utils/notificator.dart';
import 'package:dde_gesture_manager/utils/simple_throttle.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -89,6 +90,7 @@ class MyApp extends StatelessWidget {
Sentry.captureMessage,
timeout: const Duration(days: 1),
)?.call('App launched');
SimpleThrottle.throttledFunc(_checkBulletin, timeout: const Duration(days: 1))?.call(context);
});
return Container();
}),
Expand All @@ -112,3 +114,14 @@ void _checkAuthStatus(BuildContext context) {
H().lastCheckAuthStatusTime = DateTime.now();
}
}

void _checkBulletin(BuildContext context) {
Api.checkBulletin(kIsWeb).then((value) {
if (value != null && value.id != null) {
if (value.once == false || (H().sp.getInt(SPKeys.readBulletinId) ?? 0) < value.id!) {
Notificator.showAlert(title: value.title ?? '', description: value.content ?? '');
}
H().sp.setInt(SPKeys.readBulletinId, value.id!);
}
});
}
17 changes: 10 additions & 7 deletions app/lib/widgets/dde_markdown_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ class _DMarkdownFieldState extends State<DMarkdownField> {
super.didUpdateWidget(oldWidget);
}

VoidCallback? get _onMdPreviewTap => widget.readOnly
? null
: () {
setState(() {
_previewText = null;
});
};

@override
Widget build(BuildContext context) {
return Focus(
Expand All @@ -62,19 +70,14 @@ class _DMarkdownFieldState extends State<DMarkdownField> {
),
child: isPreview
? GestureDetector(
onTap: widget.readOnly
? null
: () {
setState(() {
_previewText = null;
});
},
onTap: _onMdPreviewTap,
child: MouseRegion(
cursor: widget.readOnly ? SystemMouseCursors.basic : SystemMouseCursors.text,
child: MdPreview(
text: _previewText ?? '',
padding: EdgeInsets.only(left: 15),
onTapLink: H.launchURL,
richTap: _onMdPreviewTap,
textStyle: context.t.textTheme.bodyText2,
onCodeCopied: () {
Notificator.success(
Expand Down
6 changes: 6 additions & 0 deletions app/web/bulletin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"id": 1,
"once": true,
"title": "欢迎",
"content": "感谢使用本工具,使用前建议先点击右下角阅读使用说明哦~"
}

0 comments on commit 0c87b71

Please sign in to comment.