Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
import 'package:flutter/material.dart';
import 'package:grassh_renew/src/config/global_config.dart';
import 'package:grassh_renew/src/ui/main.dart';
import 'package:grassh_renew/src/util/platform.dart';
import 'package:grassh_renew/src/util/screen.dart';
import 'package:window_manager/window_manager.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();

await GlobalConfig.init();

// Initialize PC Window
if (PlatformUtil.isPC) {
await windowManager.ensureInitialized();

WindowOptions windowOptions = const WindowOptions(
size: Size(1000, 800),
minimumSize: Size(1000, 800),
WindowOptions windowOptions = WindowOptions(
size: Size(1000, ScreenUtil.height < 800 ? ScreenUtil.height : 800),
minimumSize:
Size(1000, ScreenUtil.height < 800 ? ScreenUtil.height : 800),
center: true,
backgroundColor: Colors.transparent,
skipTaskbar: false,
Expand Down
56 changes: 56 additions & 0 deletions lib/src/config/config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import 'dart:io';

import 'package:toml/toml.dart';

class Config {
late Map<String, dynamic> conf;
String path;

Config({
required this.path,
required Map<String, dynamic> defaultConfig,
}) {
conf = defaultConfig;
init(path, defaultConfig);
}

init(String path, Map<String, dynamic> defaultConfig) {
var f = File(path);
_configFileCheck(f);
read();
}

save() {
var f = File(path);
_configFileCheck(f);
try {
var config = TomlDocument.fromMap(conf).toString();
f.writeAsStringSync(config);
} catch (e) {
rethrow;
}
}

read() {
var f = File(path);
_configFileCheck(f);
var ctx = f.readAsStringSync();
try {
conf = TomlDocument.parse(ctx).toMap();
} catch (e) {
rethrow;
}
}

_configFileCheck(File f) {
if (!f.existsSync()) {
f.createSync();
try {
var config = TomlDocument.fromMap(conf).toString();
f.writeAsStringSync(config);
} catch (e) {
rethrow;
}
}
}
}
21 changes: 21 additions & 0 deletions lib/src/config/global_config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'package:grassh_renew/src/config/config.dart';
import 'package:package_info_plus/package_info_plus.dart';

class GlobalConfig {
static late PackageInfo packageInfo;
static late Config config;

static init() async {
packageInfo = await PackageInfo.fromPlatform();

// config = Config(
// path: "./config.toml",
// defaultConfig: {
// "version": 1,
// "global": {
// "language": "zh-CN",
// },
// },
// );
}
}
10 changes: 0 additions & 10 deletions lib/src/ui/component/appbar/action_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,6 @@ class _ActionButtonState extends State<ActionButton> {
Widget build(BuildContext context) {
return Row(
children: [
Button(
icon:
isSidebarLeftOpen ? Codicon.sidebarLeft : Codicon.sidebarLeftOff,
callback: () {
setState(() {
isSidebarLeftOpen = !isSidebarLeftOpen;
});
},
),
const SizedBox(width: 5),
Button(
icon: isSidebarRightOpen
? Codicon.sidebarRight
Expand Down
71 changes: 71 additions & 0 deletions lib/src/ui/component/sidebar/left.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import 'package:flutter/material.dart';
import 'package:grassh_renew/src/ui/component/sidebar/main.dart';
import 'package:grassh_renew/src/ui/component/sidebar/tab.dart';
import 'package:grassh_renew/src/ui/icons/codicon.dart';

class LeftSideBar extends StatefulWidget {
final LeftSideBarController controller;
const LeftSideBar({super.key, required this.controller});

@override
State<LeftSideBar> createState() => _LeftSideBarState();
}

class _LeftSideBarState extends State<LeftSideBar> {
@override
Widget build(BuildContext context) {
return SideBar(
width: widget.controller.isOpen ? 150 : 40,
child: Column(
children: [
SideBarTab(
icon: Codicon.menu,
text: "Menu",
callback: () {
widget.controller.switchSidebar();
setState(() {});
},
),
// TODO: Terminal Tabs
// Expanded(
// child: ListView.builder(
// itemCount: 0,
// itemBuilder: (ctx, index) {
// return Tab();
// },
// ),
// ),
Expanded(child: Container()),
SideBarTab(
icon: Codicon.add,
text: "Add Terminal",
callback: () {},
),
],
),
);
}
}

class LeftSideBarController {
final void Function()? callback;

LeftSideBarController({this.callback});

bool _open = false;
bool get isOpen => _open;

open() {
_open = true;
callback?.call();
}

close() {
_open = false;
callback?.call();
}

switchSidebar() {
_open ? close() : open();
}
}
26 changes: 26 additions & 0 deletions lib/src/ui/component/sidebar/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import 'package:flutter/material.dart';

class SideBar extends StatelessWidget {
final Widget? child;
final double width;
const SideBar({
super.key,
required this.width,
this.child,
});

@override
Widget build(BuildContext context) {
return AnimatedContainer(
duration: const Duration(milliseconds: 300),
curve: Curves.fastEaseInToSlowEaseOut,
width: width,
child: Center(
child: Container(
color: Theme.of(context).cardColor,
child: child,
),
),
);
}
}
79 changes: 79 additions & 0 deletions lib/src/ui/component/sidebar/tab.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import 'package:flutter/material.dart';

class SideBarTab extends StatefulWidget {
final void Function()? callback;
final IconData? icon;
final String? text;

const SideBarTab({super.key, this.callback, this.icon, this.text});

@override
State<SideBarTab> createState() => _SideBarTabState();
}

class _SideBarTabState extends State<SideBarTab> {
bool _isHover = false;

@override
Widget build(BuildContext context) {
return Center(
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 5),
child: GestureDetector(
onTap: () {
widget.callback?.call();
},
child: MouseRegion(
cursor: SystemMouseCursors.click,
onEnter: (e) {
_isHover = true;
setState(() {});
},
onExit: (e) {
_isHover = false;
setState(() {});
},
child: AnimatedContainer(
duration: const Duration(milliseconds: 100),
curve: Curves.easeInOut,
width: MediaQuery.of(context).size.width,
height: 30,
decoration: BoxDecoration(
color: _isHover ? Theme.of(context).highlightColor : null,
borderRadius: BorderRadius.circular(5),
),
child: Padding(
padding: const EdgeInsets.all(8),
child: ClipRect(
child: Stack(
alignment: Alignment.centerLeft,
children: [
Icon(
widget.icon,
size: 14,
),
Positioned(
left: 20,
child: Container(
constraints: const BoxConstraints(maxWidth: 104),
child: Text(
widget.text ?? "",
softWrap: false,
style: const TextStyle(
fontSize: 12,
overflow: TextOverflow.fade,
),
),
),
),
],
),
),
),
),
),
),
),
);
}
}
12 changes: 12 additions & 0 deletions lib/src/ui/icons/codicon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,16 @@ class Codicon {
fontFamily: "Codicon",
matchTextDirection: true,
);

static const IconData menu = IconData(
0xeb94,
fontFamily: "Codicon",
matchTextDirection: true,
);

static const IconData add = IconData(
0xea60,
fontFamily: "Codicon",
matchTextDirection: true,
);
}
38 changes: 35 additions & 3 deletions lib/src/ui/main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'package:flutter/material.dart';
import 'package:grassh_renew/src/config/global_config.dart';
import 'package:grassh_renew/src/ui/component/sidebar/left.dart';
import 'component/appbar/main.dart' as bar;

class MainPage extends StatefulWidget {
Expand All @@ -11,9 +13,39 @@ class MainPage extends StatefulWidget {
class _MainPageState extends State<MainPage> {
@override
Widget build(BuildContext context) {
return const Scaffold(
appBar: bar.AppBar(),
body: Row(),
return Scaffold(
appBar: const bar.AppBar(),
body: SizedBox(
width: MediaQuery.of(context).size.width,
child: Stack(
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
LeftSideBar(
controller: LeftSideBarController(),
),
Expanded(
child: Container(),
)
],
),
GlobalConfig.packageInfo.buildNumber != ""
? Positioned(
right: 0,
bottom: 0,
child: Text(
"GrassH v${GlobalConfig.packageInfo.version}\nBuild ${GlobalConfig.packageInfo.buildNumber}. Not intended for external distribution.",
textAlign: TextAlign.end,
style: TextStyle(
fontSize: 10,
color: Theme.of(context).primaryColorLight,
),
),
)
: const SizedBox(),
],
)),
);
}
}
1 change: 1 addition & 0 deletions linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
flutter_pty
)

set(PLUGIN_BUNDLED_LIBRARIES)
Expand Down
2 changes: 2 additions & 0 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import FlutterMacOS
import Foundation

import package_info_plus
import screen_retriever
import window_manager

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin"))
ScreenRetrieverPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverPlugin"))
WindowManagerPlugin.register(with: registry.registrar(forPlugin: "WindowManagerPlugin"))
}
Loading