-
Notifications
You must be signed in to change notification settings - Fork 85
Detect whether the Debug Extension was built for dev or release #1800
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
Changes from 5 commits
c6c50cf
ac505de
9f16fab
d62a64b
718f895
c4d1528
277717b
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 |
---|---|---|
|
@@ -7,41 +7,71 @@ library logger; | |
|
||
import 'package:js/js.dart'; | ||
|
||
import 'web_api.dart'; | ||
|
||
// Switch to true for debug logging. | ||
bool _enableDebugLogging = true; | ||
import 'utils.dart'; | ||
|
||
enum _LogLevel { | ||
info, | ||
warn, | ||
error, | ||
} | ||
|
||
debugLog(String msg, {String? prefix}) { | ||
debugLog( | ||
String msg, { | ||
String? prefix, | ||
bool devOnly = true, | ||
}) { | ||
_log(msg, prefix: prefix); | ||
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. needs to pass 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. Ah good catch! |
||
} | ||
|
||
debugWarn(String msg, {String? prefix}) { | ||
debugWarn( | ||
String msg, { | ||
String? prefix, | ||
bool devOnly = true, | ||
}) { | ||
_log(msg, prefix: prefix, level: _LogLevel.warn); | ||
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. same as above |
||
} | ||
|
||
debugError(String msg, {String? prefix}) { | ||
debugError( | ||
String msg, { | ||
String? prefix, | ||
bool devOnly = true, | ||
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. same as above |
||
}) { | ||
_log(msg, prefix: prefix, level: _LogLevel.error); | ||
} | ||
|
||
void _log(String msg, {_LogLevel? level, String? prefix}) { | ||
if (!_enableDebugLogging) return; | ||
void _log( | ||
String msg, { | ||
bool devOnly = true, | ||
_LogLevel? level, | ||
String? prefix, | ||
}) { | ||
if (devOnly && !isDevMode()) return; | ||
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. Would it be reasonable to rename 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. Sg, switched to verbose! |
||
final logMsg = prefix != null ? '[$prefix] $msg' : msg; | ||
final logLevel = level ?? _LogLevel.info; | ||
switch (logLevel) { | ||
case _LogLevel.error: | ||
console.error(logMsg); | ||
_console.error(logMsg); | ||
break; | ||
case _LogLevel.warn: | ||
console.warn(logMsg); | ||
_console.warn(logMsg); | ||
break; | ||
case _LogLevel.info: | ||
console.log(logMsg); | ||
_console.log(logMsg); | ||
} | ||
} | ||
|
||
@JS('console') | ||
external _Console get _console; | ||
|
||
@JS() | ||
@anonymous | ||
class _Console { | ||
external void log(String header, | ||
[String style1, String style2, String style3]); | ||
|
||
external void warn(String header, | ||
[String style1, String style2, String style3]); | ||
|
||
external void error(String header, | ||
[String style1, String style2, String style3]); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
@JS() | ||
library utils; | ||
|
||
import 'dart:js_util'; | ||
|
||
import 'package:js/js.dart'; | ||
|
||
import 'chrome_api.dart'; | ||
|
||
bool? _isDevMode; | ||
|
||
bool isDevMode() { | ||
if (_isDevMode != null) { | ||
return _isDevMode!; | ||
} | ||
final extensionManifest = chrome.runtime.getManifest(); | ||
final extensionName = getProperty(extensionManifest, 'name') ?? ''; | ||
return extensionName.contains('DEV'); | ||
} |
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.
Thanks! That is really helpful to distinguish them from each other!