Skip to content
This repository has been archived by the owner on Aug 19, 2022. It is now read-only.

Commit

Permalink
feat: warning for refresh button
Browse files Browse the repository at this point in the history
  • Loading branch information
Tricked-dev committed Mar 2, 2022
1 parent c43ee64 commit d67576c
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 97 deletions.
2 changes: 1 addition & 1 deletion lib/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Config {
"color": -1,
"use_top_nav": false,
"mod_repos": ["std"],
"mod_folder": "${defaultMinecraft[defaultTargetPlatform]}/mods",
"mod_folder": "${defaultMinecraft[defaultTargetPlatform]}",
};

static void change(String key, value) {
Expand Down
134 changes: 67 additions & 67 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
// You should have received a copy of the license along with this
// work. If not, see <http://creativecommons.org/licenses/by-nc-nd/3.0/>.

import 'package:bitsdojo_window/bitsdojo_window.dart';
import 'package:args/args.dart';
import 'package:flutter/foundation.dart';
import 'package:tmodinstaller/config.dart';
import 'package:tmodinstaller/src/screens/settings.dart';
import 'package:tmodinstaller/src/screens/version.dart';
Expand Down Expand Up @@ -176,19 +178,21 @@ class _TModInstallerPageState extends State<TModInstallerPage> {
return NavigationView(
appBar: NavigationAppBar(
title: () {
// return const DragToMoveArea(
// child: Align(
// alignment: AlignmentDirectional.centerStart,
// child: Text("TMOD Installer"),
// ),
// );
return const DragToMoveArea(
child: Align(
alignment: AlignmentDirectional.centerStart,
child: Text("TMod Installer"),
),
);
}(),
// actions: DragToMoveArea(
// child: Row(
// crossAxisAlignment: CrossAxisAlignment.start,
// children: const [Spacer(), Text("")],
// ),
// ),
actions: defaultTargetPlatform == TargetPlatform.windows
? DragToMoveArea(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: const [Spacer(), WindowButtons()],
),
)
: null,
),
pane: NavigationPane(
selected: index,
Expand All @@ -201,12 +205,7 @@ class _TModInstallerPageState extends State<TModInstallerPage> {
? Container(
height: kOneLineTileHeight,
padding: const EdgeInsets.symmetric(horizontal: 10.0),
child: SvgPicture.asset("assets/Logo.svg")
// child: const FlutterLogo(
// style: FlutterLogoStyle.horizontal,
// size: 100,
// ),
)
child: SvgPicture.asset("assets/Logo.svg"))
: null,
displayMode: appTheme.displayMode,
indicatorBuilder: () {
Expand All @@ -225,65 +224,16 @@ class _TModInstallerPageState extends State<TModInstallerPage> {
title: Text(e),
),
)
// It doesn't look good when resizing from compact to open
// PaneItemHeader(header: Text('User Interaction')),
// PaneItem(
// icon: const Icon(FluentIcons.checkbox_composite),
// title: const Text('Inputs'),
// ),
// PaneItem(
// icon: const Icon(FluentIcons.text_field),
// title: const Text('Forms'),
// ),
// PaneItemSeparator(),
// PaneItem(
// icon: const Icon(FluentIcons.color),
// title: const Text('Colors'),
// ),
// PaneItem(
// icon: const Icon(FluentIcons.icon_sets_flag),
// title: const Text('Icons'),
// ),
// PaneItem(
// icon: const Icon(FluentIcons.plain_text),
// title: const Text('Typography'),
// ),
// PaneItem(
// icon: const Icon(FluentIcons.cell_phone),
// title: const Text('Mobile'),
// ),
// PaneItem(
// icon: Icon(
// appTheme.displayMode == PaneDisplayMode.top
// ? FluentIcons.more
// : FluentIcons.more_vertical,
// ),
// title: const Text('Others'),
// infoBadge: const InfoBadge(
// source: Text('9'),
// ),
// ),
],
// autoSuggestBox: AutoSuggestBox(
// controller: TextEditingController(),
// items: const ['Item 1', 'Item 2', 'Item 3', 'Item 4'],
// ),
autoSuggestBoxReplacement: const Icon(FluentIcons.search),
footerItems: [
PaneItemSeparator(),
// PaneItem(
// icon: const Icon(FluentIcons.upload),
// title: const Text('Updater'),
// ),
PaneItem(
icon: const Icon(FluentIcons.settings),
title: const Text('Settings'),
),
],
),

// appBar: NavigationAppBar(title: Text("Fluent Design App Bar")),
// content: comp,
content: NavigationBody(index: index, children: [
...versions.map((version) => VersionPage(
mods: [
Expand All @@ -299,3 +249,53 @@ class _TModInstallerPageState extends State<TModInstallerPage> {
);
}
}

class WindowButtons extends StatelessWidget {
const WindowButtons({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
assert(debugCheckHasFluentTheme(context));
assert(debugCheckHasFluentLocalizations(context));
final ThemeData theme = FluentTheme.of(context);
final buttonColors = WindowButtonColors(
iconNormal: theme.inactiveColor,
iconMouseDown: theme.inactiveColor,
iconMouseOver: theme.inactiveColor,
mouseOver: ButtonThemeData.buttonColor(
theme.brightness, {ButtonStates.hovering}),
mouseDown: ButtonThemeData.buttonColor(
theme.brightness, {ButtonStates.pressing}),
);
final closeButtonColors = WindowButtonColors(
mouseOver: Colors.red,
mouseDown: Colors.red.dark,
iconNormal: theme.inactiveColor,
iconMouseOver: Colors.red.basedOnLuminance(),
iconMouseDown: Colors.red.dark.basedOnLuminance(),
);
return Row(children: [
Tooltip(
message: FluentLocalizations.of(context).minimizeWindowTooltip,
child: MinimizeWindowButton(colors: buttonColors),
),
Tooltip(
message: FluentLocalizations.of(context).restoreWindowTooltip,
child: WindowButton(
colors: buttonColors,
iconBuilder: (context) {
if (appWindow.isMaximized) {
return RestoreIcon(color: context.iconColor);
}
return MaximizeIcon(color: context.iconColor);
},
onPressed: appWindow.maximizeOrRestore,
),
),
Tooltip(
message: FluentLocalizations.of(context).closeWindowTooltip,
child: CloseWindowButton(colors: closeButtonColors),
),
]);
}
}
82 changes: 53 additions & 29 deletions lib/src/screens/launcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,35 +63,10 @@ class _LauncherState extends State<Launcher> {
FilledButton(
child: const Text("Click here!"),
onPressed: () async {
var backupDir =
"${Directory(_modfolder).parent.path}/mods.back";
try {
await Directory(backupDir).delete(recursive: true);
} catch (e) {
print("Backup mods folder doesn't exist");
}
try {
await Directory(_modfolder).rename(
backupDir,
);
await File("$backupDir/hi.txt").writeAsString(
"Accidentally clicked this button? dw just rename this folder to mods");

// await Directory(_modfolder).delete(recursive: true);
await Directory(_modfolder).create();
var files =
Directory("${Config.appDir}/modlists/${widget.mcv}/")
.listSync();
for (var element in files) {
if (element.statSync().type == FileSystemEntityType.file) {
await File(element.path)
.copy("$_modfolder/${basename(element.path)}");
}
}
} catch (e) {
print(e);
print("Failed to refresh mod folder");
}
showDialog(
context: context,
builder: (BuildContext context) => _refresh(context, version),
);
}),
biggerSpacer,
Text("Mod folder",
Expand Down Expand Up @@ -180,4 +155,53 @@ class _LauncherState extends State<Launcher> {
],
);
}

Widget _refresh(BuildContext context, Version? version) {
return ContentDialog(
title: const Text(
"Refresh mod folder this will delete the mod folder and replace the mods"),
content: const Text("This action CANNOT be undone"),
actions: <Widget>[
FilledButton(
onPressed: () async {
var backupDir = "${Directory(_modfolder).parent.path}/mods.back";
try {
await Directory(backupDir).delete(recursive: true);
} catch (e) {
print("Backup mods folder doesn't exist");
}
try {
await Directory(_modfolder).rename(
backupDir,
);
await File("$backupDir/hi.txt").writeAsString(
"Accidentally clicked this button? dw just rename this folder to mods");

// await Directory(_modfolder).delete(recursive: true);
await Directory(_modfolder).create();
var files = Directory("${Config.appDir}/modlists/${widget.mcv}/")
.listSync();
for (var element in files) {
if (element.statSync().type == FileSystemEntityType.file) {
await File(element.path)
.copy("$_modfolder/${basename(element.path)}");
}
}
} catch (e) {
print(e);
print("Failed to refresh mod folder");
}
Navigator.of(context).pop();
},
child: const Text('Continue'),
),
FilledButton(
onPressed: () async {
Navigator.of(context).pop();
},
child: const Text('Close'),
),
],
);
}
}
4 changes: 4 additions & 0 deletions linux/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@

#include "generated_plugin_registrant.h"

#include <bitsdojo_window_linux/bitsdojo_window_plugin.h>
#include <file_selector_linux/file_selector_plugin.h>
#include <flutter_acrylic/flutter_acrylic_plugin.h>
#include <isar_flutter_libs/isar_flutter_libs_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>
#include <window_manager/window_manager_plugin.h>

void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) bitsdojo_window_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "BitsdojoWindowPlugin");
bitsdojo_window_plugin_register_with_registrar(bitsdojo_window_linux_registrar);
g_autoptr(FlPluginRegistrar) file_selector_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FileSelectorPlugin");
file_selector_plugin_register_with_registrar(file_selector_linux_registrar);
Expand Down
1 change: 1 addition & 0 deletions linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
bitsdojo_window_linux
file_selector_linux
flutter_acrylic
isar_flutter_libs
Expand Down
35 changes: 35 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,41 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.8.2"
bitsdojo_window:
dependency: "direct main"
description:
name: bitsdojo_window
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.1+1"
bitsdojo_window_linux:
dependency: transitive
description:
name: bitsdojo_window_linux
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.1"
bitsdojo_window_macos:
dependency: transitive
description:
name: bitsdojo_window_macos
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.0"
bitsdojo_window_platform_interface:
dependency: transitive
description:
name: bitsdojo_window_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.0"
bitsdojo_window_windows:
dependency: transitive
description:
name: bitsdojo_window_windows
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.0"
boolean_selector:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dependencies:
file_selector_macos:
file_selector_windows:
file_selector: ^0.8.3
bitsdojo_window: ^0.1.1+1

dev_dependencies:
build_runner: ^2.0.0
Expand Down
3 changes: 3 additions & 0 deletions windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "generated_plugin_registrant.h"

#include <bitsdojo_window_windows/bitsdojo_window_plugin.h>
#include <file_selector_windows/file_selector_windows.h>
#include <flutter_acrylic/flutter_acrylic_plugin.h>
#include <isar_flutter_libs/isar_flutter_libs_plugin.h>
Expand All @@ -14,6 +15,8 @@
#include <window_manager/window_manager_plugin.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
BitsdojoWindowPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("BitsdojoWindowPlugin"));
FileSelectorWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FileSelectorWindows"));
FlutterAcrylicPluginRegisterWithRegistrar(
Expand Down
1 change: 1 addition & 0 deletions windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
bitsdojo_window_windows
file_selector_windows
flutter_acrylic
isar_flutter_libs
Expand Down

0 comments on commit d67576c

Please sign in to comment.