Skip to content

Commit

Permalink
files: Yarufy the app
Browse files Browse the repository at this point in the history
  • Loading branch information
HrX03 committed Mar 11, 2023
1 parent 210b473 commit 01ec113
Show file tree
Hide file tree
Showing 20 changed files with 512 additions and 268 deletions.
19 changes: 10 additions & 9 deletions lib/backend/folder_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import 'package:files/backend/utils.dart';
import 'package:flutter/material.dart';
import 'package:windows_path_provider/windows_path_provider.dart';
import 'package:xdg_directories/xdg_directories.dart';
import 'package:yaru_icons/yaru_icons.dart';

class FolderProvider {
final List<BuiltinFolder> _folders;
Expand Down Expand Up @@ -129,15 +130,15 @@ class SideDestination {
}

const Map<FolderType, IconData> _icons = {
FolderType.home: Icons.home_filled,
FolderType.desktop: Icons.desktop_windows,
FolderType.documents: Icons.note_outlined,
FolderType.pictures: Icons.photo_library_outlined,
FolderType.download: Icons.file_download,
FolderType.videos: Icons.videocam_outlined,
FolderType.music: Icons.music_note_outlined,
FolderType.publicShare: Icons.public_outlined,
FolderType.templates: Icons.file_copy_outlined,
FolderType.home: YaruIcons.home,
FolderType.desktop: YaruIcons.desktop,
FolderType.documents: YaruIcons.document,
FolderType.pictures: YaruIcons.image,
FolderType.download: YaruIcons.download,
FolderType.videos: YaruIcons.video,
FolderType.music: YaruIcons.music_note,
FolderType.publicShare: YaruIcons.globe,
FolderType.templates: YaruIcons.document_new,
};

String windowsFolderToString(WindowsFolder folder) {
Expand Down
7 changes: 4 additions & 3 deletions lib/backend/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:files/backend/providers.dart';
import 'package:flutter/material.dart';
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
import 'package:mime/mime.dart';
import 'package:yaru_icons/yaru_icons.dart';

class Utils {
Utils._();
Expand Down Expand Up @@ -52,10 +53,10 @@ class Utils {
final String? mime = lookupMimeType(path);

if (mime != null) {
return iconsPerMime[mime] ?? Icons.insert_drive_file_outlined;
return iconsPerMime[mime] ?? YaruIcons.document_filled;
}

return Icons.insert_drive_file_outlined;
return YaruIcons.document_filled;
}

static IconData iconForFolder(String path) {
Expand All @@ -64,7 +65,7 @@ class Utils {
? folderProvider.getIconForType(builtinFolder.type)
: null;

return builtinFolderIcon ?? Icons.folder;
return builtinFolderIcon ?? YaruIcons.folder_filled;
}

static String getEntityName(String path) {
Expand Down
180 changes: 102 additions & 78 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,59 +20,49 @@ import 'package:files/widgets/side_pane.dart';
import 'package:files/widgets/tab_strip.dart';
import 'package:files/widgets/workspace.dart';
import 'package:flutter/material.dart';
import 'package:yaru/yaru.dart';
import 'package:yaru_widgets/yaru_widgets.dart';

Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await YaruWindowTitleBar.ensureInitialized();
await YaruWindow.ensureInitialized();
await initProviders();
await driveProvider.init();

runApp(const Files());
}

ThemeData? _applyThemeValues(ThemeData? theme) {
return theme?.copyWith(
outlinedButtonTheme: OutlinedButtonThemeData(
style: theme.outlinedButtonTheme.style?.merge(
OutlinedButton.styleFrom(
backgroundColor: theme.colorScheme.surfaceVariant,
),
),
),
);
}

class Files extends StatelessWidget {
const Files({super.key});

@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Files',
theme: ThemeData(
colorScheme: const ColorScheme(
primary: Colors.deepOrange,
secondary: Colors.deepOrange,
background: Color(0xFF161616),
surface: Color(0xFF212121),
error: Colors.red,
onPrimary: Colors.white,
onSecondary: Colors.white,
onBackground: Colors.white,
onSurface: Colors.white,
onError: Colors.white,
brightness: Brightness.dark,
),
scrollbarTheme: ScrollbarThemeData(
thumbVisibility: const MaterialStatePropertyAll(true),
trackVisibility: MaterialStateProperty.resolveWith(
(states) => states.contains(MaterialState.hovered),
return YaruTheme(
builder: (context, value, child) {
return MaterialApp(
title: 'Files',
theme: _applyThemeValues(value.theme),
darkTheme: _applyThemeValues(value.darkTheme),
scrollBehavior: const MaterialScrollBehavior().copyWith(
scrollbars: false,
),
trackBorderColor: MaterialStateProperty.all(Colors.transparent),
crossAxisMargin: 0,
mainAxisMargin: 0,
radius: Radius.zero,
),
menuTheme: const MenuThemeData(
style: MenuStyle(
padding: MaterialStatePropertyAll(
EdgeInsets.symmetric(vertical: 16),
),
),
),
),
scrollBehavior: const MaterialScrollBehavior().copyWith(
scrollbars: false,
),
debugShowCheckedModeBanner: false,
home: const FilesHome(),
debugShowCheckedModeBanner: false,
home: const FilesHome(),
);
},
);
}
}
Expand All @@ -94,47 +84,81 @@ class _FilesHomeState extends State<FilesHome> {

@override
Widget build(BuildContext context) {
return Row(
children: [
SidePane(
destinations: folderProvider.destinations,
workspace: workspaces[currentWorkspace],
onNewTab: (String tabPath) {
workspaces.add(WorkspaceController(initialDir: tabPath));
currentWorkspace = workspaces.length - 1;
setState(() {});
},
),
Expanded(
child: Material(
color: Theme.of(context).colorScheme.background,
child: Column(
children: [
SizedBox(
height: 56,
child: TabStrip(
tabs: workspaces,
selectedTab: currentWorkspace,
allowClosing: workspaces.length > 1,
onTabChanged: (index) =>
setState(() => currentWorkspace = index),
onTabClosed: (index) {
workspaces.removeAt(index);
if (index < workspaces.length) {
currentWorkspace = index;
} else if (index - 1 >= 0) {
currentWorkspace = index - 1;
}
setState(() {});
},
onNewTab: () {
workspaces
.add(WorkspaceController(initialDir: currentDir));
currentWorkspace = workspaces.length - 1;
setState(() {});
return Material(
color: Theme.of(context).colorScheme.background,
child: Column(
children: [
GestureDetector(
onPanStart: (details) => YaruWindow.drag(context),
child: SizedBox(
height: 56,
child: TabStrip(
tabs: workspaces,
selectedTab: currentWorkspace,
allowClosing: workspaces.length > 1,
onTabChanged: (index) =>
setState(() => currentWorkspace = index),
onTabClosed: (index) {
workspaces.removeAt(index);
if (index < workspaces.length) {
currentWorkspace = index;
} else if (index - 1 >= 0) {
currentWorkspace = index - 1;
}
setState(() {});
},
onNewTab: () {
workspaces.add(WorkspaceController(initialDir: currentDir));
currentWorkspace = workspaces.length - 1;
setState(() {});
},
trailing: [
const SizedBox(width: 16),
YaruWindowControl(
type: YaruWindowControlType.minimize,
onTap: () => YaruWindow.minimize(context),
),
const SizedBox(width: 8),
StreamBuilder<YaruWindowState>(
stream: YaruWindow.states(context),
builder: (context, snapshot) {
final bool maximized =
snapshot.data?.isMaximized ?? false;

return YaruWindowControl(
type: maximized
? YaruWindowControlType.restore
: YaruWindowControlType.maximize,
onTap: () => maximized
? YaruWindow.restore(context)
: YaruWindow.maximize(context),
);
},
),
const SizedBox(width: 8),
YaruWindowControl(
type: YaruWindowControlType.close,
onTap: () => YaruWindow.close(context),
),
const SizedBox(width: 16),
],
),
),
),
const Divider(thickness: 1, height: 1),
Expanded(
child: Row(
children: [
SidePane(
destinations: folderProvider.destinations,
workspace: workspaces[currentWorkspace],
onNewTab: (String tabPath) {
workspaces.add(WorkspaceController(initialDir: tabPath));
currentWorkspace = workspaces.length - 1;
setState(() {});
},
),
const VerticalDivider(thickness: 1, width: 1),
Expanded(
child: FilesWorkspace(
key: ValueKey(currentWorkspace),
Expand All @@ -144,8 +168,8 @@ class _FilesHomeState extends State<FilesHome> {
],
),
),
),
],
],
),
);
}
}
Loading

0 comments on commit 01ec113

Please sign in to comment.