mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 07:55:18 +00:00
fix(web): add conditional imports for window manager and initializers
- Split wm_tools into native/web implementations - Split initializers into native/web implementations - Add web stubs for window management functionality - Remove win32_registry dependency from web builds
This commit is contained in:
parent
cba8016e94
commit
1ecd5f6ae6
@ -13,6 +13,9 @@ class FontFamily {
|
||||
/// Font family: BootstrapIcons
|
||||
static const String bootstrapIcons = 'BootstrapIcons';
|
||||
|
||||
/// Font family: Cookie
|
||||
static const String cookie = 'Cookie';
|
||||
|
||||
/// Font family: RadixIcons
|
||||
static const String radixIcons = 'RadixIcons';
|
||||
}
|
||||
|
@ -1,26 +1,3 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:spotube/utils/platform.dart';
|
||||
import 'package:win32_registry/win32_registry.dart';
|
||||
|
||||
Future<void> registerWindowsScheme(String scheme) async {
|
||||
if (!kIsWindows) return;
|
||||
String appPath = Platform.resolvedExecutable;
|
||||
|
||||
String protocolRegKey = 'Software\\Classes\\$scheme';
|
||||
RegistryValue protocolRegValue = const RegistryValue(
|
||||
'URL Protocol',
|
||||
RegistryValueType.string,
|
||||
'',
|
||||
);
|
||||
String protocolCmdRegKey = 'shell\\open\\command';
|
||||
RegistryValue protocolCmdRegValue = RegistryValue(
|
||||
'',
|
||||
RegistryValueType.string,
|
||||
'"$appPath" "%1"',
|
||||
);
|
||||
|
||||
final regKey = Registry.currentUser.createKey(protocolRegKey);
|
||||
regKey.createValue(protocolRegValue);
|
||||
regKey.createKey(protocolCmdRegKey).createValue(protocolCmdRegValue);
|
||||
}
|
||||
// Conditional exports for platform initializers
|
||||
export 'initializers_native.dart'
|
||||
if (dart.library.html) 'initializers_web.dart';
|
26
lib/collections/initializers_native.dart
Normal file
26
lib/collections/initializers_native.dart
Normal file
@ -0,0 +1,26 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:spotube/utils/platform.dart';
|
||||
import 'package:win32_registry/win32_registry.dart';
|
||||
|
||||
Future<void> registerWindowsScheme(String scheme) async {
|
||||
if (!kIsWindows) return;
|
||||
String appPath = Platform.resolvedExecutable;
|
||||
|
||||
String protocolRegKey = 'Software\\Classes\\$scheme';
|
||||
RegistryValue protocolRegValue = const RegistryValue(
|
||||
'URL Protocol',
|
||||
RegistryValueType.string,
|
||||
'',
|
||||
);
|
||||
String protocolCmdRegKey = 'shell\\open\\command';
|
||||
RegistryValue protocolCmdRegValue = RegistryValue(
|
||||
'',
|
||||
RegistryValueType.string,
|
||||
'"$appPath" "%1"',
|
||||
);
|
||||
|
||||
final regKey = Registry.currentUser.createKey(protocolRegKey);
|
||||
regKey.createValue(protocolRegValue);
|
||||
regKey.createKey(protocolCmdRegKey).createValue(protocolCmdRegValue);
|
||||
}
|
4
lib/collections/initializers_web.dart
Normal file
4
lib/collections/initializers_web.dart
Normal file
@ -0,0 +1,4 @@
|
||||
// Web implementation - no Windows registry needed
|
||||
Future<void> registerWindowsScheme(String scheme) async {
|
||||
// Web doesn't support custom URL schemes registration
|
||||
}
|
@ -1,89 +1,3 @@
|
||||
import 'package:shadcn_flutter/shadcn_flutter.dart';
|
||||
import 'package:spotube/services/kv_store/kv_store.dart';
|
||||
import 'package:spotube/utils/platform.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
|
||||
class WindowSize {
|
||||
final double height;
|
||||
final double width;
|
||||
final bool maximized;
|
||||
|
||||
WindowSize({
|
||||
required this.height,
|
||||
required this.width,
|
||||
required this.maximized,
|
||||
});
|
||||
|
||||
factory WindowSize.fromJson(Map<String, dynamic> json) => WindowSize(
|
||||
height: json["height"],
|
||||
width: json["width"],
|
||||
maximized: json["maximized"],
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
"height": height,
|
||||
"width": width,
|
||||
"maximized": maximized,
|
||||
};
|
||||
}
|
||||
|
||||
class WindowManagerTools with WidgetsBindingObserver {
|
||||
static WindowManagerTools? _instance;
|
||||
static WindowManagerTools get instance => _instance!;
|
||||
|
||||
WindowManagerTools._();
|
||||
|
||||
static Future<void> initialize() async {
|
||||
await windowManager.ensureInitialized();
|
||||
_instance = WindowManagerTools._();
|
||||
WidgetsBinding.instance.addObserver(instance);
|
||||
|
||||
await windowManager.waitUntilReadyToShow(
|
||||
const WindowOptions(
|
||||
title: "Spotube",
|
||||
backgroundColor: Colors.transparent,
|
||||
minimumSize: Size(300, 700),
|
||||
titleBarStyle: TitleBarStyle.hidden,
|
||||
center: true,
|
||||
),
|
||||
() async {
|
||||
final savedSize = KVStoreService.windowSize;
|
||||
await windowManager.setResizable(true);
|
||||
if (savedSize?.maximized == true &&
|
||||
!(await windowManager.isMaximized())) {
|
||||
await windowManager.maximize();
|
||||
} else if (savedSize != null) {
|
||||
await windowManager.setSize(Size(savedSize.width, savedSize.height));
|
||||
}
|
||||
|
||||
await windowManager.focus();
|
||||
await windowManager.show();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Size? _prevSize;
|
||||
|
||||
@override
|
||||
void didChangeMetrics() async {
|
||||
super.didChangeMetrics();
|
||||
if (kIsMobile) return;
|
||||
final size = await windowManager.getSize();
|
||||
final windowSameDimension =
|
||||
_prevSize?.width == size.width && _prevSize?.height == size.height;
|
||||
|
||||
if (windowSameDimension || _prevSize == null) {
|
||||
_prevSize = size;
|
||||
return;
|
||||
}
|
||||
final isMaximized = await windowManager.isMaximized();
|
||||
await KVStoreService.setWindowSize(
|
||||
WindowSize(
|
||||
height: size.height,
|
||||
width: size.width,
|
||||
maximized: isMaximized,
|
||||
),
|
||||
);
|
||||
_prevSize = size;
|
||||
}
|
||||
}
|
||||
// Conditional exports for window manager tools
|
||||
export 'wm_tools_native.dart'
|
||||
if (dart.library.html) 'wm_tools_web.dart';
|
89
lib/services/wm_tools/wm_tools_native.dart
Normal file
89
lib/services/wm_tools/wm_tools_native.dart
Normal file
@ -0,0 +1,89 @@
|
||||
import 'package:shadcn_flutter/shadcn_flutter.dart';
|
||||
import 'package:spotube/services/kv_store/kv_store.dart';
|
||||
import 'package:spotube/utils/platform.dart';
|
||||
import 'package:window_manager/window_manager.dart';
|
||||
|
||||
class WindowSize {
|
||||
final double height;
|
||||
final double width;
|
||||
final bool maximized;
|
||||
|
||||
WindowSize({
|
||||
required this.height,
|
||||
required this.width,
|
||||
required this.maximized,
|
||||
});
|
||||
|
||||
factory WindowSize.fromJson(Map<String, dynamic> json) => WindowSize(
|
||||
height: json["height"],
|
||||
width: json["width"],
|
||||
maximized: json["maximized"],
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
"height": height,
|
||||
"width": width,
|
||||
"maximized": maximized,
|
||||
};
|
||||
}
|
||||
|
||||
class WindowManagerTools with WidgetsBindingObserver {
|
||||
static WindowManagerTools? _instance;
|
||||
static WindowManagerTools get instance => _instance!;
|
||||
|
||||
WindowManagerTools._();
|
||||
|
||||
static Future<void> initialize() async {
|
||||
await windowManager.ensureInitialized();
|
||||
_instance = WindowManagerTools._();
|
||||
WidgetsBinding.instance.addObserver(instance);
|
||||
|
||||
await windowManager.waitUntilReadyToShow(
|
||||
const WindowOptions(
|
||||
title: "Spotube",
|
||||
backgroundColor: Colors.transparent,
|
||||
minimumSize: Size(300, 700),
|
||||
titleBarStyle: TitleBarStyle.hidden,
|
||||
center: true,
|
||||
),
|
||||
() async {
|
||||
final savedSize = KVStoreService.windowSize;
|
||||
await windowManager.setResizable(true);
|
||||
if (savedSize?.maximized == true &&
|
||||
!(await windowManager.isMaximized())) {
|
||||
await windowManager.maximize();
|
||||
} else if (savedSize != null) {
|
||||
await windowManager.setSize(Size(savedSize.width, savedSize.height));
|
||||
}
|
||||
|
||||
await windowManager.focus();
|
||||
await windowManager.show();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Size? _prevSize;
|
||||
|
||||
@override
|
||||
void didChangeMetrics() async {
|
||||
super.didChangeMetrics();
|
||||
if (kIsMobile) return;
|
||||
final size = await windowManager.getSize();
|
||||
final windowSameDimension =
|
||||
_prevSize?.width == size.width && _prevSize?.height == size.height;
|
||||
|
||||
if (windowSameDimension || _prevSize == null) {
|
||||
_prevSize = size;
|
||||
return;
|
||||
}
|
||||
final isMaximized = await windowManager.isMaximized();
|
||||
await KVStoreService.setWindowSize(
|
||||
WindowSize(
|
||||
height: size.height,
|
||||
width: size.width,
|
||||
maximized: isMaximized,
|
||||
),
|
||||
);
|
||||
_prevSize = size;
|
||||
}
|
||||
}
|
46
lib/services/wm_tools/wm_tools_web.dart
Normal file
46
lib/services/wm_tools/wm_tools_web.dart
Normal file
@ -0,0 +1,46 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
class WindowSize {
|
||||
final double height;
|
||||
final double width;
|
||||
final bool maximized;
|
||||
|
||||
WindowSize({
|
||||
required this.height,
|
||||
required this.width,
|
||||
required this.maximized,
|
||||
});
|
||||
|
||||
factory WindowSize.fromJson(Map<String, dynamic> json) => WindowSize(
|
||||
height: json["height"],
|
||||
width: json["width"],
|
||||
maximized: json["maximized"],
|
||||
);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
"height": height,
|
||||
"width": width,
|
||||
"maximized": maximized,
|
||||
};
|
||||
}
|
||||
|
||||
class WindowManagerTools with WidgetsBindingObserver {
|
||||
static WindowManagerTools? _instance;
|
||||
static WindowManagerTools get instance => _instance!;
|
||||
|
||||
WindowManagerTools._();
|
||||
|
||||
static Future<void> initialize() async {
|
||||
// Web doesn't need window manager initialization
|
||||
_instance = WindowManagerTools._();
|
||||
WidgetsBinding.instance.addObserver(instance);
|
||||
}
|
||||
|
||||
Size? _prevSize;
|
||||
|
||||
@override
|
||||
void didChangeMetrics() async {
|
||||
super.didChangeMetrics();
|
||||
// Web implementation - no window size saving needed
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user