Skip to content
This repository has been archived by the owner on Oct 3, 2024. It is now read-only.

Commit

Permalink
fix #573
Browse files Browse the repository at this point in the history
  • Loading branch information
wgh136 committed Jun 30, 2024
1 parent b48fb55 commit cf81c28
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 24 deletions.
8 changes: 6 additions & 2 deletions assets/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,9 @@
"首页显示单张图片": "首頁顯示單張圖片",
"要删除此项目吗?" : "要刪除此項目嗎?",
"要清空历史记录吗?" : "要清空歷史記錄嗎?",
"要清空收藏吗?" : "要清空收藏嗎?"
"要清空收藏吗?" : "要清空收藏嗎?",
"是否退出程序?" : "是否退出程序?",
"不再提示": "不再提示"
},
"en_US": {
"有可用更新": "Updates available",
Expand Down Expand Up @@ -1052,6 +1054,8 @@
"首页显示单张图片": "Show single image on first page",
"要删除此项目吗?" : "Do you want to delete this item?",
"要清空历史记录吗?" : "Do you want to clear the history?",
"要清空收藏吗?" : "Do you want to clear the favorites?"
"要清空收藏吗?" : "Do you want to clear the favorites?",
"是否退出程序?" : "Exit the program?",
"不再提示": "Do not show again"
}
}
1 change: 1 addition & 0 deletions lib/base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class Appdata {
List<String> implicitData = [
"1;;", //收藏夹状态
"0", // 双页模式下第一页显示单页
"0", // 点击关闭按钮时不显示提示
];

void writeImplicitData() async {
Expand Down
56 changes: 35 additions & 21 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import 'network/webdav.dart';

bool notFirstUse = false;

void main(){
runZonedGuarded(() async{
void main() {
runZonedGuarded(() async {
WidgetsFlutterBinding.ensureInitialized();
await init();
FlutterError.onError = (details) {
Expand All @@ -35,7 +35,7 @@ void main(){
notFirstUse = appdata.firstUse[3] == "1";
setNetworkProxy();
runApp(const MyApp());
if(App.isDesktop){
if (App.isDesktop) {
await windowManager.ensureInitialized();
windowManager.waitUntilReadyToShow().then((_) async {
await windowManager.setTitleBarStyle(
Expand Down Expand Up @@ -70,17 +70,18 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {

OverlayEntry? hideContentOverlay;

void hideContent(){
if(hideContentOverlay != null) return;
hideContentOverlay = OverlayEntry(builder: (context) => Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.width,
color: Theme.of(context).colorScheme.surface,
));
void hideContent() {
if (hideContentOverlay != null) return;
hideContentOverlay = OverlayEntry(
builder: (context) => Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.width,
color: Theme.of(context).colorScheme.surface,
));
OverlayWidget.addOverlay(hideContentOverlay!);
}

void showContent(){
void showContent() {
hideContentOverlay = null;
OverlayWidget.removeAll();
}
Expand All @@ -98,14 +99,14 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
setNetworkProxy();
scheduleMicrotask(() {
if (state == AppLifecycleState.hidden && enableAuth) {
if(!AuthPage.lock && appdata.settings[13] == "1"){
if (!AuthPage.lock && appdata.settings[13] == "1") {
AuthPage.initial = false;
AuthPage.lock = true;
App.to(App.globalContext!, () => const AuthPage());
}
}

if(state == AppLifecycleState.inactive && enableAuth) {
if (state == AppLifecycleState.inactive && enableAuth) {
hideContent();
} else if (state == AppLifecycleState.resumed) {
showContent();
Expand Down Expand Up @@ -241,11 +242,12 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
useMaterial3: true,
fontFamily: App.isWindows ? "font" : "",
),
onGenerateRoute: (settings) => AppPageRoute(builder: (context) => notFirstUse
? (appdata.settings[13] == "1"
? const AuthPage()
: const MainPage())
: const WelcomePage()),
onGenerateRoute: (settings) => AppPageRoute(
builder: (context) => notFirstUse
? (appdata.settings[13] == "1"
? const AuthPage()
: const MainPage())
: const WelcomePage()),
localizationsDelegates: const [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
Expand All @@ -268,8 +270,21 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
};
if (widget != null) {
widget = OverlayWidget(widget);
if(App.isDesktop) {
widget = WindowFrame(widget);
if (App.isDesktop) {
widget = Shortcuts(
shortcuts: {
LogicalKeySet(LogicalKeyboardKey.escape): VoidCallbackIntent(
() {
if (App.canPop) {
App.globalBack();
} else {
MainPage.back();
}
},
),
},
child: WindowFrame(widget),
);
}
return widget;
}
Expand All @@ -279,4 +294,3 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
});
}
}

45 changes: 44 additions & 1 deletion lib/views/widgets/window_frame.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:convert';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:pica_comic/base.dart';
import 'package:pica_comic/foundation/app.dart';
import 'package:pica_comic/tools/translations.dart';
import 'package:pica_comic/views/app_views/image_favorites.dart';
Expand Down Expand Up @@ -467,7 +468,49 @@ class _WindowButtonsState extends State<WindowButtons> with WindowListener{
),
hoverColor: Colors.red,
onPressed: () {
windowManager.close();
if(appdata.implicitData[2] == '0') {
showDialog(context: App.navigatorKey.currentContext!, builder: (context) {
bool isCheck = false;
return AlertDialog(
title: Text('是否退出程序?'.tl),
content: StatefulBuilder(builder: (context, setState) {
return Row(
children: [
Checkbox(
value: isCheck,
onChanged: (value) {
setState(() {
isCheck = value!;
});
},
),
Text('不再提示'.tl),
],
);
}),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text('否'.tl),
),
TextButton(
onPressed: () {
if(isCheck) {
appdata.implicitData[2] = '1';
appdata.writeImplicitData();
}
windowManager.close();
},
child: Text('是'.tl),
),
],
);
});
} else {
windowManager.close();
}
},
)
],
Expand Down

0 comments on commit cf81c28

Please sign in to comment.