mirror of https://github.com/Wox-launcher/Wox
refactor(ui): Refactor ToolbarInfo handling
- Updated toolbar management to utilize new methods for emptying toolbar sides. - Replaced direct instantiation of ToolbarInfo with emptyRightSide and emptyLeftSide methods for better clarity and maintainability. - Introduced copyWith method in ToolbarInfo for easier updates to toolbar properties without full re-instantiation.
This commit is contained in:
parent
4797037ae8
commit
fda4d4df3a
|
@ -65,7 +65,7 @@ func (a *APIImpl) Notify(ctx context.Context, message string) {
|
|||
GetPluginManager().GetUI().Notify(ctx, common.NotifyMsg{
|
||||
PluginId: a.pluginInstance.Metadata.Id,
|
||||
Text: a.GetTranslation(ctx, message),
|
||||
DisplaySeconds: 8,
|
||||
DisplaySeconds: 5,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -344,10 +344,10 @@ func (s *Store) InstallFromLocal(ctx context.Context, filePath string) error {
|
|||
logger.Error(ctx, fmt.Sprintf("failed to load plugin %s(%s): %s", pluginMetadata.Name, pluginMetadata.Version, loadErr.Error()))
|
||||
|
||||
// remove plugin directory
|
||||
removeErr := os.RemoveAll(pluginDirectory)
|
||||
if removeErr != nil {
|
||||
logger.Error(ctx, fmt.Sprintf("failed to remove plugin directory %s: %s", pluginDirectory, removeErr.Error()))
|
||||
}
|
||||
// removeErr := os.RemoveAll(pluginDirectory)
|
||||
// if removeErr != nil {
|
||||
// logger.Error(ctx, fmt.Sprintf("failed to remove plugin directory %s: %s", pluginDirectory, removeErr.Error()))
|
||||
// }
|
||||
|
||||
return fmt.Errorf("failed to load plugin %s(%s): %s", pluginMetadata.Name, pluginMetadata.Version, loadErr.Error())
|
||||
}
|
||||
|
|
|
@ -112,45 +112,6 @@ func (u *uiImpl) isNotifyInToolbar(ctx context.Context, pluginId string) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
respData, err := u.invokeWebsocketMethod(ctx, "GetCurrentQuery", nil)
|
||||
if err != nil {
|
||||
logger.Error(ctx, fmt.Sprintf("isNotifyInToolbar error: %s", err.Error()))
|
||||
return false
|
||||
}
|
||||
//first marshal to json , then unmarshal to entity.PlainQuery
|
||||
jsonData, marshalErr := json.Marshal(respData)
|
||||
if marshalErr != nil {
|
||||
logger.Error(ctx, fmt.Sprintf("isNotifyInToolbar marshal error: %s", marshalErr.Error()))
|
||||
return false
|
||||
}
|
||||
var currentQuery common.PlainQuery
|
||||
unmarshalErr := json.Unmarshal(jsonData, ¤tQuery)
|
||||
if unmarshalErr != nil {
|
||||
logger.Error(ctx, fmt.Sprintf("isNotifyInToolbar unmarshal error: %s", unmarshalErr.Error()))
|
||||
return false
|
||||
}
|
||||
|
||||
// if current query is plugin specific query, we show notify in toolbar
|
||||
if currentQuery.QueryType == plugin.QueryTypeSelection {
|
||||
return true
|
||||
}
|
||||
|
||||
queryPlugin, pluginInstance, queryErr := plugin.GetPluginManager().NewQuery(ctx, currentQuery)
|
||||
if queryErr != nil {
|
||||
logger.Error(ctx, fmt.Sprintf("isNotifyInToolbar new query error: %s", queryErr.Error()))
|
||||
return false
|
||||
}
|
||||
if pluginInstance == nil {
|
||||
logger.Error(ctx, "isNotifyInToolbar plugin instance not found")
|
||||
return false
|
||||
}
|
||||
|
||||
if !queryPlugin.IsGlobalQuery() && pluginInstance.Metadata.Id == pluginId {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -592,7 +592,7 @@ class WoxLauncherController extends GetxController {
|
|||
);
|
||||
} else {
|
||||
Logger.instance.debug(traceId, "update toolbar to empty because of query changed and is empty");
|
||||
toolbar.value = ToolbarInfo.empty();
|
||||
toolbar.value = toolbar.value.emptyRightSide();
|
||||
}
|
||||
|
||||
await resizeHeight();
|
||||
|
@ -873,13 +873,7 @@ class WoxLauncherController extends GetxController {
|
|||
Future.delayed(Duration(seconds: msg.displaySeconds), () {
|
||||
// only hide toolbar msg when the text is the same as the one we are showing
|
||||
if (toolbar.value.text == msg.text) {
|
||||
toolbar.value = ToolbarInfo(
|
||||
text: "",
|
||||
icon: WoxImage.empty(),
|
||||
action: toolbar.value.action,
|
||||
actionName: toolbar.value.actionName,
|
||||
hotkey: toolbar.value.hotkey,
|
||||
);
|
||||
toolbar.value = toolbar.value.emptyLeftSide();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -975,7 +969,7 @@ class WoxLauncherController extends GetxController {
|
|||
|
||||
// only update action and hotkey if it's different from the current one
|
||||
if (toolbar.value.actionName != action.name || toolbar.value.hotkey != action.hotkey) {
|
||||
toolbar.value = ToolbarInfo(
|
||||
toolbar.value = toolbar.value.copyWith(
|
||||
hotkey: "enter",
|
||||
actionName: action.name,
|
||||
action: () {
|
||||
|
@ -1066,7 +1060,7 @@ class WoxLauncherController extends GetxController {
|
|||
// if query is not empty, update the toolbar after 100ms to avoid flickering
|
||||
cleanToolbarTimer = Timer(Duration(milliseconds: cleanToolbarDelay), () {
|
||||
Logger.instance.debug(traceId, "update toolbar to empty because of query changed");
|
||||
toolbar.value = ToolbarInfo.empty();
|
||||
toolbar.value = toolbar.value.emptyRightSide();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,30 @@ class ToolbarInfo {
|
|||
);
|
||||
}
|
||||
|
||||
ToolbarInfo copyWith({
|
||||
WoxImage? icon,
|
||||
String? text,
|
||||
String? actionName,
|
||||
String? hotkey,
|
||||
Function()? action,
|
||||
}) {
|
||||
return ToolbarInfo(
|
||||
icon: icon ?? this.icon,
|
||||
text: text ?? this.text,
|
||||
actionName: actionName ?? this.actionName,
|
||||
hotkey: hotkey ?? this.hotkey,
|
||||
action: action ?? this.action,
|
||||
);
|
||||
}
|
||||
|
||||
ToolbarInfo emptyRightSide() {
|
||||
return ToolbarInfo(icon: icon, text: text, actionName: null, hotkey: null, action: null);
|
||||
}
|
||||
|
||||
ToolbarInfo emptyLeftSide() {
|
||||
return ToolbarInfo(icon: null, text: null, actionName: actionName, hotkey: hotkey, action: action);
|
||||
}
|
||||
|
||||
// text and hotkey are both empty
|
||||
bool isEmpty() {
|
||||
return (text == null || text!.isEmpty) && (hotkey == null || hotkey!.isEmpty);
|
||||
|
|
Loading…
Reference in New Issue