Skip to content

Commit

Permalink
General updates (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdlukaa authored Jan 7, 2024
2 parents 794123b + 8a1e1e9 commit f283c5c
Show file tree
Hide file tree
Showing 22 changed files with 242 additions and 194 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
submodules: recursive
- uses: subosito/flutter-action@v2.8.0
with:
channel: "master"
channel: "stable"
# cache: true
# TODO: Signing Android application.
# - name: Create Key Store
Expand Down Expand Up @@ -81,7 +81,7 @@ jobs:
submodules: recursive
- uses: subosito/flutter-action@v2.8.0
with:
channel: "master"
channel: "stable"
architecture: x64
# cache: true

Expand Down Expand Up @@ -123,7 +123,7 @@ jobs:
submodules: recursive
- uses: subosito/flutter-action@v2.8.0
with:
channel: "master"
channel: "stable"
architecture: x64
# cache: true

Expand Down Expand Up @@ -164,7 +164,7 @@ jobs:
submodules: recursive
- uses: subosito/flutter-action@v2.8.0
with:
channel: "master"
channel: "stable"
# cache: true
- run: git config --system core.longpaths true
- run: flutter gen-l10n
Expand Down Expand Up @@ -218,7 +218,7 @@ jobs:
- name: Install Flutter
uses: subosito/flutter-action@v2.8.0
with:
channel: "master"
channel: "stable"
# cache: true

- name: Initiate Flutter
Expand Down
4 changes: 2 additions & 2 deletions lib/api/events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ extension EventsExtension on API {

return compute(_getEvents, {
'server': server,
'limit': await eventsLimit,
'limit': (startTime != null && endTime != null) ? -1 : await eventsLimit,
'startTime': startTime,
'endTime': endTime,
'device_id': device?.id,
Expand All @@ -46,10 +46,10 @@ extension EventsExtension on API {
return [];
}

final limit = (data['limit'] as int?) ?? -1;
var startTime = data['startTime'] as DateTime?;
final endTime = data['endTime'] as DateTime?;
final deviceId = data['device_id'] as int?;
final limit = (data['limit'] as int?) ?? -1;

if (startTime != null && endTime != null) {
if (startTime == endTime) {
Expand Down
2 changes: 1 addition & 1 deletion lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@
}
},
"howToDownload": "Go to the \"Events History\" screen to download events.",
"downloadTitle": "{event} on {device} under server {server} at {date}",
"downloadTitle": "{event} on {device} ({server}) at {date}",
"@downloadTitle": {
"placeholders": {
"event": {
Expand Down
7 changes: 3 additions & 4 deletions lib/providers/downloads_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,7 @@ class DownloadsManager extends UnityProvider {
/// Downloads the given [event]
Future<void> download(Event event) async {
assert(event.mediaURL != null, 'There must be an url to be downloaded');

// safe for release
if (event.mediaURL == null) return;
if (event.mediaURL == null) return; // safe for release

final home = HomeProvider.instance
..loading(UnityLoadingReason.downloadEvent);
Expand All @@ -224,7 +222,8 @@ class DownloadsManager extends UnityProvider {
notifyListeners();

final dir = SettingsProvider.instance.downloadsDirectory;
final fileName = 'event_${event.id}${event.deviceID}${event.server.ip}.mp4';
final fileName =
'event_${event.id}_${event.deviceID}_${event.server.name}.mp4';
final downloadPath = path.join(dir, fileName);

await Dio().downloadUri(
Expand Down
13 changes: 9 additions & 4 deletions lib/utils/logging.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,26 @@ void handleError(dynamic error, dynamic stackTrace) {
writeErrorToFile(error, stackTrace);
}

Future<File> getLogFile() async {
final dir = await getApplicationSupportDirectory();
final file = File(path.join(dir.path, 'logs.txt'));

return file;
}

Future<void> writeErrorToFile(dynamic error, dynamic stackTrace) async {
final time = DateTime.now().toIso8601String();
final errorLog = '\n[$time]Error: $error\n[$time]Stack trace: $stackTrace';

final dir = await getApplicationSupportDirectory();
final file = File(path.join(dir.path, 'logs.txt'));
final file = await getLogFile();

await file.writeAsString(errorLog, mode: FileMode.append);
Logger.root.log(Level.INFO, 'Wrote log file to ${file.path}');
}

Future<void> writeLogToFile(String text) async {
final time = DateTime.now().toIso8601String();
final dir = await getApplicationSupportDirectory();
final file = File(path.join(dir.path, 'logs.txt'));
final file = await getLogFile();

await file.writeAsString('\n[$time] $text', mode: FileMode.append);
Logger.root.log(Level.INFO, 'Wrote log file to ${file.path}');
Expand Down
27 changes: 13 additions & 14 deletions lib/utils/methods.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ class DeviceOrientations {
/// Private constructor.
DeviceOrientations._();

Future<void> set(
List<DeviceOrientation> orientations,
) {
/// Maintain a stack of the last set of orientations, to switch back to the
/// most recent one.
final List<List<DeviceOrientation>> _stack = [];

Future<void> set(List<DeviceOrientation> orientations) {
_stack.add(orientations);
debugPrint(orientations.toString());
return SystemChrome.setPreferredOrientations(orientations);
Expand All @@ -46,9 +48,6 @@ class DeviceOrientations {
debugPrint(_stack.toString());
await SystemChrome.setPreferredOrientations(_stack.last);
}

/// Maintain a stack of the last set of orientations, to switch back to the most recent one.
final List<List<DeviceOrientation>> _stack = [];
}

/// Wraps [child] in a [Tooltip] if the app meets [condition]
Expand All @@ -69,7 +68,7 @@ Widget wrapTooltipIf(
return child;
}

/// Wraps [child] in an [Expanded] if the app meets [condition]
/// Wraps [child] in an [Expanded] if [condition] is true.
Widget wrapExpandedIf(
bool condition, {
required Widget child,
Expand All @@ -81,14 +80,11 @@ Widget wrapExpandedIf(
return child;
}

T? showIf<T extends Widget>(bool condition, {required T child}) {
if (condition) return child;

return null;
}

/// Returns true if the app is running on a desktop platform. This is useful
/// for determining whether to show desktop-specific UI elements.
///
/// This does not check if the runtime is native or web. Use [isDesktopPlatform]
/// for that instead.
bool get isDesktop {
return [
TargetPlatform.windows,
Expand All @@ -106,6 +102,9 @@ bool get isDesktopPlatform {

/// Returns true if the app is running on a mobile platform. This is useful
/// for determining whether to show mobile-specific UI elements.
///
/// This does not check if the runtime is native or web. Use [isMobilePlatform]
/// for that instead.
bool get isMobile {
return [
TargetPlatform.android,
Expand All @@ -121,7 +120,7 @@ bool get isMobilePlatform {
return Platform.isAndroid || Platform.isIOS;
}

/// Whether the current platform is iOS or macOS
/// Whether the current platform is iOS or macOS.
bool get isCupertino {
final cupertinoPlatforms = [TargetPlatform.iOS, TargetPlatform.macOS];
final navigatorContext = navigatorKey.currentContext;
Expand Down
3 changes: 2 additions & 1 deletion lib/utils/widgets/tree_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Widget buildCheckbox({
required bool isError,
required String text,
required double gapCheckboxText,
IconData offlineIcon = Icons.videocam_off_outlined,
String? secondaryText,
double checkboxScale = 0.8,
FlexFit textFit = FlexFit.loose,
Expand All @@ -27,7 +28,7 @@ Widget buildCheckbox({
? Tooltip(
message: loc.offline,
child: Icon(
Icons.videocam_off_outlined,
offlineIcon,
size: 16.0,
color: theme.colorScheme.error,
),
Expand Down
6 changes: 3 additions & 3 deletions lib/utils/window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ Future<void> configureWindow() async {
windowButtonVisibility: true,
),
() async {
if ((isDesktopPlatform && Platform.isMacOS) || kDebugMode) {
await windowManager.setSize(kInitialWindowSize);
}
// if ((isDesktopPlatform && Platform.isMacOS) || kDebugMode) {
// await windowManager.setSize(kInitialWindowSize);
// }
await windowManager.show();
},
);
Expand Down
33 changes: 20 additions & 13 deletions lib/widgets/collapsable_sidebar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import 'package:bluecherry_client/utils/widgets/squared_icon_button.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

const kSidebarConstraints = BoxConstraints(maxWidth: 220.0);
const kCompactSidebarConstraints = BoxConstraints(maxWidth: 46.0);
const kSidebarConstraints = BoxConstraints(maxWidth: 256.0);
const kCompactSidebarConstraints = BoxConstraints(maxWidth: 48.0);

typedef SidebarBuilder = Widget Function(
BuildContext context,
Expand Down Expand Up @@ -96,12 +96,21 @@ class _CollapsableSidebarState extends State<CollapsableSidebar>
return AnimatedBuilder(
animation: collapseAnimation,
builder: (context, child) {
final isTransitioning = collapseAnimation.value > 0.0 &&
collapseAnimation.value < 1.0 &&
collapseController.status != AnimationStatus.completed &&
collapseController.status != AnimationStatus.dismissed;
final collapsed = collapseController.isCompleted;
final collapseButton = Padding(
final collapseButton = Container(
alignment: isTransitioning
? (widget.left
? AlignmentDirectional.topStart
: AlignmentDirectional.topEnd)
: AlignmentDirectional.topCenter,
padding: collapsed
? EdgeInsetsDirectional.zero
: widget.left
? const EdgeInsetsDirectional.only(start: 5.0)
? const EdgeInsetsDirectional.symmetric(horizontal: 5.0)
: const EdgeInsetsDirectional.only(end: 5.0),
child: SquaredIconButton(
key: collapseButtonKey,
Expand All @@ -117,9 +126,7 @@ class _CollapsableSidebarState extends State<CollapsableSidebar>
end: 0.5,
))
.animate(collapseAnimation),
child: const Icon(
Icons.keyboard_arrow_right,
),
child: const Icon(Icons.keyboard_arrow_right),
),
onPressed: () {
if (collapseController.isCompleted) {
Expand All @@ -138,12 +145,12 @@ class _CollapsableSidebarState extends State<CollapsableSidebar>
).evaluate(collapseAnimation),
child: () {
if (collapseAnimation.value > 0.35) {
return Container(
alignment: widget.left
? AlignmentDirectional.topStart
: AlignmentDirectional.topEnd,
padding: const EdgeInsetsDirectional.symmetric(horizontal: 4.0),
child: widget.builder(context, true, collapseButton),
return Padding(
padding: const EdgeInsetsDirectional.symmetric(horizontal: 6.0),
child: Align(
alignment: AlignmentDirectional.topCenter,
child: widget.builder(context, true, collapseButton),
),
);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/widgets/device_grid/desktop/desktop_device_grid.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class _DesktopDeviceGridState extends State<DesktopDeviceGrid> {
SquaredIconButton(
icon: Icon(
Icons.cyclone,
size: 18.0,
size: 20.0,
color: settings.layoutCyclingEnabled
? theme.colorScheme.primary
: IconTheme.of(context).color,
Expand All @@ -78,7 +78,7 @@ class _DesktopDeviceGridState extends State<DesktopDeviceGrid> {
onPressed: settings.toggleCycling,
),
SquaredIconButton(
icon: const Icon(Icons.camera_outdoor, size: 18.0),
icon: const Icon(Icons.camera_outdoor, size: 20.0),
tooltip: loc.addExternalStream,
onPressed: () => AddExternalStreamDialog.show(context),
),
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/device_grid/desktop/desktop_sidebar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ class _DesktopDeviceSelectorTileState extends State<DesktopDeviceSelectorTile> {
minWidth: size.width,
),
items: <PopupMenuEntry>[
PopupLabel(
PopupMenuLabel(
label: Padding(
padding: padding
.add(const EdgeInsetsDirectional.symmetric(vertical: 6.0)),
Expand Down
7 changes: 2 additions & 5 deletions lib/widgets/device_grid/desktop/layout_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ import 'package:provider/provider.dart';
class LayoutManager extends StatefulWidget {
final Widget collapseButton;

const LayoutManager({
super.key,
required this.collapseButton,
});
const LayoutManager({super.key, required this.collapseButton});

@override
State<LayoutManager> createState() => _LayoutManagerState();
Expand Down Expand Up @@ -273,7 +270,7 @@ class _LayoutTileState extends State<LayoutTile> {
minWidth: size.width,
),
items: <PopupMenuEntry>[
PopupLabel(
PopupMenuLabel(
label: Padding(
padding: padding.add(const EdgeInsets.symmetric(vertical: 6.0)),
child: Text(
Expand Down
18 changes: 6 additions & 12 deletions lib/widgets/downloads_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -299,34 +299,28 @@ class _DownloadTileState extends State<DownloadTile> {
]),
),
),
TextButton(
TextButton.icon(
onPressed: isDownloaded
? () {
context
.read<DownloadsManager>()
.delete(widget.downloadPath!);
}
: null,
child: Row(children: [
const Icon(Icons.delete, size: 20.0),
const SizedBox(width: 8.0),
Text(loc.delete),
]),
icon: const Icon(Icons.delete, size: 20.0),
label: Text(loc.delete),
),
if (isDesktop)
TextButton(
TextButton.icon(
onPressed: isDownloaded
? () {
launchFileExplorer(
File(widget.downloadPath!).parent.path,
);
}
: null,
child: Row(children: [
const Icon(Icons.folder, size: 20.0),
const SizedBox(width: 8.0),
Text(loc.showInFiles), // show in explorer
]),
icon: const Icon(Icons.folder, size: 20.0),
label: Text(loc.showInFiles),
),
],
),
Expand Down
Loading

0 comments on commit f283c5c

Please sign in to comment.