-
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
1 parent
724b6ec
commit 614e862
Showing
10 changed files
with
216 additions
and
119 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,54 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:flutter/widgets.dart'; | ||
import 'package:get/get.dart'; | ||
import 'package:logger/logger.dart'; | ||
import 'package:web_socket_channel/web_socket_channel.dart'; | ||
import 'package:window_manager/window_manager.dart'; | ||
import 'package:wox/entities/show_app_params.dart'; | ||
import 'package:wox/entities/websocket_msg.dart'; | ||
|
||
class WoxController extends GetxController { | ||
final query = "".obs; | ||
final queryTextFieldController = TextEditingController(); | ||
late final WebSocketChannel channel; | ||
|
||
void connect() { | ||
var channel = WebSocketChannel.connect(Uri.parse("ws://localhost:34987/ws")); | ||
channel.stream.listen((event) { | ||
var msg = WebsocketMsg.fromJson(jsonDecode(event)); | ||
if (msg.type == "ToggleApp") { | ||
toggleApp(msg.data); | ||
} | ||
}); | ||
} | ||
|
||
Future<void> toggleApp(ShowAppParams params) async { | ||
Logger().i("Toggle app"); | ||
var isVisible = await windowManager.isVisible(); | ||
if (isVisible) { | ||
hide(); | ||
} else { | ||
show(params); | ||
} | ||
} | ||
|
||
void hide() { | ||
windowManager.hide(); | ||
} | ||
|
||
void show(ShowAppParams params) { | ||
windowManager.show(); | ||
windowManager.focus(); | ||
if (params.position != null) { | ||
windowManager.setPosition(Offset(params.position!.x as double, params.position!.y as double)); | ||
} | ||
} | ||
|
||
void onQueryChanged(String value) { | ||
query.value = value; | ||
Logger().i("Query changed: $value"); | ||
|
||
windowManager.setSize(Size(800, (value.length + 1) * 100), animate: false); | ||
} | ||
} |
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,29 @@ | ||
typedef SelectionType = String; | ||
typedef LastQueryMode = String; | ||
|
||
const SelectionType selectionTypeText = "text"; | ||
const SelectionType selectionTypeFile = "file"; | ||
|
||
const LastQueryMode lastQueryModePreserve = "preserve"; | ||
const LastQueryMode lastQueryModeEmpty = "empty"; | ||
|
||
class Selection { | ||
SelectionType? type; | ||
|
||
// Only available when Type is SelectionTypeText | ||
String? text; | ||
|
||
// Only available when Type is SelectionTypeFile | ||
List<String>? filePaths; | ||
} | ||
|
||
class ChangedQuery { | ||
String? queryType; | ||
String? queryText; | ||
Selection? querySelection; | ||
} | ||
|
||
class QueryHistory { | ||
ChangedQuery? query; | ||
int? timestamp; | ||
} |
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,19 @@ | ||
import 'package:wox/entities/query.dart'; | ||
|
||
typedef PositionType = String; | ||
|
||
const PositionType positionTypeMouseScreen = "MouseScreen"; | ||
const PositionType positionTypeLastLocation = "LastLocation"; | ||
|
||
class Position { | ||
PositionType? type; | ||
int? x; | ||
int? y; | ||
} | ||
|
||
class ShowAppParams { | ||
bool? selectAll; | ||
Position? position; | ||
List<QueryHistory>? queryHistories; | ||
LastQueryMode? lastQueryMode; | ||
} |
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,27 @@ | ||
class WebsocketMsg { | ||
String? id; | ||
String? type; | ||
String? method; | ||
bool? success; | ||
dynamic data; | ||
|
||
WebsocketMsg({this.id, this.type, this.method, this.success, this.data}); | ||
|
||
WebsocketMsg.fromJson(Map<String, dynamic> json) { | ||
id = json['Id']; | ||
type = json['Type']; | ||
method = json['Method']; | ||
success = json['Success']; | ||
data = json['Data']; | ||
} | ||
|
||
Map<String, dynamic> toJson() { | ||
return <String, dynamic>{ | ||
'Id': id, | ||
'Type': type, | ||
'Method': method, | ||
'Success': success, | ||
'Data': 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
Empty file.
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,26 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter/services.dart'; | ||
import 'package:get/get.dart'; | ||
import 'package:wox/controller.dart'; | ||
|
||
class QueryBoxView extends GetView<WoxController> { | ||
const QueryBoxView({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return RawKeyboardListener( | ||
focusNode: FocusNode(), | ||
onKey: (event) { | ||
if (event.logicalKey == LogicalKeyboardKey.escape) { | ||
controller.hide(); | ||
} | ||
}, | ||
child: TextField( | ||
controller: controller.queryTextFieldController, | ||
onChanged: (value) { | ||
controller.onQueryChanged(value); | ||
}, | ||
), | ||
); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -31,4 +31,4 @@ SPEC CHECKSUMS: | |
|
||
PODFILE CHECKSUM: 16208599a12443d53889ba2270a4985981cfb204 | ||
|
||
COCOAPODS: 1.12.1 | ||
COCOAPODS: 1.11.3 |
Oops, something went wrong.