-
-
Notifications
You must be signed in to change notification settings - Fork 238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
POC: Move package:web
access to separate package
#2110
Changes from 4 commits
c7ecaca
e0c9796
016ffc1
bd8e02d
7da63f0
55adc7c
c8d7033
de51ed6
5c0480b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import 'dart:html' as html show window, Window; | ||
|
||
import '../sentry_options.dart'; | ||
import 'window.dart'; | ||
|
||
Window createWindow(SentryOptions options) { | ||
return HttpWindow(html.window); | ||
} | ||
|
||
class HttpWindow implements Window { | ||
HttpWindow(this._window); | ||
|
||
final html.Window _window; | ||
|
||
@override | ||
WindowScreen get screen => HttpWindowScreen(_window); | ||
|
||
@override | ||
WindowNavigator get navigator => HttpWindowNavigator(_window); | ||
|
||
@override | ||
WindowLocation get location => HttpWindowLocation(_window); | ||
|
||
@override | ||
double get devicePixelRatio => _window.devicePixelRatio.toDouble(); | ||
} | ||
|
||
class HttpWindowScreen implements WindowScreen { | ||
HttpWindowScreen(this._window); | ||
|
||
final html.Window _window; | ||
|
||
@override | ||
int get availableHeight => _window.screen?.available.height.toInt() ?? 0; | ||
|
||
@override | ||
int get availableWidth => _window.screen?.available.width.toInt() ?? 0; | ||
|
||
@override | ||
ScreenOrientation? get orientation => | ||
_window.screen?.orientation?.type == "portrait" | ||
? ScreenOrientation.portrait | ||
: _window.screen?.orientation?.type == "landscape" | ||
? ScreenOrientation.landscape | ||
: null; | ||
} | ||
|
||
class HttpWindowNavigator implements WindowNavigator { | ||
HttpWindowNavigator(this._window); | ||
|
||
final html.Window _window; | ||
|
||
@override | ||
String get userAgent => _window.navigator.userAgent; | ||
|
||
@override | ||
bool? get onLine => _window.navigator.onLine; | ||
|
||
@override | ||
double? get deviceMemory => _window.navigator.deviceMemory?.toDouble(); | ||
} | ||
|
||
class HttpWindowLocation implements WindowLocation { | ||
HttpWindowLocation(this._window); | ||
|
||
final html.Window _window; | ||
|
||
@override | ||
String? get pathname => _window.location.pathname; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
|
||
import '../sentry_options.dart'; | ||
import 'window.dart'; | ||
|
||
Window createWindow(SentryOptions options) { | ||
return NoopWindow(); | ||
} | ||
|
||
class NoopWindow implements Window { | ||
|
||
@override | ||
WindowScreen get screen => NoopWindowScreen(); | ||
|
||
@override | ||
WindowNavigator get navigator => NoopWindowNavigator(); | ||
|
||
@override | ||
WindowLocation get location => NoopWindowLocation(); | ||
|
||
@override | ||
double get devicePixelRatio => 1.0; | ||
} | ||
|
||
class NoopWindowScreen implements WindowScreen { | ||
NoopWindowScreen(); | ||
|
||
@override | ||
int get availableHeight => 0; | ||
|
||
@override | ||
int get availableWidth => 0; | ||
|
||
@override | ||
ScreenOrientation? get orientation => null; | ||
} | ||
|
||
class NoopWindowNavigator implements WindowNavigator { | ||
NoopWindowNavigator(); | ||
|
||
@override | ||
String get userAgent => "--"; | ||
|
||
@override | ||
bool? get onLine => null; | ||
|
||
@override | ||
double? get deviceMemory => null; | ||
} | ||
|
||
class NoopWindowLocation implements WindowLocation { | ||
NoopWindowLocation(); | ||
|
||
@override | ||
String? get pathname => null; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import '../sentry_options.dart'; | ||
import 'noop_window.dart'; | ||
import 'window.dart'; | ||
|
||
// Get window from options or noop | ||
Window createWindow(SentryOptions options) { | ||
return options.window() ?? NoopWindow(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We create the since we don't use the options inside the technically the user could provide their own Window implementation but I don't think it's likely that they do that |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
abstract class Window { | ||
|
||
WindowScreen get screen; | ||
WindowNavigator get navigator; | ||
WindowLocation get location; | ||
|
||
double get devicePixelRatio; | ||
} | ||
|
||
abstract class WindowScreen { | ||
WindowScreen(); | ||
|
||
int get availableHeight; | ||
int get availableWidth; | ||
|
||
ScreenOrientation? get orientation; | ||
} | ||
|
||
abstract class WindowNavigator { | ||
WindowNavigator(); | ||
|
||
String get userAgent; | ||
|
||
bool? get onLine; | ||
|
||
double? get deviceMemory; | ||
} | ||
|
||
abstract class WindowLocation { | ||
String? get pathname; | ||
} | ||
|
||
enum ScreenOrientation { | ||
portrait, | ||
landscape, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import 'package:drift/backends.dart'; | ||
import 'package:drift/drift.dart'; | ||
import 'package:drift/native.dart'; | ||
|
||
QueryExecutor inMemoryExecutor() { | ||
return NativeDatabase.memory(); | ||
} | ||
// import 'package:drift/backends.dart'; | ||
// import 'package:drift/drift.dart'; | ||
// import 'package:drift/native.dart'; | ||
// | ||
// QueryExecutor inMemoryExecutor() { | ||
// return NativeDatabase.memory(); | ||
// } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
import 'package:drift/drift.dart'; | ||
|
||
Never _unsupported() { | ||
throw UnsupportedError( | ||
'No suitable database implementation was found on this platform.'); | ||
} | ||
|
||
// Depending on the platform the app is compiled to, the following stubs will | ||
// be replaced with the methods in native.dart or web.dart | ||
|
||
QueryExecutor inMemoryExecutor() { | ||
return _unsupported(); | ||
} | ||
|
||
Future<void> validateDatabaseSchema(GeneratedDatabase database) async { | ||
_unsupported(); | ||
} | ||
// import 'package:drift/drift.dart'; | ||
// | ||
// Never _unsupported() { | ||
// throw UnsupportedError( | ||
// 'No suitable database implementation was found on this platform.'); | ||
// } | ||
// | ||
// // Depending on the platform the app is compiled to, the following stubs will | ||
// // be replaced with the methods in native.dart or web.dart | ||
// | ||
// QueryExecutor inMemoryExecutor() { | ||
// return _unsupported(); | ||
// } | ||
// | ||
// Future<void> validateDatabaseSchema(GeneratedDatabase database) async { | ||
// _unsupported(); | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing this order probably breaks stuff in unpredictable ways...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we have to change the ordering?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok nvm I understand.
We'll have to think further about this. Like you said this might break stuff / have side effects
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can have a static
setWindow()
function which sets an internal window and then assign that to options when calling init.The user just needs to call the setWindow function before SentryFlutter.init if they wanna do wasm
at least that way we can keep the ordering. maybe there's better ways
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still a breaking change, isn't it? As in, things that worked before for users won't work anymore unless they change their code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tbh I'm not sure, wasm compilation only works on the latest stable channel so they all have to upgrade flutter afaik and it's not working right now for them anyway.
non-wasm users won't have to care about this stuff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I meant is that it would be breaking for existing users targeting web? Or am I missing something.