mirror of
https://github.com/lollipopkit/flutter_server_box.git
synced 2026-02-01 05:45:04 +01:00
new: custom tabs (#889)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'package:fl_lib/fl_lib.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hive_ce_flutter/adapters.dart';
|
||||
import 'package:icons_plus/icons_plus.dart';
|
||||
import 'package:server_box/core/extension/context/locale.dart';
|
||||
import 'package:server_box/view/page/server/tab/tab.dart';
|
||||
@@ -8,10 +9,17 @@ import 'package:server_box/view/page/snippet/list.dart';
|
||||
import 'package:server_box/view/page/ssh/tab.dart';
|
||||
import 'package:server_box/view/page/storage/local.dart';
|
||||
|
||||
part 'tab.g.dart';
|
||||
|
||||
@HiveType(typeId: 103)
|
||||
enum AppTab {
|
||||
@HiveField(0)
|
||||
server,
|
||||
@HiveField(1)
|
||||
ssh,
|
||||
@HiveField(2)
|
||||
file,
|
||||
@HiveField(3)
|
||||
snippet
|
||||
//settings,
|
||||
;
|
||||
@@ -93,4 +101,35 @@ enum AppTab {
|
||||
static List<NavigationRailDestination> get navRailDestinations {
|
||||
return AppTab.values.map((e) => e.navRailDestination).toList();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// Helper function to parse AppTab list from stored object
|
||||
static List<AppTab> parseAppTabsFromObj(dynamic val) {
|
||||
if (val is List) {
|
||||
final tabs = <AppTab>[];
|
||||
for (final e in val) {
|
||||
final tab = _parseAppTabFromElement(e);
|
||||
if (tab != null) {
|
||||
tabs.add(tab);
|
||||
}
|
||||
}
|
||||
if (tabs.isNotEmpty) return tabs;
|
||||
}
|
||||
return AppTab.values;
|
||||
}
|
||||
|
||||
/// Helper function to parse a single AppTab from various element types
|
||||
static AppTab? _parseAppTabFromElement(dynamic e) {
|
||||
if (e is AppTab) {
|
||||
return e;
|
||||
} else if (e is String) {
|
||||
return AppTab.values.firstWhereOrNull((t) => t.name == e);
|
||||
} else if (e is int) {
|
||||
if (e >= 0 && e < AppTab.values.length) {
|
||||
return AppTab.values[e];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
52
lib/data/model/app/tab.g.dart
Normal file
52
lib/data/model/app/tab.g.dart
Normal file
@@ -0,0 +1,52 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'tab.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// TypeAdapterGenerator
|
||||
// **************************************************************************
|
||||
|
||||
class AppTabAdapter extends TypeAdapter<AppTab> {
|
||||
@override
|
||||
final typeId = 103;
|
||||
|
||||
@override
|
||||
AppTab read(BinaryReader reader) {
|
||||
switch (reader.readByte()) {
|
||||
case 0:
|
||||
return AppTab.server;
|
||||
case 1:
|
||||
return AppTab.ssh;
|
||||
case 2:
|
||||
return AppTab.file;
|
||||
case 3:
|
||||
return AppTab.snippet;
|
||||
default:
|
||||
return AppTab.server;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void write(BinaryWriter writer, AppTab obj) {
|
||||
switch (obj) {
|
||||
case AppTab.server:
|
||||
writer.writeByte(0);
|
||||
case AppTab.ssh:
|
||||
writer.writeByte(1);
|
||||
case AppTab.file:
|
||||
writer.writeByte(2);
|
||||
case AppTab.snippet:
|
||||
writer.writeByte(3);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => typeId.hashCode;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is AppTabAdapter &&
|
||||
runtimeType == other.runtimeType &&
|
||||
typeId == other.typeId;
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import 'package:fl_lib/fl_lib.dart';
|
||||
import 'package:server_box/data/model/app/menu/server_func.dart';
|
||||
import 'package:server_box/data/model/app/net_view.dart';
|
||||
import 'package:server_box/data/model/app/server_detail_card.dart';
|
||||
import 'package:server_box/data/model/app/tab.dart';
|
||||
import 'package:server_box/data/model/ssh/virtual_key.dart';
|
||||
import 'package:server_box/data/res/default.dart';
|
||||
|
||||
@@ -22,10 +23,7 @@ class SettingStore extends HiveStore {
|
||||
// late final launchPage = property('launchPage', Defaults.launchPageIdx);
|
||||
|
||||
/// Disk view: amount / IO
|
||||
late final serverTabPreferDiskAmount = propertyDefault(
|
||||
'serverTabPreferDiskAmount',
|
||||
false,
|
||||
);
|
||||
late final serverTabPreferDiskAmount = propertyDefault('serverTabPreferDiskAmount', false);
|
||||
|
||||
/// Bigger for bigger font size
|
||||
/// 1.0 means 100%
|
||||
@@ -70,20 +68,14 @@ class SettingStore extends HiveStore {
|
||||
late final locale = propertyDefault('locale', '');
|
||||
|
||||
// SSH virtual key (ctrl | alt) auto turn off
|
||||
late final sshVirtualKeyAutoOff = propertyDefault(
|
||||
'sshVirtualKeyAutoOff',
|
||||
true,
|
||||
);
|
||||
late final sshVirtualKeyAutoOff = propertyDefault('sshVirtualKeyAutoOff', true);
|
||||
|
||||
late final editorFontSize = propertyDefault('editorFontSize', 12.5);
|
||||
|
||||
// Editor theme
|
||||
late final editorTheme = propertyDefault('editorTheme', Defaults.editorTheme);
|
||||
|
||||
late final editorDarkTheme = propertyDefault(
|
||||
'editorDarkTheme',
|
||||
Defaults.editorDarkTheme,
|
||||
);
|
||||
late final editorDarkTheme = propertyDefault('editorDarkTheme', Defaults.editorDarkTheme);
|
||||
|
||||
late final fullScreen = propertyDefault('fullScreen', false);
|
||||
|
||||
@@ -113,29 +105,20 @@ class SettingStore extends HiveStore {
|
||||
);
|
||||
|
||||
// Only valid on iOS
|
||||
late final autoUpdateHomeWidget = propertyDefault(
|
||||
'autoUpdateHomeWidget',
|
||||
isIOS,
|
||||
);
|
||||
late final autoUpdateHomeWidget = propertyDefault('autoUpdateHomeWidget', isIOS);
|
||||
|
||||
late final autoCheckAppUpdate = propertyDefault('autoCheckAppUpdate', true);
|
||||
|
||||
/// Display server tab function buttons on the bottom of each server card if [true]
|
||||
///
|
||||
/// Otherwise, display them on the top of server detail page
|
||||
late final moveServerFuncs = propertyDefault(
|
||||
'moveOutServerTabFuncBtns',
|
||||
false,
|
||||
);
|
||||
late final moveServerFuncs = propertyDefault('moveOutServerTabFuncBtns', false);
|
||||
|
||||
/// Whether use `rm -r` to delete directory on SFTP
|
||||
late final sftpRmrDir = propertyDefault('sftpRmrDir', false);
|
||||
|
||||
/// Whether use system's primary color as the app's primary color
|
||||
late final useSystemPrimaryColor = propertyDefault(
|
||||
'useSystemPrimaryColor',
|
||||
false,
|
||||
);
|
||||
late final useSystemPrimaryColor = propertyDefault('useSystemPrimaryColor', false);
|
||||
|
||||
/// Only valid on iOS / Android / Windows
|
||||
late final useBioAuth = propertyDefault('useBioAuth', false);
|
||||
@@ -151,10 +134,7 @@ class SettingStore extends HiveStore {
|
||||
late final sftpOpenLastPath = propertyDefault('sftpOpenLastPath', true);
|
||||
|
||||
/// Show folders first in SFTP file browser
|
||||
late final sftpShowFoldersFirst = propertyDefault(
|
||||
'sftpShowFoldersFirst',
|
||||
true,
|
||||
);
|
||||
late final sftpShowFoldersFirst = propertyDefault('sftpShowFoldersFirst', true);
|
||||
|
||||
/// Show tip of suspend
|
||||
late final showSuspendTip = propertyDefault('showSuspendTip', true);
|
||||
@@ -162,10 +142,7 @@ class SettingStore extends HiveStore {
|
||||
/// Whether collapse UI items by default
|
||||
late final collapseUIDefault = propertyDefault('collapseUIDefault', true);
|
||||
|
||||
late final serverFuncBtns = listProperty(
|
||||
'serverBtns',
|
||||
defaultValue: ServerFuncBtn.defaultIdxs,
|
||||
);
|
||||
late final serverFuncBtns = listProperty('serverBtns', defaultValue: ServerFuncBtn.defaultIdxs);
|
||||
|
||||
/// Docker is more popular than podman, set to `false` to use docker
|
||||
late final usePodman = propertyDefault('usePodman', false);
|
||||
@@ -180,16 +157,10 @@ class SettingStore extends HiveStore {
|
||||
late final containerParseStat = propertyDefault('containerParseStat', true);
|
||||
|
||||
/// Auto refresh container status
|
||||
late final containerAutoRefresh = propertyDefault(
|
||||
'containerAutoRefresh',
|
||||
true,
|
||||
);
|
||||
late final containerAutoRefresh = propertyDefault('containerAutoRefresh', true);
|
||||
|
||||
/// Use double column servers page on Desktop
|
||||
late final doubleColumnServersPage = propertyDefault(
|
||||
'doubleColumnServersPage',
|
||||
true,
|
||||
);
|
||||
late final doubleColumnServersPage = propertyDefault('doubleColumnServersPage', true);
|
||||
|
||||
/// Ignore local network device (eg: br-xxx, ovs-system...)
|
||||
/// when building traffic view on server tab
|
||||
@@ -244,8 +215,7 @@ class SettingStore extends HiveStore {
|
||||
/// Record the position and size of the window.
|
||||
late final windowState = property<WindowState>(
|
||||
'windowState',
|
||||
fromObj: (raw) =>
|
||||
WindowState.fromJson(jsonDecode(raw as String) as Map<String, dynamic>),
|
||||
fromObj: (raw) => WindowState.fromJson(jsonDecode(raw as String) as Map<String, dynamic>),
|
||||
toObj: (state) => state == null ? null : jsonEncode(state.toJson()),
|
||||
);
|
||||
|
||||
@@ -258,10 +228,7 @@ class SettingStore extends HiveStore {
|
||||
late final sftpEditor = propertyDefault('sftpEditor', '');
|
||||
|
||||
/// Preferred terminal emulator command on desktop
|
||||
late final desktopTerminal = propertyDefault(
|
||||
'desktopTerminal',
|
||||
'x-terminal-emulator',
|
||||
);
|
||||
late final desktopTerminal = propertyDefault('desktopTerminal', 'x-terminal-emulator');
|
||||
|
||||
/// Run foreground service on Android, if the SSH terminal is running
|
||||
late final fgService = propertyDefault('fgService', false);
|
||||
@@ -280,4 +247,14 @@ class SettingStore extends HiveStore {
|
||||
|
||||
/// Whether to read SSH config from ~/.ssh/config on first time
|
||||
late final firstTimeReadSSHCfg = propertyDefault('firstTimeReadSSHCfg', true);
|
||||
|
||||
/// Tabs at home page
|
||||
late final homeTabs = listProperty(
|
||||
'homeTabs',
|
||||
defaultValue: AppTab.values,
|
||||
fromObj: AppTab.parseAppTabsFromObj,
|
||||
toObj: (val) {
|
||||
return val?.map((e) => e.name).toList() ?? [];
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user