-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
354 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import 'dart:core'; | ||
|
||
import 'package:wox/entity/wox_theme.dart'; | ||
import 'package:wox/utils/wox_http_util.dart'; | ||
|
||
class WoxApi { | ||
WoxApi._privateConstructor(); | ||
|
||
static final WoxApi _instance = WoxApi._privateConstructor(); | ||
|
||
static WoxApi get instance => _instance; | ||
|
||
Future<WoxTheme> loadTheme() async { | ||
return await WoxHttpUtil.instance.postData<WoxTheme>("/theme", null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
class WoxResponse { | ||
bool? success; | ||
String? message; | ||
dynamic data; | ||
|
||
WoxResponse({this.success, this.message, this.data}); | ||
|
||
WoxResponse.fromJson(Map<String, dynamic> json) { | ||
success = json['Success']; | ||
message = json['Message']; | ||
data = json['Data']; | ||
} | ||
|
||
Map<String, dynamic> toJson() { | ||
final Map<String, dynamic> data = <String, dynamic>{}; | ||
data['Success'] = success; | ||
data['Message'] = message; | ||
if (this.data != null) { | ||
data['Data'] = this.data!.toJson(); | ||
} | ||
return data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
class WoxTheme { | ||
String? themeId; | ||
String? themeName; | ||
String? themeAuthor; | ||
String? themeUrl; | ||
String? version; | ||
String? appBackgroundColor; | ||
int? appPaddingLeft; | ||
int? appPaddingTop; | ||
int? appPaddingRight; | ||
int? appPaddingBottom; | ||
int? resultContainerPaddingLeft; | ||
int? resultContainerPaddingTop; | ||
int? resultContainerPaddingRight; | ||
int? resultContainerPaddingBottom; | ||
int? resultItemBorderRadius; | ||
int? resultItemPaddingLeft; | ||
int? resultItemPaddingTop; | ||
int? resultItemPaddingRight; | ||
int? resultItemPaddingBottom; | ||
String? resultItemTitleColor; | ||
String? resultItemSubTitleColor; | ||
String? resultItemBorderLeft; | ||
String? resultItemActiveBackgroundColor; | ||
String? resultItemActiveTitleColor; | ||
String? resultItemActiveSubTitleColor; | ||
String? resultItemActiveBorderLeft; | ||
String? queryBoxFontColor; | ||
String? queryBoxBackgroundColor; | ||
int? queryBoxBorderRadius; | ||
String? actionContainerBackgroundColor; | ||
String? actionContainerHeaderFontColor; | ||
int? actionContainerPaddingLeft; | ||
int? actionContainerPaddingTop; | ||
int? actionContainerPaddingRight; | ||
int? actionContainerPaddingBottom; | ||
String? actionItemActiveBackgroundColor; | ||
String? actionItemActiveFontColor; | ||
String? actionItemFontColor; | ||
String? actionQueryBoxFontColor; | ||
String? actionQueryBoxBackgroundColor; | ||
int? actionQueryBoxBorderRadius; | ||
String? previewFontColor; | ||
String? previewSplitLineColor; | ||
String? previewPropertyTitleColor; | ||
String? previewPropertyContentColor; | ||
|
||
WoxTheme( | ||
{themeId, | ||
themeName, | ||
themeAuthor, | ||
themeUrl, | ||
version, | ||
appBackgroundColor, | ||
appPaddingLeft, | ||
appPaddingTop, | ||
appPaddingRight, | ||
appPaddingBottom, | ||
resultContainerPaddingLeft, | ||
resultContainerPaddingTop, | ||
resultContainerPaddingRight, | ||
resultContainerPaddingBottom, | ||
resultItemBorderRadius, | ||
resultItemPaddingLeft, | ||
resultItemPaddingTop, | ||
resultItemPaddingRight, | ||
resultItemPaddingBottom, | ||
resultItemTitleColor, | ||
resultItemSubTitleColor, | ||
resultItemBorderLeft, | ||
resultItemActiveBackgroundColor, | ||
resultItemActiveTitleColor, | ||
resultItemActiveSubTitleColor, | ||
resultItemActiveBorderLeft, | ||
queryBoxFontColor, | ||
queryBoxBackgroundColor, | ||
queryBoxBorderRadius, | ||
actionContainerBackgroundColor, | ||
actionContainerHeaderFontColor, | ||
actionContainerPaddingLeft, | ||
actionContainerPaddingTop, | ||
actionContainerPaddingRight, | ||
actionContainerPaddingBottom, | ||
actionItemActiveBackgroundColor, | ||
actionItemActiveFontColor, | ||
actionItemFontColor, | ||
actionQueryBoxFontColor, | ||
actionQueryBoxBackgroundColor, | ||
actionQueryBoxBorderRadius, | ||
previewFontColor, | ||
previewSplitLineColor, | ||
previewPropertyTitleColor, | ||
previewPropertyContentColor}); | ||
|
||
WoxTheme.fromJson(Map<String, dynamic> json) { | ||
themeId = json['ThemeId']; | ||
themeName = json['ThemeName']; | ||
themeAuthor = json['ThemeAuthor']; | ||
themeUrl = json['ThemeUrl']; | ||
version = json['Version']; | ||
appBackgroundColor = json['AppBackgroundColor']; | ||
appPaddingLeft = json['AppPaddingLeft']; | ||
appPaddingTop = json['AppPaddingTop']; | ||
appPaddingRight = json['AppPaddingRight']; | ||
appPaddingBottom = json['AppPaddingBottom']; | ||
resultContainerPaddingLeft = json['ResultContainerPaddingLeft']; | ||
resultContainerPaddingTop = json['ResultContainerPaddingTop']; | ||
resultContainerPaddingRight = json['ResultContainerPaddingRight']; | ||
resultContainerPaddingBottom = json['ResultContainerPaddingBottom']; | ||
resultItemBorderRadius = json['ResultItemBorderRadius']; | ||
resultItemPaddingLeft = json['ResultItemPaddingLeft']; | ||
resultItemPaddingTop = json['ResultItemPaddingTop']; | ||
resultItemPaddingRight = json['ResultItemPaddingRight']; | ||
resultItemPaddingBottom = json['ResultItemPaddingBottom']; | ||
resultItemTitleColor = json['ResultItemTitleColor']; | ||
resultItemSubTitleColor = json['ResultItemSubTitleColor']; | ||
resultItemBorderLeft = json['ResultItemBorderLeft']; | ||
resultItemActiveBackgroundColor = json['ResultItemActiveBackgroundColor']; | ||
resultItemActiveTitleColor = json['ResultItemActiveTitleColor']; | ||
resultItemActiveSubTitleColor = json['ResultItemActiveSubTitleColor']; | ||
resultItemActiveBorderLeft = json['ResultItemActiveBorderLeft']; | ||
queryBoxFontColor = json['QueryBoxFontColor']; | ||
queryBoxBackgroundColor = json['QueryBoxBackgroundColor']; | ||
queryBoxBorderRadius = json['QueryBoxBorderRadius']; | ||
actionContainerBackgroundColor = json['ActionContainerBackgroundColor']; | ||
actionContainerHeaderFontColor = json['ActionContainerHeaderFontColor']; | ||
actionContainerPaddingLeft = json['ActionContainerPaddingLeft']; | ||
actionContainerPaddingTop = json['ActionContainerPaddingTop']; | ||
actionContainerPaddingRight = json['ActionContainerPaddingRight']; | ||
actionContainerPaddingBottom = json['ActionContainerPaddingBottom']; | ||
actionItemActiveBackgroundColor = json['ActionItemActiveBackgroundColor']; | ||
actionItemActiveFontColor = json['ActionItemActiveFontColor']; | ||
actionItemFontColor = json['ActionItemFontColor']; | ||
actionQueryBoxFontColor = json['ActionQueryBoxFontColor']; | ||
actionQueryBoxBackgroundColor = json['ActionQueryBoxBackgroundColor']; | ||
actionQueryBoxBorderRadius = json['ActionQueryBoxBorderRadius']; | ||
previewFontColor = json['PreviewFontColor']; | ||
previewSplitLineColor = json['PreviewSplitLineColor']; | ||
previewPropertyTitleColor = json['PreviewPropertyTitleColor']; | ||
previewPropertyContentColor = json['PreviewPropertyContentColor']; | ||
} | ||
|
||
Map<String, dynamic> toJson() { | ||
final Map<String, dynamic> data = <String, dynamic>{}; | ||
data['ThemeId'] = themeId; | ||
data['ThemeName'] = themeName; | ||
data['ThemeAuthor'] = themeAuthor; | ||
data['ThemeUrl'] = themeUrl; | ||
data['Version'] = version; | ||
data['AppBackgroundColor'] = appBackgroundColor; | ||
data['AppPaddingLeft'] = appPaddingLeft; | ||
data['AppPaddingTop'] = appPaddingTop; | ||
data['AppPaddingRight'] = appPaddingRight; | ||
data['AppPaddingBottom'] = appPaddingBottom; | ||
data['ResultContainerPaddingLeft'] = resultContainerPaddingLeft; | ||
data['ResultContainerPaddingTop'] = resultContainerPaddingTop; | ||
data['ResultContainerPaddingRight'] = resultContainerPaddingRight; | ||
data['ResultContainerPaddingBottom'] = resultContainerPaddingBottom; | ||
data['ResultItemBorderRadius'] = resultItemBorderRadius; | ||
data['ResultItemPaddingLeft'] = resultItemPaddingLeft; | ||
data['ResultItemPaddingTop'] = resultItemPaddingTop; | ||
data['ResultItemPaddingRight'] = resultItemPaddingRight; | ||
data['ResultItemPaddingBottom'] = resultItemPaddingBottom; | ||
data['ResultItemTitleColor'] = resultItemTitleColor; | ||
data['ResultItemSubTitleColor'] = resultItemSubTitleColor; | ||
data['ResultItemBorderLeft'] = resultItemBorderLeft; | ||
data['ResultItemActiveBackgroundColor'] = resultItemActiveBackgroundColor; | ||
data['ResultItemActiveTitleColor'] = resultItemActiveTitleColor; | ||
data['ResultItemActiveSubTitleColor'] = resultItemActiveSubTitleColor; | ||
data['ResultItemActiveBorderLeft'] = resultItemActiveBorderLeft; | ||
data['QueryBoxFontColor'] = queryBoxFontColor; | ||
data['QueryBoxBackgroundColor'] = queryBoxBackgroundColor; | ||
data['QueryBoxBorderRadius'] = queryBoxBorderRadius; | ||
data['ActionContainerBackgroundColor'] = actionContainerBackgroundColor; | ||
data['ActionContainerHeaderFontColor'] = actionContainerHeaderFontColor; | ||
data['ActionContainerPaddingLeft'] = actionContainerPaddingLeft; | ||
data['ActionContainerPaddingTop'] = actionContainerPaddingTop; | ||
data['ActionContainerPaddingRight'] = actionContainerPaddingRight; | ||
data['ActionContainerPaddingBottom'] = actionContainerPaddingBottom; | ||
data['ActionItemActiveBackgroundColor'] = actionItemActiveBackgroundColor; | ||
data['ActionItemActiveFontColor'] = actionItemActiveFontColor; | ||
data['ActionItemFontColor'] = actionItemFontColor; | ||
data['ActionQueryBoxFontColor'] = actionQueryBoxFontColor; | ||
data['ActionQueryBoxBackgroundColor'] = actionQueryBoxBackgroundColor; | ||
data['ActionQueryBoxBorderRadius'] = actionQueryBoxBorderRadius; | ||
data['PreviewFontColor'] = previewFontColor; | ||
data['PreviewSplitLineColor'] = previewSplitLineColor; | ||
data['PreviewPropertyTitleColor'] = previewPropertyTitleColor; | ||
data['PreviewPropertyContentColor'] = previewPropertyContentColor; | ||
return data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import 'package:wox/entity/wox_theme.dart'; | ||
|
||
class EntityFactory { | ||
static T generateOBJ<T>(Map<String, dynamic> json) { | ||
if (T.toString() == "WoxTheme") { | ||
return WoxTheme.fromJson(json) as T; | ||
} else { | ||
return json as T; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import 'package:dio/dio.dart'; | ||
import 'package:wox/entity/wox_response.dart'; | ||
import 'package:wox/utils/entity_factory.dart'; | ||
|
||
class WoxHttpUtil { | ||
final Dio _dio = Dio(); | ||
final String _baseUrl = 'http://localhost:34987'; | ||
|
||
WoxHttpUtil._privateConstructor(); | ||
|
||
static final WoxHttpUtil _instance = WoxHttpUtil._privateConstructor(); | ||
|
||
static WoxHttpUtil get instance => _instance; | ||
|
||
Future<T> getData<T>(String url, {Map<String, dynamic>? params}) async { | ||
try { | ||
final response = await _dio.get(_baseUrl + url, queryParameters: params); | ||
WoxResponse woxResponse = WoxResponse.fromJson(response.data); | ||
if (woxResponse.success == false) throw Exception(woxResponse.message); | ||
return EntityFactory.generateOBJ<T>(woxResponse.data); | ||
} catch (e) { | ||
throw Exception('Failed to fetch data: $e'); | ||
} | ||
} | ||
|
||
Future<T> postData<T>(String url, dynamic data) async { | ||
try { | ||
final response = await _dio.post(_baseUrl + url, data: data); | ||
WoxResponse woxResponse = WoxResponse.fromJson(response.data); | ||
if (woxResponse.success == false) throw Exception(woxResponse.message); | ||
return EntityFactory.generateOBJ<T>(woxResponse.data); | ||
} catch (e) { | ||
throw Exception('Failed to post data: $e'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import 'package:wox/api/wox_api.dart'; | ||
import 'package:wox/entity/wox_theme.dart'; | ||
|
||
class WoxThemeUtil { | ||
late WoxTheme _currentTheme; | ||
|
||
WoxThemeUtil._privateConstructor(); | ||
|
||
static final WoxThemeUtil _instance = WoxThemeUtil._privateConstructor(); | ||
|
||
static WoxThemeUtil get instance => _instance; | ||
|
||
Future<void> loadTheme() async { | ||
WoxApi.instance.loadTheme().then((value) { | ||
_currentTheme = value; | ||
}); | ||
} | ||
|
||
WoxTheme get currentTheme => _currentTheme; | ||
} |
Oops, something went wrong.