mirror of https://github.com/Wox-launcher/Wox
Add theme restore functionality and toolbar in the ui
This commit is contained in:
parent
8328c3f613
commit
f6470c7b46
|
@ -51,6 +51,10 @@ class WoxTheme {
|
||||||
late String previewPropertyTitleColor;
|
late String previewPropertyTitleColor;
|
||||||
late String previewPropertyContentColor;
|
late String previewPropertyContentColor;
|
||||||
late String previewTextSelectionColor;
|
late String previewTextSelectionColor;
|
||||||
|
late String toolbarFontColor;
|
||||||
|
late String toolbarBackgroundColor;
|
||||||
|
late int toolbarPaddingLeft;
|
||||||
|
late int toolbarPaddingRight;
|
||||||
|
|
||||||
WoxTheme(
|
WoxTheme(
|
||||||
{themeId,
|
{themeId,
|
||||||
|
@ -100,7 +104,11 @@ class WoxTheme {
|
||||||
previewSplitLineColor,
|
previewSplitLineColor,
|
||||||
previewPropertyTitleColor,
|
previewPropertyTitleColor,
|
||||||
previewPropertyContentColor,
|
previewPropertyContentColor,
|
||||||
previewTextSelectionColor});
|
previewTextSelectionColor,
|
||||||
|
toolbarFontColor,
|
||||||
|
toolbarBackgroundColor,
|
||||||
|
toolbarPaddingLeft,
|
||||||
|
toolbarPaddingRight});
|
||||||
|
|
||||||
WoxTheme.fromJson(Map<String, dynamic> json) {
|
WoxTheme.fromJson(Map<String, dynamic> json) {
|
||||||
themeId = json['ThemeId'];
|
themeId = json['ThemeId'];
|
||||||
|
@ -153,6 +161,10 @@ class WoxTheme {
|
||||||
previewPropertyTitleColor = json['PreviewPropertyTitleColor'];
|
previewPropertyTitleColor = json['PreviewPropertyTitleColor'];
|
||||||
previewPropertyContentColor = json['PreviewPropertyContentColor'];
|
previewPropertyContentColor = json['PreviewPropertyContentColor'];
|
||||||
previewTextSelectionColor = json['PreviewTextSelectionColor'];
|
previewTextSelectionColor = json['PreviewTextSelectionColor'];
|
||||||
|
toolbarFontColor = json['ToolbarFontColor'];
|
||||||
|
toolbarBackgroundColor = json['ToolbarBackgroundColor'];
|
||||||
|
toolbarPaddingLeft = json['ToolbarPaddingLeft'];
|
||||||
|
toolbarPaddingRight = json['ToolbarPaddingRight'];
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, dynamic> toJson() {
|
Map<String, dynamic> toJson() {
|
||||||
|
@ -207,6 +219,10 @@ class WoxTheme {
|
||||||
data['PreviewPropertyTitleColor'] = previewPropertyTitleColor;
|
data['PreviewPropertyTitleColor'] = previewPropertyTitleColor;
|
||||||
data['PreviewPropertyContentColor'] = previewPropertyContentColor;
|
data['PreviewPropertyContentColor'] = previewPropertyContentColor;
|
||||||
data['PreviewTextSelectionColor'] = previewTextSelectionColor;
|
data['PreviewTextSelectionColor'] = previewTextSelectionColor;
|
||||||
|
data['ToolbarFontColor'] = toolbarFontColor;
|
||||||
|
data['ToolbarBackgroundColor'] = toolbarBackgroundColor;
|
||||||
|
data['ToolbarPaddingLeft'] = toolbarPaddingLeft;
|
||||||
|
data['ToolbarPaddingRight'] = toolbarPaddingRight;
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import 'package:from_css_color/from_css_color.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:wox/modules/launcher/views/wox_query_box_view.dart';
|
import 'package:wox/modules/launcher/views/wox_query_box_view.dart';
|
||||||
import 'package:wox/modules/launcher/views/wox_query_result_view.dart';
|
import 'package:wox/modules/launcher/views/wox_query_result_view.dart';
|
||||||
|
import 'package:wox/modules/launcher/views/wox_query_toolbar_view.dart';
|
||||||
import 'package:wox/modules/launcher/wox_launcher_controller.dart';
|
import 'package:wox/modules/launcher/wox_launcher_controller.dart';
|
||||||
|
|
||||||
class WoxLauncherView extends GetView<WoxLauncherController> {
|
class WoxLauncherView extends GetView<WoxLauncherController> {
|
||||||
|
@ -14,20 +15,28 @@ class WoxLauncherView extends GetView<WoxLauncherController> {
|
||||||
return Obx(() {
|
return Obx(() {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
backgroundColor: fromCssColor(controller.woxTheme.value.appBackgroundColor),
|
backgroundColor: fromCssColor(controller.woxTheme.value.appBackgroundColor),
|
||||||
body: Padding(
|
body: DropTarget(
|
||||||
padding: EdgeInsets.only(
|
onDragDone: (DropDoneDetails details) {
|
||||||
top: controller.woxTheme.value.appPaddingTop.toDouble(),
|
controller.handleDropFiles(details);
|
||||||
right: controller.woxTheme.value.appPaddingRight.toDouble(),
|
},
|
||||||
bottom: controller.woxTheme.value.appPaddingBottom.toDouble(),
|
child: Column(
|
||||||
left: controller.woxTheme.value.appPaddingLeft.toDouble(),
|
children: [
|
||||||
),
|
Padding(
|
||||||
child: DropTarget(
|
padding: EdgeInsets.only(
|
||||||
onDragDone: (DropDoneDetails details) {
|
top: controller.woxTheme.value.appPaddingTop.toDouble(),
|
||||||
controller.handleDropFiles(details);
|
right: controller.woxTheme.value.appPaddingRight.toDouble(),
|
||||||
},
|
bottom: controller.woxTheme.value.appPaddingBottom.toDouble(),
|
||||||
child: const Column(
|
left: controller.woxTheme.value.appPaddingLeft.toDouble(),
|
||||||
children: [WoxQueryBoxView(), WoxQueryResultView()],
|
),
|
||||||
),
|
child: const Column(
|
||||||
|
children: [
|
||||||
|
WoxQueryBoxView(),
|
||||||
|
WoxQueryResultView(),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
controller.queryResults.isNotEmpty ? const WoxQueryToolbarView() : const SizedBox(),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
@ -4,16 +4,10 @@ import 'package:from_css_color/from_css_color.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:uuid/v4.dart';
|
import 'package:uuid/v4.dart';
|
||||||
import 'package:window_manager/window_manager.dart';
|
import 'package:window_manager/window_manager.dart';
|
||||||
import 'package:wox/api/wox_api.dart';
|
|
||||||
import 'package:wox/components/wox_image_view.dart';
|
import 'package:wox/components/wox_image_view.dart';
|
||||||
import 'package:wox/entity/wox_image.dart';
|
import 'package:wox/modules/launcher/wox_launcher_controller.dart';
|
||||||
import 'package:wox/enums/wox_image_type_enum.dart';
|
|
||||||
import 'package:wox/enums/wox_query_type_enum.dart';
|
|
||||||
import 'package:wox/enums/wox_selection_type_enum.dart';
|
|
||||||
import 'package:wox/utils/log.dart';
|
import 'package:wox/utils/log.dart';
|
||||||
|
|
||||||
import '../wox_launcher_controller.dart';
|
|
||||||
|
|
||||||
class WoxQueryBoxView extends GetView<WoxLauncherController> {
|
class WoxQueryBoxView extends GetView<WoxLauncherController> {
|
||||||
const WoxQueryBoxView({super.key});
|
const WoxQueryBoxView({super.key});
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:from_css_color/from_css_color.dart';
|
||||||
|
import 'package:get/get.dart';
|
||||||
|
import 'package:wox/modules/launcher/wox_launcher_controller.dart';
|
||||||
|
import 'package:wox/utils/wox_theme_util.dart';
|
||||||
|
|
||||||
|
class WoxQueryToolbarView extends GetView<WoxLauncherController> {
|
||||||
|
const WoxQueryToolbarView({super.key});
|
||||||
|
|
||||||
|
Widget leftTip() {
|
||||||
|
return const SizedBox();
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget rightTip() {
|
||||||
|
return Row(
|
||||||
|
children: [
|
||||||
|
Text("Actions Command + J", style: TextStyle(color: fromCssColor(controller.woxTheme.value.toolbarFontColor))),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Obx(() {
|
||||||
|
return SizedBox(
|
||||||
|
height: WoxThemeUtil.instance.getResultTipHeight(),
|
||||||
|
child: Container(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: fromCssColor(controller.woxTheme.value.toolbarBackgroundColor),
|
||||||
|
),
|
||||||
|
child: Padding(
|
||||||
|
padding: EdgeInsets.only(left: controller.woxTheme.value.toolbarPaddingLeft.toDouble(), right: controller.woxTheme.value.toolbarPaddingRight.toDouble()),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
leftTip(),
|
||||||
|
rightTip(),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -160,6 +160,10 @@ class WoxLauncherController extends GetxController implements WoxLauncherInterfa
|
||||||
resizeHeight();
|
resizeHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getActiveQueryResult() {
|
||||||
|
return queryResults[_activeResultIndex.value];
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> executeResultAction(String traceId) async {
|
Future<void> executeResultAction(String traceId) async {
|
||||||
if (queryResults.isEmpty) {
|
if (queryResults.isEmpty) {
|
||||||
|
@ -167,7 +171,7 @@ class WoxLauncherController extends GetxController implements WoxLauncherInterfa
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger.instance.debug(traceId, "user execute result action");
|
Logger.instance.debug(traceId, "user execute result action");
|
||||||
WoxQueryResult woxQueryResult = queryResults[_activeResultIndex.value];
|
WoxQueryResult woxQueryResult = getActiveQueryResult();
|
||||||
WoxResultAction woxResultAction = WoxResultAction.empty();
|
WoxResultAction woxResultAction = WoxResultAction.empty();
|
||||||
if (isShowActionPanel.value) {
|
if (isShowActionPanel.value) {
|
||||||
if (filterResultActions.isNotEmpty) {
|
if (filterResultActions.isNotEmpty) {
|
||||||
|
@ -508,9 +512,11 @@ class WoxLauncherController extends GetxController implements WoxLauncherInterfa
|
||||||
if (isShowActionPanel.value || isShowPreviewPanel.value) {
|
if (isShowActionPanel.value || isShowPreviewPanel.value) {
|
||||||
resultHeight = WoxThemeUtil.instance.getResultListViewHeightByCount(10);
|
resultHeight = WoxThemeUtil.instance.getResultListViewHeightByCount(10);
|
||||||
}
|
}
|
||||||
final totalHeight = WoxThemeUtil.instance.getQueryBoxHeight() +
|
if (queryResults.isNotEmpty) {
|
||||||
resultHeight +
|
resultHeight += woxTheme.value.resultContainerPaddingTop + woxTheme.value.resultContainerPaddingBottom;
|
||||||
(queryResults.isNotEmpty ? woxTheme.value.resultContainerPaddingTop + woxTheme.value.resultContainerPaddingBottom : 0);
|
resultHeight += WoxThemeUtil.instance.getResultTipHeight();
|
||||||
|
}
|
||||||
|
final totalHeight = WoxThemeUtil.instance.getQueryBoxHeight() + resultHeight;
|
||||||
if (Platform.isWindows) {
|
if (Platform.isWindows) {
|
||||||
// on windows, if I set screen ratio to 2.0, then the window height should add more 4.5 pixel, otherwise it will show render error
|
// on windows, if I set screen ratio to 2.0, then the window height should add more 4.5 pixel, otherwise it will show render error
|
||||||
// still don't know why. here is the test result: ratio -> additional window height
|
// still don't know why. here is the test result: ratio -> additional window height
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
const int MAX_LIST_VIEW_ITEM_COUNT = 10;
|
const int MAX_LIST_VIEW_ITEM_COUNT = 10;
|
||||||
const double QUERY_BOX_BASE_HEIGHT = 55.0;
|
const double QUERY_BOX_BASE_HEIGHT = 55.0;
|
||||||
const double RESULT_ITEM_BASE_HEIGHT = 50.0;
|
const double RESULT_ITEM_BASE_HEIGHT = 50.0;
|
||||||
|
const double RESULT_BOTTOM_TIP_BASE_HEIGHT = 40.0;
|
||||||
|
|
|
@ -30,6 +30,10 @@ class WoxThemeUtil {
|
||||||
return RESULT_ITEM_BASE_HEIGHT + currentTheme.resultItemPaddingTop + currentTheme.resultItemPaddingBottom;
|
return RESULT_ITEM_BASE_HEIGHT + currentTheme.resultItemPaddingTop + currentTheme.resultItemPaddingBottom;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double getResultTipHeight() {
|
||||||
|
return RESULT_BOTTOM_TIP_BASE_HEIGHT;
|
||||||
|
}
|
||||||
|
|
||||||
double getResultListViewHeightByCount(int count) {
|
double getResultListViewHeightByCount(int count) {
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"wox/ai"
|
"wox/ai"
|
||||||
"wox/plugin"
|
"wox/plugin"
|
||||||
"wox/resource"
|
"wox/resource"
|
||||||
|
"wox/setting"
|
||||||
"wox/setting/definition"
|
"wox/setting/definition"
|
||||||
"wox/share"
|
"wox/share"
|
||||||
"wox/util"
|
"wox/util"
|
||||||
|
@ -44,6 +45,10 @@ func (c *ThemePlugin) GetMetadata() plugin.Metadata {
|
||||||
Command: "ai",
|
Command: "ai",
|
||||||
Description: "Generate a new theme with AI",
|
Description: "Generate a new theme with AI",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Command: "restore",
|
||||||
|
Description: "Remove all custom themes and restore to default",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
SettingDefinitions: definition.PluginSettingDefinitions{
|
SettingDefinitions: definition.PluginSettingDefinitions{
|
||||||
{
|
{
|
||||||
|
@ -76,12 +81,15 @@ func (c *ThemePlugin) Query(ctx context.Context, query plugin.Query) []plugin.Qu
|
||||||
if query.Command == "ai" {
|
if query.Command == "ai" {
|
||||||
return c.queryAI(ctx, query)
|
return c.queryAI(ctx, query)
|
||||||
}
|
}
|
||||||
|
if query.Command == "restore" {
|
||||||
|
return c.queryRestore(ctx, query)
|
||||||
|
}
|
||||||
|
|
||||||
ui := plugin.GetPluginManager().GetUI()
|
ui := plugin.GetPluginManager().GetUI()
|
||||||
return lo.FilterMap(ui.GetAllThemes(ctx), func(theme share.Theme, _ int) (plugin.QueryResult, bool) {
|
return lo.FilterMap(ui.GetAllThemes(ctx), func(theme share.Theme, _ int) (plugin.QueryResult, bool) {
|
||||||
match, _ := IsStringMatchScore(ctx, theme.ThemeName, query.Search)
|
match, _ := IsStringMatchScore(ctx, theme.ThemeName, query.Search)
|
||||||
if match {
|
if match {
|
||||||
return plugin.QueryResult{
|
result := plugin.QueryResult{
|
||||||
Title: theme.ThemeName,
|
Title: theme.ThemeName,
|
||||||
Icon: themeIcon,
|
Icon: themeIcon,
|
||||||
Actions: []plugin.QueryResultAction{
|
Actions: []plugin.QueryResultAction{
|
||||||
|
@ -93,7 +101,23 @@ func (c *ThemePlugin) Query(ctx context.Context, query plugin.Query) []plugin.Qu
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}, true
|
}
|
||||||
|
if theme.IsSystem {
|
||||||
|
result.Tails = append(result.Tails, plugin.QueryResultTail{
|
||||||
|
Type: plugin.QueryResultTailTypeText,
|
||||||
|
Text: "System",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
currentThemeId := setting.GetSettingManager().GetWoxSetting(ctx).ThemeId
|
||||||
|
if currentThemeId == theme.ThemeId {
|
||||||
|
result.Group = "Current"
|
||||||
|
result.GroupScore = 100
|
||||||
|
} else {
|
||||||
|
result.Group = "Available"
|
||||||
|
result.GroupScore = 50
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, true
|
||||||
} else {
|
} else {
|
||||||
return plugin.QueryResult{}, false
|
return plugin.QueryResult{}, false
|
||||||
}
|
}
|
||||||
|
@ -238,3 +262,21 @@ func (c *ThemePlugin) queryAI(ctx context.Context, query plugin.Query) []plugin.
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *ThemePlugin) queryRestore(ctx context.Context, query plugin.Query) []plugin.QueryResult {
|
||||||
|
return []plugin.QueryResult{
|
||||||
|
{
|
||||||
|
Title: "Remove all custom themes and restore to default",
|
||||||
|
Icon: themeIcon,
|
||||||
|
Actions: []plugin.QueryResultAction{
|
||||||
|
{
|
||||||
|
Name: "Restore",
|
||||||
|
PreventHideAfterAction: true,
|
||||||
|
Action: func(ctx context.Context, actionContext plugin.ActionContext) {
|
||||||
|
plugin.GetPluginManager().GetUI().RestoreTheme(ctx)
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -51,5 +51,9 @@
|
||||||
"PreviewSplitLineColor": "#3a474e",
|
"PreviewSplitLineColor": "#3a474e",
|
||||||
"PreviewPropertyTitleColor": "#b0b3b5",
|
"PreviewPropertyTitleColor": "#b0b3b5",
|
||||||
"PreviewPropertyContentColor": "#f0f0f0",
|
"PreviewPropertyContentColor": "#f0f0f0",
|
||||||
"PreviewTextSelectionColor": "rgba(31, 118, 124, 0.8)"
|
"PreviewTextSelectionColor": "rgba(31, 118, 124, 0.8)",
|
||||||
|
"ToolbarFontColor": "#f0f0f0",
|
||||||
|
"ToolbarBackgroundColor": "rgba(24, 25, 26, 0.4)",
|
||||||
|
"ToolbarPaddingLeft": 10,
|
||||||
|
"ToolbarPaddingRight": 10
|
||||||
}
|
}
|
|
@ -51,5 +51,9 @@
|
||||||
"PreviewSplitLineColor": "#caced0",
|
"PreviewSplitLineColor": "#caced0",
|
||||||
"PreviewPropertyTitleColor": "#716b6b",
|
"PreviewPropertyTitleColor": "#716b6b",
|
||||||
"PreviewPropertyContentColor": "#716b6b",
|
"PreviewPropertyContentColor": "#716b6b",
|
||||||
"PreviewTextSelectionColor": "#529df7"
|
"PreviewTextSelectionColor": "#529df7",
|
||||||
|
"ToolbarFontColor": "#454545",
|
||||||
|
"ToolbarBackgroundColor": "rgba(255,255,255,0.5)",
|
||||||
|
"ToolbarPaddingLeft": 10,
|
||||||
|
"ToolbarPaddingRight": 10
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,5 +51,9 @@
|
||||||
"PreviewSplitLineColor": "#CCCCCC",
|
"PreviewSplitLineColor": "#CCCCCC",
|
||||||
"PreviewPropertyTitleColor": "#999999",
|
"PreviewPropertyTitleColor": "#999999",
|
||||||
"PreviewPropertyContentColor": "#663399",
|
"PreviewPropertyContentColor": "#663399",
|
||||||
"PreviewTextSelectionColor": "rgba(255, 192, 203, 0.8)"
|
"PreviewTextSelectionColor": "rgba(255, 192, 203, 0.8)",
|
||||||
|
"ToolbarFontColor": "#663399",
|
||||||
|
"ToolbarBackgroundColor": "rgba(255, 235, 205, 0.4)",
|
||||||
|
"ToolbarPaddingLeft": 10,
|
||||||
|
"ToolbarPaddingRight": 10
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,5 +51,9 @@
|
||||||
"PreviewSplitLineColor": "#788494",
|
"PreviewSplitLineColor": "#788494",
|
||||||
"PreviewPropertyTitleColor": "#455A64",
|
"PreviewPropertyTitleColor": "#455A64",
|
||||||
"PreviewPropertyContentColor": "#455A64",
|
"PreviewPropertyContentColor": "#455A64",
|
||||||
"PreviewTextSelectionColor": "rgba(173, 216, 230, 0.8)"
|
"PreviewTextSelectionColor": "rgba(173, 216, 230, 0.8)",
|
||||||
|
"ToolbarFontColor": "#455A64",
|
||||||
|
"ToolbarBackgroundColor": "rgba(240, 235, 225, 0.4)",
|
||||||
|
"ToolbarPaddingLeft": 10,
|
||||||
|
"ToolbarPaddingRight": 10
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,5 +51,9 @@
|
||||||
"PreviewSplitLineColor": "#999999",
|
"PreviewSplitLineColor": "#999999",
|
||||||
"PreviewPropertyTitleColor": "#663300",
|
"PreviewPropertyTitleColor": "#663300",
|
||||||
"PreviewPropertyContentColor": "#663300",
|
"PreviewPropertyContentColor": "#663300",
|
||||||
"PreviewTextSelectionColor": "rgba(255, 215, 0, 0.8)"
|
"PreviewTextSelectionColor": "rgba(255, 215, 0, 0.8)",
|
||||||
|
"ToolbarFontColor": "#663300",
|
||||||
|
"ToolbarBackgroundColor": "rgba(245, 245, 220, 0.4)",
|
||||||
|
"ToolbarPaddingLeft": 10,
|
||||||
|
"ToolbarPaddingRight": 10
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
package share
|
package share
|
||||||
|
|
||||||
type Theme struct {
|
type Theme struct {
|
||||||
ThemeId string
|
ThemeId string
|
||||||
ThemeName string
|
ThemeName string
|
||||||
ThemeAuthor string
|
ThemeAuthor string
|
||||||
ThemeUrl string
|
ThemeUrl string
|
||||||
Version string
|
Version string
|
||||||
IsSystem bool
|
Description string
|
||||||
IsInstalled bool
|
ScreenshotUrls []string
|
||||||
|
IsSystem bool
|
||||||
|
IsInstalled bool
|
||||||
|
|
||||||
AppBackgroundColor string
|
AppBackgroundColor string
|
||||||
AppPaddingLeft int
|
AppPaddingLeft int
|
||||||
|
@ -54,6 +56,8 @@ type Theme struct {
|
||||||
PreviewPropertyTitleColor string
|
PreviewPropertyTitleColor string
|
||||||
PreviewPropertyContentColor string
|
PreviewPropertyContentColor string
|
||||||
PreviewTextSelectionColor string
|
PreviewTextSelectionColor string
|
||||||
Description string
|
ToolbarFontColor string
|
||||||
ScreenshotUrls []string
|
ToolbarBackgroundColor string
|
||||||
|
ToolbarPaddingLeft int
|
||||||
|
ToolbarPaddingRight int
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,7 @@ type UI interface {
|
||||||
GetAllThemes(ctx context.Context) []Theme
|
GetAllThemes(ctx context.Context) []Theme
|
||||||
ChangeTheme(ctx context.Context, theme Theme)
|
ChangeTheme(ctx context.Context, theme Theme)
|
||||||
InstallTheme(ctx context.Context, theme Theme)
|
InstallTheme(ctx context.Context, theme Theme)
|
||||||
|
RestoreTheme(ctx context.Context)
|
||||||
}
|
}
|
||||||
|
|
||||||
type ShowContext struct {
|
type ShowContext struct {
|
||||||
|
|
|
@ -1,62 +1,5 @@
|
||||||
package dto
|
package dto
|
||||||
|
|
||||||
type ThemeDto struct {
|
|
||||||
ThemeId string
|
|
||||||
ThemeName string
|
|
||||||
ThemeAuthor string
|
|
||||||
ThemeUrl string
|
|
||||||
Version string
|
|
||||||
IsInstalled bool
|
|
||||||
IsSystem bool
|
|
||||||
IsUpgradable bool
|
|
||||||
|
|
||||||
AppBackgroundColor string
|
|
||||||
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 int
|
|
||||||
ResultItemTitleColor string
|
|
||||||
ResultItemSubTitleColor string
|
|
||||||
ResultItemTailTextColor string
|
|
||||||
ResultItemBorderLeft string
|
|
||||||
ResultItemActiveBackgroundColor string
|
|
||||||
ResultItemActiveTitleColor string
|
|
||||||
ResultItemActiveSubTitleColor string
|
|
||||||
ResultItemActiveBorderLeft string
|
|
||||||
ResultItemActiveTailTextColor string
|
|
||||||
QueryBoxFontColor string
|
|
||||||
QueryBoxBackgroundColor string
|
|
||||||
QueryBoxBorderRadius int
|
|
||||||
QueryBoxCursorColor string
|
|
||||||
QueryBoxTextSelectionColor string
|
|
||||||
ActionContainerBackgroundColor string
|
|
||||||
ActionContainerHeaderFontColor string
|
|
||||||
ActionContainerPaddingLeft int
|
|
||||||
ActionContainerPaddingTop int
|
|
||||||
ActionContainerPaddingRight int
|
|
||||||
ActionContainerPaddingBottom int
|
|
||||||
ActionItemActiveBackgroundColor string
|
|
||||||
ActionItemActiveFontColor string
|
|
||||||
ActionItemFontColor string
|
|
||||||
ActionQueryBoxFontColor string
|
|
||||||
ActionQueryBoxBackgroundColor string
|
|
||||||
ActionQueryBoxBorderRadius int
|
|
||||||
PreviewFontColor string
|
|
||||||
PreviewSplitLineColor string
|
|
||||||
PreviewPropertyTitleColor string
|
|
||||||
PreviewPropertyContentColor string
|
|
||||||
PreviewTextSelectionColor string
|
|
||||||
}
|
|
||||||
|
|
||||||
type SettingTheme struct {
|
type SettingTheme struct {
|
||||||
ThemeId string
|
ThemeId string
|
||||||
ThemeName string
|
ThemeName string
|
||||||
|
|
|
@ -328,11 +328,26 @@ func (m *Manager) AddTheme(ctx context.Context, theme share.Theme) {
|
||||||
|
|
||||||
func (m *Manager) RemoveTheme(ctx context.Context, theme share.Theme) {
|
func (m *Manager) RemoveTheme(ctx context.Context, theme share.Theme) {
|
||||||
m.themes.Delete(theme.ThemeId)
|
m.themes.Delete(theme.ThemeId)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Manager) ChangeToDefaultTheme(ctx context.Context) {
|
||||||
if v, ok := m.themes.Load("53c1d0a4-ffc8-4d90-91dc-b408fb0b9a03"); ok {
|
if v, ok := m.themes.Load("53c1d0a4-ffc8-4d90-91dc-b408fb0b9a03"); ok {
|
||||||
m.ChangeTheme(ctx, v)
|
m.ChangeTheme(ctx, v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Manager) RestoreTheme(ctx context.Context) {
|
||||||
|
var uninstallThemes = m.themes.FilterList(func(key string, theme share.Theme) bool {
|
||||||
|
return !theme.IsSystem
|
||||||
|
})
|
||||||
|
|
||||||
|
for _, theme := range uninstallThemes {
|
||||||
|
GetStoreManager().Uninstall(ctx, theme)
|
||||||
|
}
|
||||||
|
|
||||||
|
m.ChangeToDefaultTheme(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
func (m *Manager) GetThemeById(themeId string) share.Theme {
|
func (m *Manager) GetThemeById(themeId string) share.Theme {
|
||||||
if v, ok := m.themes.Load(themeId); ok {
|
if v, ok := m.themes.Load(themeId); ok {
|
||||||
return v
|
return v
|
||||||
|
|
|
@ -421,6 +421,8 @@ func handleThemeUninstall(w http.ResponseWriter, r *http.Request) {
|
||||||
if uninstallErr != nil {
|
if uninstallErr != nil {
|
||||||
writeErrorResponse(w, "can't uninstall theme: "+uninstallErr.Error())
|
writeErrorResponse(w, "can't uninstall theme: "+uninstallErr.Error())
|
||||||
return
|
return
|
||||||
|
} else {
|
||||||
|
GetUIManager().ChangeToDefaultTheme(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
writeSuccessResponse(w, "")
|
writeSuccessResponse(w, "")
|
||||||
|
|
|
@ -120,6 +120,8 @@ func (s *Store) Install(ctx context.Context, theme share.Theme) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Store) Uninstall(ctx context.Context, theme share.Theme) error {
|
func (s *Store) Uninstall(ctx context.Context, theme share.Theme) error {
|
||||||
|
logger.Info(ctx, fmt.Sprintf("uninstalling theme: %s", theme.ThemeName))
|
||||||
|
|
||||||
if GetUIManager().IsSystemTheme(theme.ThemeId) {
|
if GetUIManager().IsSystemTheme(theme.ThemeId) {
|
||||||
return fmt.Errorf("can't uninstall system theme")
|
return fmt.Errorf("can't uninstall system theme")
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,6 +73,10 @@ func (u *uiImpl) GetAllThemes(ctx context.Context) []share.Theme {
|
||||||
return GetUIManager().GetAllThemes(ctx)
|
return GetUIManager().GetAllThemes(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (u *uiImpl) RestoreTheme(ctx context.Context) {
|
||||||
|
GetUIManager().RestoreTheme(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
func (u *uiImpl) PickFiles(ctx context.Context, params share.PickFilesParams) []string {
|
func (u *uiImpl) PickFiles(ctx context.Context, params share.PickFilesParams) []string {
|
||||||
respData, err := u.invokeWebsocketMethod(ctx, "PickFiles", params)
|
respData, err := u.invokeWebsocketMethod(ctx, "PickFiles", params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -100,6 +100,20 @@ func (h *HashMap[K, V]) Range(f func(K, V) bool) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *HashMap[K, V]) FilterList(f func(K, V) bool) []V {
|
||||||
|
h.rw.RLock()
|
||||||
|
defer h.rw.RUnlock()
|
||||||
|
|
||||||
|
var list []V
|
||||||
|
for k, v := range h.inner {
|
||||||
|
if f(k, v) {
|
||||||
|
list = append(list, v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
|
||||||
func (h *HashMap[K, V]) String() (s string) {
|
func (h *HashMap[K, V]) String() (s string) {
|
||||||
h.Range(func(k K, v V) bool {
|
h.Range(func(k K, v V) bool {
|
||||||
s += fmt.Sprintf("{%+v:%+v}, ", k, v)
|
s += fmt.Sprintf("{%+v:%+v}, ", k, v)
|
||||||
|
|
Loading…
Reference in New Issue