2024-03-03 14:28:29 +03:30
|
|
|
import 'dart:io';
|
2023-12-28 23:16:56 +03:30
|
|
|
import 'dart:ui';
|
|
|
|
|
|
2024-08-04 23:19:46 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2023-12-28 23:16:56 +03:30
|
|
|
import 'package:hiddify/features/connection/notifier/connection_notifier.dart';
|
|
|
|
|
import 'package:hiddify/utils/utils.dart';
|
|
|
|
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
|
|
|
|
import 'package:tray_manager/tray_manager.dart';
|
|
|
|
|
import 'package:window_manager/window_manager.dart';
|
|
|
|
|
|
|
|
|
|
part 'window_notifier.g.dart';
|
|
|
|
|
|
|
|
|
|
const minimumWindowSize = Size(368, 568);
|
|
|
|
|
const defaultWindowSize = Size(868, 668);
|
|
|
|
|
|
|
|
|
|
@Riverpod(keepAlive: true)
|
|
|
|
|
class WindowNotifier extends _$WindowNotifier with AppLogger {
|
|
|
|
|
@override
|
|
|
|
|
Future<void> build() async {
|
|
|
|
|
if (!PlatformUtils.isDesktop) return;
|
|
|
|
|
|
2024-01-10 17:28:08 +03:30
|
|
|
// if (Platform.isWindows) {
|
|
|
|
|
// loggy.debug("ensuring single instance");
|
2024-02-10 11:39:37 +01:00
|
|
|
// await WindowsSingleInstance.ensureSingleInstance([], "Hiddify");
|
2024-01-10 17:28:08 +03:30
|
|
|
// }
|
2023-12-29 17:59:53 +03:30
|
|
|
|
2023-12-28 23:16:56 +03:30
|
|
|
await windowManager.ensureInitialized();
|
|
|
|
|
await windowManager.setMinimumSize(minimumWindowSize);
|
|
|
|
|
await windowManager.setSize(defaultWindowSize);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> open({bool focus = true}) async {
|
|
|
|
|
await windowManager.show();
|
|
|
|
|
if (focus) await windowManager.focus();
|
2024-03-03 14:28:29 +03:30
|
|
|
if (Platform.isMacOS) {
|
|
|
|
|
await windowManager.setSkipTaskbar(false);
|
|
|
|
|
}
|
2023-12-28 23:16:56 +03:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO add option to quit or minimize to tray
|
|
|
|
|
Future<void> close() async {
|
|
|
|
|
await windowManager.hide();
|
2024-03-03 14:28:29 +03:30
|
|
|
if (Platform.isMacOS) {
|
|
|
|
|
await windowManager.setSkipTaskbar(true);
|
|
|
|
|
}
|
2023-12-28 23:16:56 +03:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> quit() async {
|
2024-08-04 23:19:46 +02:00
|
|
|
await ref.read(connectionNotifierProvider.notifier).abortConnection().timeout(const Duration(seconds: 2)).catchError(
|
2023-12-28 23:16:56 +03:30
|
|
|
(e) {
|
|
|
|
|
loggy.warning("error aborting connection on quit", e);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
await trayManager.destroy();
|
|
|
|
|
await windowManager.destroy();
|
|
|
|
|
}
|
|
|
|
|
}
|