Skip to content

Commit 0c87b71

Browse files
committed
feat: add startup bulletin; switch to edit mode when click text on md preview.
1 parent 49ec2a6 commit 0c87b71

10 files changed

Lines changed: 86 additions & 20 deletions

File tree

api/lib/apis.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ class Apis {
55

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

8+
static appBulletinUrl(bool isWeb) =>
9+
'https://www.debuggerx.com/dgm_web/bulletin.json?from=app_${isWeb ? 'web' : 'linux'}';
10+
811
static appManualUrl(bool isWeb) =>
912
'https://www.debuggerx.com/2022/01/21/dgm-manual?from=app_${isWeb ? 'web' : 'linux'}';
1013

app/3rd_party/markdown_core/lib/builder.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class MarkdownBuilder implements md.NodeVisitor {
1919
this.defaultTextStyle, {
2020
this.tagTextStyle = defaultTagTextStyle,
2121
required this.onCodeCopied,
22+
this.richTap,
2223
});
2324

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

3132
final BuildContext context;
3233
final LinkTap linkTap;
34+
final VoidCallback? richTap;
3335
final WidgetImage widgetImage;
3436
final double maxWidth;
3537
final Function onCodeCopied;
@@ -125,6 +127,7 @@ class MarkdownBuilder implements md.NodeVisitor {
125127
children: last.textSpans,
126128
style: last.textStyle,
127129
),
130+
onTap: richTap,
128131
);
129132
}
130133
}

app/3rd_party/markdown_core/lib/markdown.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class Markdown extends StatefulWidget {
1414
required this.onCodeCopied,
1515
this.maxWidth,
1616
this.textStyle,
17+
this.richTap,
1718
}) : super(key: key);
1819

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

2930
final Function onCodeCopied;
3031

32+
final VoidCallback? richTap;
33+
3134
@override
3235
MarkdownState createState() => MarkdownState();
3336
}
@@ -62,6 +65,7 @@ class MarkdownState extends State<Markdown> {
6265
widget.maxWidth ?? MediaQuery.of(context).size.width,
6366
widget.textStyle ?? defaultTextStyle(context),
6467
onCodeCopied: widget.onCodeCopied,
68+
richTap: widget.richTap,
6569
).build(nodes);
6670
}
6771
}

app/3rd_party/markdown_editor_ot/lib/src/preview.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class MdPreview extends StatefulWidget {
1111
required this.widgetImage,
1212
required this.onCodeCopied,
1313
this.textStyle,
14+
this.richTap,
1415
}) : super(key: key);
1516

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

28+
final VoidCallback? richTap;
29+
2730
@override
2831
State<StatefulWidget> createState() => MdPreviewState();
2932
}
@@ -50,6 +53,7 @@ class MdPreviewState extends State<MdPreview>
5053
image: widget.widgetImage,
5154
textStyle: widget.textStyle,
5255
onCodeCopied: widget.onCodeCopied,
56+
richTap: widget.richTap,
5357
);
5458
},
5559
),

app/build_web.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ sed -i -e "s!$wasmLocation!.!" \
1212
-e "s!https://fonts.googleapis.com/css2?family=Noto+Sans+Symbols!./assets/assets/css/Noto-Sans-Symbols.css!" \
1313
-e "s!https://fonts.googleapis.com/css2?family=Noto+Color+Emoji+Compat!./assets/assets/css/Noto-Color-Emoji-Compat.css!" \
1414
build/web/main.dart.js
15+
16+
17+
# 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

app/lib/constants/sp_keys.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ class SPKeys {
55
static final String accessToken = 'USER_ACCESS_TOKEN';
66
static final String loginEmail = 'USER_LOGIN_EMAIL';
77
static final String ignoredUpdateVersion = 'IGNORED_UPDATE_VERSION';
8+
static final String readBulletinId = 'READ_BULLETIN_ID';
89
}

app/lib/http/api.dart

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ class Api {
6363
return res;
6464
};
6565

66+
static final _fullPathRegExp = RegExp('http(s?)://');
67+
6668
static Future<T?> _get<T>(
6769
String path,
6870
BeanBuilder<T> builder, {
@@ -72,13 +74,15 @@ class Api {
7274
}) =>
7375
http
7476
.get(
75-
Uri(
76-
scheme: Apis.apiScheme,
77-
host: Apis.apiHost,
78-
port: Apis.apiPort,
79-
queryParameters: queryParams,
80-
path: path,
81-
),
77+
path.startsWith(_fullPathRegExp)
78+
? Uri.parse(path)
79+
: Uri(
80+
scheme: Apis.apiScheme,
81+
host: Apis.apiHost,
82+
port: Apis.apiPort,
83+
queryParameters: queryParams,
84+
path: path,
85+
),
8286
headers: <String, String>{
8387
HttpHeaders.contentTypeHeader: ContentType.json.toString(),
8488
}..addAll(
@@ -103,12 +107,14 @@ class Api {
103107
}) =>
104108
http
105109
.post(
106-
Uri(
107-
scheme: Apis.apiScheme,
108-
host: Apis.apiHost,
109-
port: Apis.apiPort,
110-
path: path,
111-
),
110+
path.startsWith(_fullPathRegExp)
111+
? Uri.parse(path)
112+
: Uri(
113+
scheme: Apis.apiScheme,
114+
host: Apis.apiHost,
115+
port: Apis.apiPort,
116+
path: path,
117+
),
112118
body: jsonEncode(body),
113119
headers: <String, String>{
114120
HttpHeaders.contentTypeHeader: ContentType.json.toString(),
@@ -199,6 +205,26 @@ class Api {
199205
Apis.scheme.userLikes,
200206
(e) => (e['list'] as List).cast<int>(),
201207
);
208+
209+
static Future<AppBulletinResp?> checkBulletin(bool isWeb) => _get(
210+
Apis.appBulletinUrl(isWeb),
211+
AppBulletinResp.fromMap,
212+
ignoreErrorHandle: true,
213+
ignoreToken: true,
214+
).catchError((_) {});
215+
}
216+
217+
class AppBulletinResp {
218+
int? id;
219+
bool? once;
220+
String? title;
221+
String? content;
222+
223+
AppBulletinResp.fromMap(Map map)
224+
: id = map['id'],
225+
once = map['once'],
226+
title = map['title'],
227+
content = map['content'];
202228
}
203229

204230
class MarketSchemeTransMetaDataResp {

app/lib/main.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import 'package:dde_gesture_manager/themes/dark.dart';
1111
import 'package:dde_gesture_manager/themes/light.dart';
1212
import 'package:dde_gesture_manager/utils/helper.dart';
1313
import 'package:dde_gesture_manager/utils/init.dart';
14+
import 'package:dde_gesture_manager/utils/notificator.dart';
1415
import 'package:dde_gesture_manager/utils/simple_throttle.dart';
1516
import 'package:flutter/foundation.dart';
1617
import 'package:flutter/material.dart';
@@ -89,6 +90,7 @@ class MyApp extends StatelessWidget {
8990
Sentry.captureMessage,
9091
timeout: const Duration(days: 1),
9192
)?.call('App launched');
93+
SimpleThrottle.throttledFunc(_checkBulletin, timeout: const Duration(days: 1))?.call(context);
9294
});
9395
return Container();
9496
}),
@@ -112,3 +114,14 @@ void _checkAuthStatus(BuildContext context) {
112114
H().lastCheckAuthStatusTime = DateTime.now();
113115
}
114116
}
117+
118+
void _checkBulletin(BuildContext context) {
119+
Api.checkBulletin(kIsWeb).then((value) {
120+
if (value != null && value.id != null) {
121+
if (value.once == false || (H().sp.getInt(SPKeys.readBulletinId) ?? 0) < value.id!) {
122+
Notificator.showAlert(title: value.title ?? '', description: value.content ?? '');
123+
}
124+
H().sp.setInt(SPKeys.readBulletinId, value.id!);
125+
}
126+
});
127+
}

app/lib/widgets/dde_markdown_field.dart

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ class _DMarkdownFieldState extends State<DMarkdownField> {
4646
super.didUpdateWidget(oldWidget);
4747
}
4848

49+
VoidCallback? get _onMdPreviewTap => widget.readOnly
50+
? null
51+
: () {
52+
setState(() {
53+
_previewText = null;
54+
});
55+
};
56+
4957
@override
5058
Widget build(BuildContext context) {
5159
return Focus(
@@ -62,19 +70,14 @@ class _DMarkdownFieldState extends State<DMarkdownField> {
6270
),
6371
child: isPreview
6472
? GestureDetector(
65-
onTap: widget.readOnly
66-
? null
67-
: () {
68-
setState(() {
69-
_previewText = null;
70-
});
71-
},
73+
onTap: _onMdPreviewTap,
7274
child: MouseRegion(
7375
cursor: widget.readOnly ? SystemMouseCursors.basic : SystemMouseCursors.text,
7476
child: MdPreview(
7577
text: _previewText ?? '',
7678
padding: EdgeInsets.only(left: 15),
7779
onTapLink: H.launchURL,
80+
richTap: _onMdPreviewTap,
7881
textStyle: context.t.textTheme.bodyText2,
7982
onCodeCopied: () {
8083
Notificator.success(

app/web/bulletin.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"id": 1,
3+
"once": true,
4+
"title": "欢迎",
5+
"content": "感谢使用本工具,使用前建议先点击右下角阅读使用说明哦~"
6+
}

0 commit comments

Comments
 (0)