new: hideTitlebar & cupertinoRoute

This commit is contained in:
lollipopkit
2024-04-08 23:43:24 +08:00
parent 7d2fbde2fe
commit 4fd82afade
19 changed files with 93 additions and 29 deletions

View File

@@ -1,7 +1,9 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:toolbox/core/analysis.dart';
import 'package:toolbox/data/model/server/private_key_info.dart';
import 'package:toolbox/data/model/server/server_private_info.dart';
import 'package:toolbox/data/res/store.dart';
import 'package:toolbox/view/page/backup.dart';
import 'package:toolbox/view/page/container.dart';
import 'package:toolbox/view/page/home/home.dart';
@@ -43,7 +45,9 @@ class AppRoute {
Analysis.recordView(title);
return Navigator.push<T>(
context,
MaterialPageRoute(builder: (context) => page),
Stores.setting.cupertinoRoute.fetch()
? CupertinoPageRoute(builder: (context) => page)
: MaterialPageRoute(builder: (context) => page),
);
}

View File

@@ -67,15 +67,21 @@ class Cpus extends TimeSeq<List<SingleCpuCore>> {
double get idle => _idle;
double _getIdle() => 100 - usedPercent();
void _coresLoop(void Function(int i) callback) {
/// Only update the entire core when [coresCount] > 4, or the chart will be too crowded
final onlyCalcSingle = coresCount > 4;
final maxIdx = onlyCalcSingle ? 1 : coresCount;
for (var i = onlyCalcSingle ? 0 : 1; i < maxIdx; i++) {
callback(i);
}
}
/// [core1, core2]
/// core1: [FlSpot(0, 10), FlSpot(1, 20), FlSpot(2, 30)]
final _spots = <Fifo<FlSpot>>[];
List<Fifo<FlSpot>> get spots => _spots;
void _updateSpots() {
/// Only update the entire core when [coresCount] > 4, or the chart will be too crowded
final onlyCalcSingle = coresCount > 4;
final maxIdx = onlyCalcSingle ? 1 : coresCount;
for (var i = onlyCalcSingle ? 0 : 1; i < maxIdx; i++) {
_coresLoop((i) {
if (i >= _spots.length) {
_spots.add(Fifo(capacity: _kCap));
} else {
@@ -83,7 +89,7 @@ class Cpus extends TimeSeq<List<SingleCpuCore>> {
final spot = FlSpot(item.count.toDouble(), usedPercent(coreIdx: i));
item.add(spot);
}
}
});
}
var _rangeX = Range<double>(0.0, _kCap.toDouble());
@@ -91,16 +97,17 @@ class Cpus extends TimeSeq<List<SingleCpuCore>> {
// var _rangeY = Range<double>(0.0, 100.0);
// Range<double> get rangeY => _rangeY;
void _updateRange() {
double? minX, maxX;
for (var i = 1; i < now.length; i++) {
final item = _spots[i];
if (item.isEmpty) continue;
final first = item.first.x;
final last = item.last.x;
if (minX == null || first < minX) minX = first;
if (maxX == null || last > maxX) maxX = last;
}
if (minX != null && maxX != null) _rangeX = Range(minX, maxX);
double minX = 0;
double maxX = 0;
_coresLoop((i) {
final fifo = _spots[i];
if (fifo.isEmpty) return;
final first = fifo.first.x;
final last = fifo.last.x;
if (first > minX) minX = first;
if (last > maxX) maxX = last;
});
_rangeX = Range(minX, maxX);
// double? minY, maxY;
// for (var i = 1; i < now.length; i++) {

View File

@@ -256,6 +256,12 @@ class SettingStore extends PersistentStore {
late final lastVer = property('lastVer', 0);
/// Use CupertinoPageRoute for all routes
late final cupertinoRoute = property('cupertinoRoute', isIOS);
/// Hide title bar on desktop
late final hideTitleBar = property('hideTitleBar', isDesktop);
// Never show these settings for users
//
// ------BEGIN------

View File

@@ -113,6 +113,7 @@
"gettingToken": "Getting token...",
"goBackQ": "Zurückkommen?",
"goto": "Pfad öffnen",
"hideTitleBar": "Titelleiste ausblenden",
"highlight": "Code highlight",
"homeWidgetUrlConfig": "Home-Widget-Link konfigurieren",
"host": "Host",
@@ -221,6 +222,7 @@
"restoreSuccess": "Wiederherstellung erfolgreich. App neustarten um Änderungen anzuwenden.",
"result": "Result",
"rotateAngel": "Rotationswinkel",
"route": "Routen",
"run": "Ausführen",
"running": "läuft",
"save": "Speichern",

View File

@@ -113,6 +113,7 @@
"gettingToken": "Getting token...",
"goBackQ": "Go back?",
"goto": "Go to",
"hideTitleBar": "Hide title bar",
"highlight": "Code highlight",
"homeWidgetUrlConfig": "Config home widget url",
"host": "Host",
@@ -221,6 +222,7 @@
"restoreSuccess": "Restore success. Restart app to apply.",
"result": "Result",
"rotateAngel": "Rotation angle",
"route": "Routing",
"run": "Run",
"running": "Running",
"save": "Save",

View File

@@ -113,6 +113,7 @@
"gettingToken": "Obteniendo Token...",
"goBackQ": "¿Regresar?",
"goto": "Ir a",
"hideTitleBar": "Ocultar barra de título",
"highlight": "Resaltar código",
"homeWidgetUrlConfig": "Configuración de URL del widget de inicio",
"host": "Anfitrión",
@@ -221,6 +222,7 @@
"restoreSuccess": "Restauración exitosa, necesitas reiniciar la App para aplicar cambios",
"result": "Resultado",
"rotateAngel": "Ángulo de rotación",
"route": "Enrutamiento",
"run": "Ejecutar",
"running": "En ejecución",
"save": "Guardar",

View File

@@ -113,6 +113,7 @@
"gettingToken": "Récupération du jeton...",
"goBackQ": "Revenir en arrière ?",
"goto": "Aller à",
"hideTitleBar": "Masquer la barre de titre",
"highlight": "Coloration syntaxique",
"homeWidgetUrlConfig": "Configurer l'URL du widget d'accueil",
"host": "Hôte",
@@ -221,6 +222,7 @@
"restoreSuccess": "Restauration réussie. Redémarrez l'application pour l'appliquer.",
"result": "Résultat",
"rotateAngel": "Angle de rotation",
"route": "Routage",
"run": "Exécuter",
"running": "en cours d'exécution",
"save": "Enregistrer",

View File

@@ -113,6 +113,7 @@
"gettingToken": "Mendapatkan token ...",
"goBackQ": "Datang kembali?",
"goto": "Pergi ke",
"hideTitleBar": "Sembunyikan bilah judul",
"highlight": "Sorotan kode",
"homeWidgetUrlConfig": "Konfigurasi URL Widget Rumah",
"host": "Host",
@@ -221,6 +222,7 @@
"restoreSuccess": "Kembalikan kesuksesan. Mulai ulang aplikasi untuk diterapkan.",
"result": "Hasil",
"rotateAngel": "Sudut rotasi",
"route": "Routing",
"run": "Berlari",
"running": "berlari",
"save": "Menyimpan",

View File

@@ -113,6 +113,7 @@
"gettingToken": "トークンを取得しています...",
"goBackQ": "戻りますか?",
"goto": "移動",
"hideTitleBar": "タイトルバーを非表示にする",
"highlight": "コードハイライト",
"homeWidgetUrlConfig": "ホームウィジェットURL設定",
"host": "ホスト",
@@ -221,6 +222,7 @@
"restoreSuccess": "復元に成功しました。変更を適用するためにアプリを再起動する必要があります",
"result": "結果",
"rotateAngel": "回転角度",
"route": "ルーティング",
"run": "実行",
"running": "実行中",
"save": "保存",

View File

@@ -113,6 +113,7 @@
"gettingToken": "Obtendo Token...",
"goBackQ": "Voltar?",
"goto": "Ir para",
"hideTitleBar": "Ocultar barra de título",
"highlight": "Destaque de código",
"homeWidgetUrlConfig": "Configuração de URL do widget da tela inicial",
"host": "Host",
@@ -221,6 +222,7 @@
"restoreSuccess": "Restauração bem-sucedida, é necessário reiniciar o app para aplicar as mudanças",
"result": "Resultado",
"rotateAngel": "Ângulo de rotação",
"route": "Roteamento",
"run": "Executar",
"running": "Executando",
"save": "Salvar",

View File

@@ -113,6 +113,7 @@
"gettingToken": "Получение токена...",
"goBackQ": "Вернуться?",
"goto": "перейти к",
"hideTitleBar": "Скрыть заголовок",
"highlight": "подсветка кода",
"homeWidgetUrlConfig": "конфигурация URL виджета домашнего экрана",
"host": "хост",
@@ -221,6 +222,7 @@
"restoreSuccess": "Восстановление успешно, требуется перезапуск приложения для применения изменений",
"result": "результат",
"rotateAngel": "угол поворота",
"route": "Маршрутизация",
"run": "запустить",
"running": "работает",
"save": "сохранить",

View File

@@ -113,6 +113,7 @@
"gettingToken": "正在获取Token...",
"goBackQ": "返回?",
"goto": "前往",
"hideTitleBar": "隐藏标题栏",
"highlight": "代码高亮",
"homeWidgetUrlConfig": "桌面部件链接配置",
"host": "主机",
@@ -221,6 +222,7 @@
"restoreSuccess": "恢复成功需要重启App来应用更改",
"result": "结果",
"rotateAngel": "旋转角度",
"route": "路由",
"run": "运行",
"running": "运行中",
"save": "保存",

View File

@@ -113,6 +113,7 @@
"gettingToken": "正在獲取Token...",
"goBackQ": "返回?",
"goto": "前往",
"hideTitleBar": "隱藏標題欄",
"highlight": "代碼高亮",
"homeWidgetUrlConfig": "桌面部件鏈接配置",
"host": "主機",
@@ -221,6 +222,7 @@
"restoreSuccess": "恢復成功需要重啓App來應用更改",
"result": "結果",
"rotateAngel": "旋轉角度",
"route": "路由",
"run": "運行",
"running": "運作中",
"save": "保存",

View File

@@ -142,11 +142,11 @@ Future<void> _initDesktopWindow() async {
await windowManager.ensureInitialized();
await CustomAppBar.updateTitlebarHeight();
const windowOptions = WindowOptions(
final windowOptions = WindowOptions(
center: true,
backgroundColor: Colors.transparent,
skipTaskbar: false,
titleBarStyle: TitleBarStyle.hidden,
titleBarStyle: CustomAppBar.barHeight != 0 ? TitleBarStyle.hidden : null,
);
windowManager.waitUntilReadyToShow(windowOptions, () async {
await windowManager.show();

View File

@@ -31,7 +31,6 @@ import 'package:toolbox/view/widget/appbar.dart';
import 'package:toolbox/view/widget/cardx.dart';
import 'package:toolbox/view/widget/markdown.dart';
part 'appbar.dart';
class HomePage extends StatefulWidget {
@@ -332,6 +331,7 @@ ${GithubIds.participants.map((e) => '[$e](${e.url})').join(' ')}
}
Future<void> _reqNotiPerm() async {
if (!isAndroid) return;
final suc = await PermUtils.request(Permission.notification);
if (!suc) {
final noNotiPerm = Stores.setting.noNotiPerm;

View File

@@ -42,13 +42,13 @@ Widget _buildLineChart(
Range<double> x, {
String? tooltipPrefix,
bool curve = false,
int verticalInterval = 20,
}) {
return LineChart(LineChartData(
lineTouchData: LineTouchData(
touchTooltipData: LineTouchTooltipData(
tooltipPadding: const EdgeInsets.all(5),
tooltipRoundedRadius: 8,
tooltipMargin: 3,
getTooltipItems: (List<LineBarSpot> touchedSpots) {
return touchedSpots.map((e) {
return LineTooltipItem(
@@ -66,11 +66,12 @@ Widget _buildLineChart(
gridData: FlGridData(
show: true,
drawVerticalLine: false,
horizontalInterval: 20,
horizontalInterval: verticalInterval.toDouble(),
getDrawingHorizontalLine: (value) {
return const FlLine(
color: Color(0xff37434d),
strokeWidth: 1,
dashArray: [5, 17],
);
},
),
@@ -90,21 +91,22 @@ Widget _buildLineChart(
showTitles: true,
interval: 1,
getTitlesWidget: (val, meta) {
if (val % 20 != 0) return UIs.placeholder;
if (val % verticalInterval != 0) return UIs.placeholder;
if (val == 0) return const Text('0 %', style: UIs.text12Grey);
return Text(
val.toInt().toString(),
style: UIs.text12Grey,
);
},
reservedSize: 42,
reservedSize: 27,
),
),
),
borderData: FlBorderData(show: false),
minX: x.start,
maxX: x.end,
minY: 0,
maxY: 100,
minY: -1,
maxY: 101,
lineBarsData: spots
.map((e) => LineChartBarData(
spots: e,

View File

@@ -186,7 +186,7 @@ class _ServerDetailPageState extends State<ServerDetailPage>
),
),
childrenPadding: const EdgeInsets.symmetric(vertical: 13),
initiallyExpanded: true,
initiallyExpanded: _getInitExpand(1),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: details,
@@ -201,7 +201,6 @@ class _ServerDetailPageState extends State<ServerDetailPage>
ss.cpu.spots,
ss.cpu.rangeX,
tooltipPrefix: 'CPU',
curve: true,
),
),
),

View File

@@ -119,7 +119,7 @@ class _SettingPageState extends State<SettingPage> {
_buildAppColor(),
//_buildLaunchPage(),
_buildCheckUpdate(),
_buildCollapseUI(),
_buildAppMore(),
];
/// Platform specific settings
@@ -1065,4 +1065,29 @@ class _SettingPageState extends State<SettingPage> {
},
);
}
Widget _buildAppMore() {
return ExpandTile(
title: Text(l10n.more),
children: [
_buildCollapseUI(),
_buildCupertinoRoute(),
if (isDesktop) _buildHideTitleBar(),
],
);
}
Widget _buildCupertinoRoute() {
return ListTile(
title: Text('Cupertino ${l10n.route}'),
trailing: StoreSwitch(prop: _setting.cupertinoRoute),
);
}
Widget _buildHideTitleBar() {
return ListTile(
title: Text(l10n.hideTitleBar),
trailing: StoreSwitch(prop: _setting.hideTitleBar),
);
}
}

View File

@@ -1,6 +1,7 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:toolbox/data/res/store.dart';
import 'package:window_manager/window_manager.dart';
class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
@@ -84,8 +85,8 @@ class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
case 'macos':
barHeight = 27;
break;
// Draw a titlebar on Linux
case 'linux' || 'windows':
if (!Stores.setting.hideTitleBar.fetch()) break;
barHeight = 37;
_drawTitlebar = true;
break;