Merge pull request #2041 from 21pages/portable-service
portable service
This commit is contained in:
commit
89a1c8b506
75
Cargo.lock
generated
75
Cargo.lock
generated
@ -1253,7 +1253,7 @@ dependencies = [
|
||||
"libc",
|
||||
"memalloc",
|
||||
"system-configuration",
|
||||
"windows",
|
||||
"windows 0.30.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -4413,6 +4413,8 @@ dependencies = [
|
||||
"serde_derive",
|
||||
"serde_json 1.0.85",
|
||||
"sha2",
|
||||
"shared_memory",
|
||||
"shutdown_hooks",
|
||||
"simple_rc",
|
||||
"sys-locale",
|
||||
"sysinfo",
|
||||
@ -4761,12 +4763,31 @@ dependencies = [
|
||||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shared_memory"
|
||||
version = "0.12.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ba8593196da75d9dc4f69349682bd4c2099f8cde114257d1ef7ef1b33d1aba54"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
"libc",
|
||||
"nix 0.23.1",
|
||||
"rand 0.8.5",
|
||||
"win-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shlex"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3"
|
||||
|
||||
[[package]]
|
||||
name = "shutdown_hooks"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6057adedbec913419c92996f395ba69931acbd50b7d56955394cd3f7bedbfa45"
|
||||
|
||||
[[package]]
|
||||
name = "signal-hook"
|
||||
version = "0.3.14"
|
||||
@ -5844,6 +5865,15 @@ version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "653f141f39ec16bba3c5abe400a0c60da7468261cc2cbf36805022876bc721a8"
|
||||
|
||||
[[package]]
|
||||
name = "win-sys"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5b7b128a98c1cfa201b09eb49ba285887deb3cbe7466a98850eb1adabb452be5"
|
||||
dependencies = [
|
||||
"windows 0.34.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.2.8"
|
||||
@ -5909,6 +5939,19 @@ dependencies = [
|
||||
"windows_x86_64_msvc 0.30.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows"
|
||||
version = "0.34.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "45296b64204227616fdbf2614cefa4c236b98ee64dfaaaa435207ed99fe7829f"
|
||||
dependencies = [
|
||||
"windows_aarch64_msvc 0.34.0",
|
||||
"windows_i686_gnu 0.34.0",
|
||||
"windows_i686_msvc 0.34.0",
|
||||
"windows_x86_64_gnu 0.34.0",
|
||||
"windows_x86_64_msvc 0.34.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-service"
|
||||
version = "0.4.0"
|
||||
@ -5959,6 +6002,12 @@ version = "0.30.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "29277a4435d642f775f63c7d1faeb927adba532886ce0287bd985bffb16b6bca"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.34.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "17cffbe740121affb56fad0fc0e421804adf0ae00891205213b5cecd30db881d"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.36.1"
|
||||
@ -5977,6 +6026,12 @@ version = "0.30.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1145e1989da93956c68d1864f32fb97c8f561a8f89a5125f6a2b7ea75524e4b8"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.34.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2564fde759adb79129d9b4f54be42b32c89970c18ebf93124ca8870a498688ed"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.36.1"
|
||||
@ -5995,6 +6050,12 @@ version = "0.30.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d4a09e3a0d4753b73019db171c1339cd4362c8c44baf1bcea336235e955954a6"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.34.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9cd9d32ba70453522332c14d38814bceeb747d80b3958676007acadd7e166956"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.36.1"
|
||||
@ -6013,6 +6074,12 @@ version = "0.30.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ca64fcb0220d58db4c119e050e7af03c69e6f4f415ef69ec1773d9aab422d5a"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.34.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cfce6deae227ee8d356d19effc141a509cc503dfd1f850622ec4b0f84428e1f4"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.36.1"
|
||||
@ -6031,6 +6098,12 @@ version = "0.30.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "08cabc9f0066848fef4bc6a1c1668e6efce38b661d2aeec75d18d8617eebb5f1"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.34.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d19538ccc21819d01deaf88d6a17eae6596a12e9aafdbb97916fb49896d89de9"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.36.1"
|
||||
|
@ -92,6 +92,8 @@ winreg = "0.10"
|
||||
windows-service = "0.4"
|
||||
virtual_display = { path = "libs/virtual_display" }
|
||||
impersonate_system = { git = "https://github.com/21pages/impersonate-system" }
|
||||
shared_memory = "0.12.4"
|
||||
shutdown_hooks = "0.1.0"
|
||||
|
||||
[target.'cfg(target_os = "macos")'.dependencies]
|
||||
objc = "0.2"
|
||||
|
@ -627,7 +627,7 @@ class CustomAlertDialog extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
void msgBox(String type, String title, String text, String link,
|
||||
void msgBox(String id, String type, String title, String text, String link,
|
||||
OverlayDialogManager dialogManager,
|
||||
{bool? hasCancel}) {
|
||||
dialogManager.dismissAll();
|
||||
@ -672,14 +672,17 @@ void msgBox(String type, String title, String text, String link,
|
||||
if (link.isNotEmpty) {
|
||||
buttons.insert(0, msgBoxButton(translate('JumpLink'), jumplink));
|
||||
}
|
||||
dialogManager.show((setState, close) => CustomAlertDialog(
|
||||
title: _msgBoxTitle(title),
|
||||
content: SelectableText(translate(text),
|
||||
style: const TextStyle(fontSize: 15)),
|
||||
actions: buttons,
|
||||
onSubmit: hasOk ? submit : null,
|
||||
onCancel: hasCancel == true ? cancel : null,
|
||||
));
|
||||
dialogManager.show(
|
||||
(setState, close) => CustomAlertDialog(
|
||||
title: _msgBoxTitle(title),
|
||||
content:
|
||||
SelectableText(translate(text), style: const TextStyle(fontSize: 15)),
|
||||
actions: buttons,
|
||||
onSubmit: hasOk ? submit : null,
|
||||
onCancel: hasCancel == true ? cancel : null,
|
||||
),
|
||||
tag: '$id-$type-$title-$text-$link',
|
||||
);
|
||||
}
|
||||
|
||||
Widget msgBoxButton(String text, void Function() onPressed) {
|
||||
|
@ -163,7 +163,7 @@ class _RemotePageState extends State<RemotePage>
|
||||
super.build(context);
|
||||
return WillPopScope(
|
||||
onWillPop: () async {
|
||||
clientClose(_ffi.dialogManager);
|
||||
clientClose(widget.id, _ffi.dialogManager);
|
||||
return false;
|
||||
},
|
||||
child: MultiProvider(providers: [
|
||||
|
@ -76,7 +76,6 @@ class _DesktopServerPageState extends State<DesktopServerPage>
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(child: ConnectionManager()),
|
||||
SizedBox.fromSize(size: Size(0, 15.0)),
|
||||
],
|
||||
),
|
||||
),
|
||||
@ -486,6 +485,8 @@ class _PrivilegeBoardState extends State<_PrivilegeBoard> {
|
||||
}
|
||||
}
|
||||
|
||||
const double bigMargin = 15;
|
||||
|
||||
class _CmControlPanel extends StatelessWidget {
|
||||
final Client client;
|
||||
|
||||
@ -501,108 +502,141 @@ class _CmControlPanel extends StatelessWidget {
|
||||
}
|
||||
|
||||
buildAuthorized(BuildContext context) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
final bool canElevate = bind.cmCanElevate();
|
||||
final model = Provider.of<ServerModel>(context);
|
||||
final showElevation = canElevate && model.showElevation;
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
Ink(
|
||||
width: 200,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.redAccent, borderRadius: BorderRadius.circular(10)),
|
||||
child: InkWell(
|
||||
onTap: () =>
|
||||
checkClickTime(client.id, () => handleDisconnect(context)),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
translate("Disconnect"),
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
],
|
||||
)),
|
||||
Offstage(
|
||||
offstage: !showElevation,
|
||||
child: buildButton(context, color: Colors.green[700], onClick: () {
|
||||
handleElevate(context);
|
||||
windowManager.minimize();
|
||||
},
|
||||
icon: Icon(
|
||||
Icons.security_sharp,
|
||||
color: Colors.white,
|
||||
),
|
||||
text: 'Elevate',
|
||||
textColor: Colors.white),
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: buildButton(context,
|
||||
color: Colors.redAccent,
|
||||
onClick: handleDisconnect,
|
||||
text: 'Disconnect',
|
||||
textColor: Colors.white)),
|
||||
],
|
||||
)
|
||||
],
|
||||
);
|
||||
)
|
||||
.marginOnly(bottom: showElevation ? 0 : bigMargin)
|
||||
.marginSymmetric(horizontal: showElevation ? 0 : bigMargin);
|
||||
}
|
||||
|
||||
buildDisconnected(BuildContext context) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Ink(
|
||||
width: 200,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: MyTheme.accent, borderRadius: BorderRadius.circular(10)),
|
||||
child: InkWell(
|
||||
onTap: () => handleClose(context),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
translate("Close"),
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
],
|
||||
)),
|
||||
)
|
||||
Expanded(
|
||||
child: buildButton(context,
|
||||
color: MyTheme.accent,
|
||||
onClick: handleClose,
|
||||
text: 'Close',
|
||||
textColor: Colors.white)),
|
||||
],
|
||||
);
|
||||
).marginOnly(bottom: 15).marginSymmetric(horizontal: bigMargin);
|
||||
}
|
||||
|
||||
buildUnAuthorized(BuildContext context) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
final bool canElevate = bind.cmCanElevate();
|
||||
final model = Provider.of<ServerModel>(context);
|
||||
final showElevation = canElevate && model.showElevation;
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
Ink(
|
||||
width: 100,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: MyTheme.accent, borderRadius: BorderRadius.circular(10)),
|
||||
child: InkWell(
|
||||
onTap: () => checkClickTime(client.id, () {
|
||||
handleAccept(context);
|
||||
windowManager.minimize();
|
||||
}),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
translate("Accept"),
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
],
|
||||
)),
|
||||
Offstage(
|
||||
offstage: !showElevation,
|
||||
child: buildButton(context, color: Colors.green[700], onClick: () {
|
||||
handleAccept(context);
|
||||
handleElevate(context);
|
||||
windowManager.minimize();
|
||||
},
|
||||
text: 'Accept',
|
||||
icon: Icon(
|
||||
Icons.security_sharp,
|
||||
color: Colors.white,
|
||||
),
|
||||
textColor: Colors.white),
|
||||
),
|
||||
SizedBox(
|
||||
width: 30,
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Expanded(
|
||||
child: buildButton(context, color: MyTheme.accent, onClick: () {
|
||||
handleAccept(context);
|
||||
windowManager.minimize();
|
||||
}, text: 'Accept', textColor: Colors.white)),
|
||||
Expanded(
|
||||
child: buildButton(context,
|
||||
color: Colors.transparent,
|
||||
border: Border.all(color: Colors.grey),
|
||||
onClick: handleDisconnect,
|
||||
text: 'Cancel',
|
||||
textColor: null)),
|
||||
],
|
||||
),
|
||||
Ink(
|
||||
width: 100,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(color: Colors.grey)),
|
||||
child: InkWell(
|
||||
onTap: () =>
|
||||
checkClickTime(client.id, () => handleDisconnect(context)),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
translate("Cancel"),
|
||||
style: TextStyle(),
|
||||
),
|
||||
],
|
||||
)),
|
||||
)
|
||||
],
|
||||
);
|
||||
)
|
||||
.marginOnly(bottom: showElevation ? 0 : bigMargin)
|
||||
.marginSymmetric(horizontal: showElevation ? 0 : bigMargin);
|
||||
}
|
||||
|
||||
void handleDisconnect(BuildContext context) {
|
||||
buildButton(
|
||||
BuildContext context, {
|
||||
required Color? color,
|
||||
required Function() onClick,
|
||||
Icon? icon,
|
||||
BoxBorder? border,
|
||||
required String text,
|
||||
required Color? textColor,
|
||||
}) {
|
||||
Widget textWidget;
|
||||
if (icon != null) {
|
||||
textWidget = Text(
|
||||
translate(text),
|
||||
style: TextStyle(color: textColor),
|
||||
textAlign: TextAlign.center,
|
||||
);
|
||||
} else {
|
||||
textWidget = Expanded(
|
||||
child: Text(
|
||||
translate(text),
|
||||
style: TextStyle(color: textColor),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
);
|
||||
}
|
||||
return Container(
|
||||
height: 35,
|
||||
decoration: BoxDecoration(
|
||||
color: color, borderRadius: BorderRadius.circular(4), border: border),
|
||||
child: InkWell(
|
||||
onTap: () => checkClickTime(client.id, onClick),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Offstage(offstage: icon == null, child: icon),
|
||||
textWidget,
|
||||
],
|
||||
)),
|
||||
).marginAll(4);
|
||||
}
|
||||
|
||||
void handleDisconnect() {
|
||||
bind.cmCloseConnection(connId: client.id);
|
||||
}
|
||||
|
||||
@ -611,7 +645,13 @@ class _CmControlPanel extends StatelessWidget {
|
||||
model.sendLoginResponse(client, true);
|
||||
}
|
||||
|
||||
void handleClose(BuildContext context) async {
|
||||
void handleElevate(BuildContext context) {
|
||||
final model = Provider.of<ServerModel>(context, listen: false);
|
||||
model.setShowElevation(false);
|
||||
bind.cmElevatePortable(connId: client.id);
|
||||
}
|
||||
|
||||
void handleClose() async {
|
||||
await bind.cmRemoveDisconnectedConnection(connId: client.id);
|
||||
if (await bind.cmGetClientsLength() == 0) {
|
||||
windowManager.close();
|
||||
|
@ -489,7 +489,7 @@ class _RemoteMenubarState extends State<RemoteMenubar> {
|
||||
return IconButton(
|
||||
tooltip: translate('Close'),
|
||||
onPressed: () {
|
||||
clientClose(widget.ffi.dialogManager);
|
||||
clientClose(widget.id, widget.ffi.dialogManager);
|
||||
},
|
||||
icon: const Icon(
|
||||
Icons.close,
|
||||
|
@ -63,7 +63,8 @@ class _FileManagerPageState extends State<FileManagerPage> {
|
||||
leading: Row(children: [
|
||||
IconButton(
|
||||
icon: Icon(Icons.close),
|
||||
onPressed: () => clientClose(gFFI.dialogManager)),
|
||||
onPressed: () =>
|
||||
clientClose(widget.id, gFFI.dialogManager)),
|
||||
]),
|
||||
centerTitle: true,
|
||||
title: ToggleSwitch(
|
||||
|
@ -223,7 +223,7 @@ class _RemotePageState extends State<RemotePage> {
|
||||
|
||||
return WillPopScope(
|
||||
onWillPop: () async {
|
||||
clientClose(gFFI.dialogManager);
|
||||
clientClose(widget.id, gFFI.dialogManager);
|
||||
return false;
|
||||
},
|
||||
child: getRawPointerAndKeyBody(Scaffold(
|
||||
@ -304,7 +304,7 @@ class _RemotePageState extends State<RemotePage> {
|
||||
color: Colors.white,
|
||||
icon: Icon(Icons.clear),
|
||||
onPressed: () {
|
||||
clientClose(gFFI.dialogManager);
|
||||
clientClose(widget.id, gFFI.dialogManager);
|
||||
},
|
||||
)
|
||||
] +
|
||||
|
@ -5,9 +5,9 @@ import '../../common.dart';
|
||||
import '../../models/model.dart';
|
||||
import '../../models/platform_model.dart';
|
||||
|
||||
void clientClose(OverlayDialogManager dialogManager) {
|
||||
msgBox(
|
||||
'', 'Close', 'Are you sure to close the connection?', '', dialogManager);
|
||||
void clientClose(String id, OverlayDialogManager dialogManager) {
|
||||
msgBox(id, '', 'Close', 'Are you sure to close the connection?', '',
|
||||
dialogManager);
|
||||
}
|
||||
|
||||
void showSuccess() {
|
||||
|
@ -192,6 +192,11 @@ class FfiModel with ChangeNotifier {
|
||||
}
|
||||
} else if (name == 'alias') {
|
||||
handleAliasChanged(evt);
|
||||
} else if (name == 'show_elevation') {
|
||||
final show = evt['show'].toString() == 'true';
|
||||
parent.target?.serverModel.setShowElevation(show);
|
||||
} else if (name == 'cancel_msgbox') {
|
||||
cancelMsgBox(evt, peerId);
|
||||
}
|
||||
};
|
||||
}
|
||||
@ -228,6 +233,13 @@ class FfiModel with ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
cancelMsgBox(Map<String, dynamic> evt, String id) {
|
||||
if (parent.target == null) return;
|
||||
final dialogManager = parent.target!.dialogManager;
|
||||
final tag = '$id-${evt['tag']}';
|
||||
dialogManager.dismissByTag(tag);
|
||||
}
|
||||
|
||||
/// Handle the message box event based on [evt] and [id].
|
||||
handleMsgBox(Map<String, dynamic> evt, String id) {
|
||||
if (parent.target == null) return;
|
||||
@ -253,7 +265,7 @@ class FfiModel with ChangeNotifier {
|
||||
showMsgBox(String id, String type, String title, String text, String link,
|
||||
bool hasRetry, OverlayDialogManager dialogManager,
|
||||
{bool? hasCancel}) {
|
||||
msgBox(type, title, text, link, dialogManager, hasCancel: hasCancel);
|
||||
msgBox(id, type, title, text, link, dialogManager, hasCancel: hasCancel);
|
||||
_timer?.cancel();
|
||||
if (hasRetry) {
|
||||
_timer = Timer(Duration(seconds: _reconnects), () {
|
||||
|
@ -27,6 +27,7 @@ class ServerModel with ChangeNotifier {
|
||||
bool _inputOk = false;
|
||||
bool _audioOk = false;
|
||||
bool _fileOk = false;
|
||||
bool _showElevation = true;
|
||||
int _connectStatus = 0; // Rendezvous Server status
|
||||
String _verificationMethod = "";
|
||||
String _temporaryPasswordLength = "";
|
||||
@ -51,6 +52,8 @@ class ServerModel with ChangeNotifier {
|
||||
|
||||
bool get fileOk => _fileOk;
|
||||
|
||||
bool get showElevation => _showElevation;
|
||||
|
||||
int get connectStatus => _connectStatus;
|
||||
|
||||
String get verificationMethod {
|
||||
@ -530,6 +533,13 @@ class ServerModel with ChangeNotifier {
|
||||
final index = _clients.indexWhere((client) => client.id == id);
|
||||
tabController.jumpTo(index);
|
||||
}
|
||||
|
||||
void setShowElevation(bool show) {
|
||||
if (_showElevation != show) {
|
||||
_showElevation = show;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Client {
|
||||
|
@ -61,7 +61,7 @@ impl TraitCapturer for Capturer {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Frame<'a>(&'a [u8]);
|
||||
pub struct Frame<'a>(pub &'a [u8]);
|
||||
|
||||
impl<'a> ops::Deref for Frame<'a> {
|
||||
type Target = [u8];
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
use hbb_common::anyhow::{anyhow, Context};
|
||||
use hbb_common::message_proto::{EncodedVideoFrame, EncodedVideoFrames, Message, VideoFrame};
|
||||
use hbb_common::{ResultType, get_time};
|
||||
use hbb_common::{get_time, ResultType};
|
||||
|
||||
use crate::codec::EncoderApi;
|
||||
use crate::STRIDE_ALIGN;
|
||||
@ -233,7 +233,9 @@ impl EncoderApi for VpxEncoder {
|
||||
|
||||
impl VpxEncoder {
|
||||
pub fn encode(&mut self, pts: i64, data: &[u8], stride_align: usize) -> Result<EncodeFrames> {
|
||||
assert!(2 * data.len() >= 3 * self.width * self.height);
|
||||
if 2 * data.len() < 3 * self.width * self.height {
|
||||
return Err(Error::FailedCall("len not enough".to_string()));
|
||||
}
|
||||
|
||||
let mut image = Default::default();
|
||||
call_vpx_ptr!(vpx_img_wrap(
|
||||
|
@ -20,18 +20,14 @@ use hbb_common::fs::{
|
||||
use hbb_common::message_proto::permission_info::Permission;
|
||||
use hbb_common::protobuf::Message as _;
|
||||
use hbb_common::rendezvous_proto::ConnType;
|
||||
#[cfg(windows)]
|
||||
use hbb_common::tokio::sync::Mutex as TokioMutex;
|
||||
use hbb_common::tokio::{
|
||||
self,
|
||||
sync::mpsc,
|
||||
time::{self, Duration, Instant, Interval},
|
||||
};
|
||||
#[cfg(windows)]
|
||||
use hbb_common::tokio::sync::Mutex as TokioMutex;
|
||||
use hbb_common::{
|
||||
allow_err,
|
||||
message_proto::*,
|
||||
sleep,
|
||||
};
|
||||
use hbb_common::{allow_err, message_proto::*, sleep};
|
||||
use hbb_common::{fs, log, Stream};
|
||||
use std::collections::HashMap;
|
||||
|
||||
@ -998,23 +994,31 @@ impl<T: InvokeUiSession> Remote<T> {
|
||||
}
|
||||
}
|
||||
Some(misc::Union::Uac(uac)) => {
|
||||
let msgtype = "custom-uac-nocancel";
|
||||
let title = "Prompt";
|
||||
let text = "Please wait for confirmation of UAC...";
|
||||
let link = "";
|
||||
if uac {
|
||||
self.handler.msgbox(
|
||||
"custom-uac-nocancel",
|
||||
"Warning",
|
||||
"uac_warning",
|
||||
"",
|
||||
);
|
||||
self.handler.msgbox(msgtype, title, text, link);
|
||||
} else {
|
||||
self.handler
|
||||
.cancel_msgbox(
|
||||
&format!("{}-{}-{}-{}", msgtype, title, text, link,),
|
||||
);
|
||||
}
|
||||
}
|
||||
Some(misc::Union::ForegroundWindowElevated(elevated)) => {
|
||||
let msgtype = "custom-elevated-foreground-nocancel";
|
||||
let title = "Prompt";
|
||||
let text = "elevated_foreground_window_tip";
|
||||
let link = "";
|
||||
if elevated {
|
||||
self.handler.msgbox(
|
||||
"custom-elevated-foreground-nocancel",
|
||||
"Warning",
|
||||
"elevated_foreground_window_warning",
|
||||
"",
|
||||
);
|
||||
self.handler.msgbox(msgtype, title, text, link);
|
||||
} else {
|
||||
self.handler
|
||||
.cancel_msgbox(
|
||||
&format!("{}-{}-{}-{}", msgtype, title, text, link,),
|
||||
);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
|
@ -80,6 +80,11 @@ pub fn core_main() -> Option<Vec<String>> {
|
||||
.ok();
|
||||
}
|
||||
}
|
||||
#[cfg(windows)]
|
||||
if !crate::platform::is_installed() && (_is_elevate || _is_run_as_system) {
|
||||
crate::platform::elevate_or_run_as_system(click_setup, _is_elevate, _is_run_as_system);
|
||||
return None;
|
||||
}
|
||||
if args.is_empty() {
|
||||
std::thread::spawn(move || crate::start_server(false));
|
||||
} else {
|
||||
@ -128,6 +133,13 @@ pub fn core_main() -> Option<Vec<String>> {
|
||||
} else if args[0] == "--tray" {
|
||||
crate::tray::start_tray();
|
||||
return None;
|
||||
} else if args[0] == "--portable-service" {
|
||||
crate::platform::elevate_or_run_as_system(
|
||||
click_setup,
|
||||
_is_elevate,
|
||||
_is_run_as_system,
|
||||
);
|
||||
return None;
|
||||
}
|
||||
}
|
||||
if args[0] == "--remove" {
|
||||
|
@ -228,8 +228,7 @@ impl InvokeUiSession for FlutterHandler {
|
||||
id: i32,
|
||||
entries: &Vec<FileEntry>,
|
||||
path: String,
|
||||
#[allow(unused_variables)]
|
||||
is_local: bool,
|
||||
#[allow(unused_variables)] is_local: bool,
|
||||
only_count: bool,
|
||||
) {
|
||||
// TODO opt
|
||||
@ -327,6 +326,10 @@ impl InvokeUiSession for FlutterHandler {
|
||||
);
|
||||
}
|
||||
|
||||
fn cancel_msgbox(&self, tag: &str) {
|
||||
self.push_event("cancel_msgbox", vec![("tag", tag)]);
|
||||
}
|
||||
|
||||
fn new_message(&self, msg: String) {
|
||||
self.push_event("chat_client_mode", vec![("text", &msg)]);
|
||||
}
|
||||
@ -406,7 +409,7 @@ pub fn session_start_(id: &str, event_stream: StreamSink<EventToUI>) -> ResultTy
|
||||
*session.event_stream.write().unwrap() = Some(event_stream);
|
||||
let session = session.clone();
|
||||
std::thread::spawn(move || {
|
||||
// if flutter : disable keyboard listen
|
||||
// if flutter : disable keyboard listen
|
||||
crate::client::disable_keyboard_listening();
|
||||
io_loop(session);
|
||||
});
|
||||
@ -469,6 +472,10 @@ pub mod connection_manager {
|
||||
fn change_language(&self) {
|
||||
self.push_event("language", vec![]);
|
||||
}
|
||||
|
||||
fn show_elevation(&self, show: bool) {
|
||||
self.push_event("show_elevation", vec![("show", &show.to_string())]);
|
||||
}
|
||||
}
|
||||
|
||||
impl FlutterHandler {
|
||||
|
@ -1010,6 +1010,14 @@ pub fn cm_switch_permission(conn_id: i32, name: String, enabled: bool) {
|
||||
crate::ui_cm_interface::switch_permission(conn_id, name, enabled)
|
||||
}
|
||||
|
||||
pub fn cm_can_elevate() -> SyncReturn<bool> {
|
||||
SyncReturn(crate::ui_cm_interface::can_elevate())
|
||||
}
|
||||
|
||||
pub fn cm_elevate_portable(conn_id: i32) {
|
||||
crate::ui_cm_interface::elevate_portable(conn_id);
|
||||
}
|
||||
|
||||
pub fn main_get_icon() -> String {
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios", feature = "cli")))]
|
||||
return ui_interface::get_icon();
|
||||
|
14
src/ipc.rs
14
src/ipc.rs
@ -130,6 +130,19 @@ pub enum DataControl {
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
#[serde(tag = "t", content = "c")]
|
||||
pub enum DataPortableService {
|
||||
Ping,
|
||||
Pong,
|
||||
ConnCount(Option<usize>),
|
||||
Mouse(Vec<u8>),
|
||||
Key(Vec<u8>),
|
||||
RequestStart,
|
||||
WillClose,
|
||||
CmShowElevation(bool),
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
#[serde(tag = "t", content = "c")]
|
||||
pub enum Data {
|
||||
@ -187,6 +200,7 @@ pub enum Data {
|
||||
Language(String),
|
||||
Empty,
|
||||
Disconnected,
|
||||
DataPortableService(DataPortableService),
|
||||
}
|
||||
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
|
@ -371,9 +371,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Deny LAN Discovery", "拒绝局域网发现"),
|
||||
("Write a message", "输入聊天消息"),
|
||||
("Prompt", "提示"),
|
||||
("elevation_prompt", "以当前用户权限运行软件,可能导致远端在访问本机时,没有足够的权限来操作部分窗口。"),
|
||||
("uac_warning", "暂时无法访问远端设备,因为远端设备正在请求用户账户权限,请等待对方关闭UAC窗口。为避免这个问题,建议在远端设备上安装或者以管理员权限运行本软件。"),
|
||||
("elevated_foreground_window_warning", "暂时无法使用鼠标键盘,因为远端桌面的当前窗口需要更高的权限才能操作, 可以请求对方最小化当前窗口。为避免这个问题,建议在远端设备上安装或者以管理员权限运行本软件。"),
|
||||
("Please wait for confirmation of UAC...", "请等待对方确认UAC..."),
|
||||
("elevated_foreground_window_tip", "远端桌面的当前窗口需要更高的权限才能操作, 暂时无法使用鼠标键盘, 可以请求对方最小化当前窗口, 或者在连接管理窗口点击提升。为避免这个问题,建议在远端设备上安装本软件。"),
|
||||
("Disconnected", "会话已结束"),
|
||||
("Other", "其他"),
|
||||
("Confirm before closing multiple tabs", "关闭多个标签页时向您确认"),
|
||||
@ -389,5 +388,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("This PC", "此电脑"),
|
||||
("or", "或"),
|
||||
("Continue with", "使用"),
|
||||
("Elevate", "提权"),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -371,9 +371,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Deny LAN Discovery", ""),
|
||||
("Write a message", ""),
|
||||
("Prompt", ""),
|
||||
("elevation_prompt", ""),
|
||||
("uac_warning", ""),
|
||||
("elevated_foreground_window_warning", ""),
|
||||
("Please wait for confirmation of UAC...", ""),
|
||||
("elevated_foreground_window_tip", ""),
|
||||
("Disconnected", ""),
|
||||
("Other", ""),
|
||||
("Confirm before closing multiple tabs", ""),
|
||||
@ -389,5 +388,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("This PC", ""),
|
||||
("or", ""),
|
||||
("Continue with", ""),
|
||||
("Elevate", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -371,9 +371,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Deny LAN Discovery", "Afvis LAN Discovery"),
|
||||
("Write a message", "Skriv en besked"),
|
||||
("Prompt", ""),
|
||||
("elevation_prompt", ""),
|
||||
("uac_warning", ""),
|
||||
("elevated_foreground_window_warning", ""),
|
||||
("Please wait for confirmation of UAC...", ""),
|
||||
("elevated_foreground_window_tip", ""),
|
||||
("Disconnected", "Afbrudt"),
|
||||
("Other", ""),
|
||||
("Confirm before closing multiple tabs", ""),
|
||||
@ -389,5 +388,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("This PC", ""),
|
||||
("or", ""),
|
||||
("Continue with", ""),
|
||||
("Elevate", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -371,9 +371,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Deny LAN Discovery", "LAN-Erkennung verbieten"),
|
||||
("Write a message", "Nachricht schreiben"),
|
||||
("Prompt", ""),
|
||||
("elevation_prompt", ""),
|
||||
("uac_warning", ""),
|
||||
("elevated_foreground_window_warning", ""),
|
||||
("Please wait for confirmation of UAC...", ""),
|
||||
("elevated_foreground_window_tip", ""),
|
||||
("Disconnected", ""),
|
||||
("Other", ""),
|
||||
("Confirm before closing multiple tabs", ""),
|
||||
@ -389,5 +388,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("This PC", ""),
|
||||
("or", ""),
|
||||
("Continue with", ""),
|
||||
("Elevate", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -30,9 +30,7 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("android_open_battery_optimizations_tip", "If you want to disable this feature, please go to the next RustDesk application settings page, find and enter [Battery], Uncheck [Unrestricted]"),
|
||||
("remote_restarting_tip", "Remote device is restarting, please close this message box and reconnect with permanent password after a while"),
|
||||
("Are you sure to close the connection?", "Are you sure you want to close the connection?"),
|
||||
("elevation_prompt", "Running software without privilege elevation may cause problems when remote users operate certain windows."),
|
||||
("uac_warning", "Temporarily denied access due to elevation request, please wait for the remote user to accept the UAC dialog. To avoid this problem, it is recommended to install the software on the remote device or run it with administrator privileges."),
|
||||
("elevated_foreground_window_warning", "Temporarily unable to use the mouse and keyboard, because the current window of the remote desktop requires higher privilege to operate, you can request the remote user to minimize the current window. To avoid this problem, it is recommended to install the software on the remote device or run it with administrator privileges."),
|
||||
("elevated_foreground_window_tip", "The current window of the remote desktop requires higher privilege to operate, so it's unable to use the mouse and keyboard temporarily. You can request the remote user to minimize the current window, or click elevation button on the connection management window. To avoid this problem, it is recommended to install the software on the remote device."),
|
||||
("JumpLink", "View"),
|
||||
("Stop service", "Stop Service"),
|
||||
("or", ""),
|
||||
|
@ -371,9 +371,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Deny LAN Discovery", ""),
|
||||
("Write a message", ""),
|
||||
("Prompt", ""),
|
||||
("elevation_prompt", ""),
|
||||
("uac_warning", ""),
|
||||
("elevated_foreground_window_warning", ""),
|
||||
("Please wait for confirmation of UAC...", ""),
|
||||
("elevated_foreground_window_tip", ""),
|
||||
("Disconnected", ""),
|
||||
("Other", ""),
|
||||
("Confirm before closing multiple tabs", ""),
|
||||
@ -389,5 +388,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("This PC", ""),
|
||||
("or", ""),
|
||||
("Continue with", ""),
|
||||
("Elevate", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -371,9 +371,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Deny LAN Discovery", "Denegar descubrimiento de LAN"),
|
||||
("Write a message", "Escribir un mensaje"),
|
||||
("Prompt", ""),
|
||||
("elevation_prompt", ""),
|
||||
("uac_warning", ""),
|
||||
("elevated_foreground_window_warning", ""),
|
||||
("Please wait for confirmation of UAC...", ""),
|
||||
("elevated_foreground_window_tip", ""),
|
||||
("Disconnected", "Desconectado"),
|
||||
("Other", "Otro"),
|
||||
("Confirm before closing multiple tabs", "Confirmar antes de cerrar múltiples pestañas"),
|
||||
@ -389,5 +388,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("This PC", "Este PC"),
|
||||
("or", "o"),
|
||||
("Continue with", "Continuar con"),
|
||||
("Elevate", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -371,9 +371,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Deny LAN Discovery", "غیر فعالسازی جستجو در شبکه"),
|
||||
("Write a message", "یک پیام بنویسید"),
|
||||
("Prompt", ""),
|
||||
("elevation_prompt", "اجرای نرمافزار بدون افزایش امتیاز میتواند باعث ایجاد مشکلاتی در هنگام کار کردن کاربران راه دور با ویندوزهای خاص شود"),
|
||||
("uac_warning", "به دلیل درخواست دسترسی سطح بالا، به طور موقت از دسترسی رد شد. منتظر بمانید تا کاربر راه دور گفتگوی UAC را بپذیرد. برای جلوگیری از این مشکل، توصیه می شود نرم افزار را روی دستگاه از راه دور نصب کنید یا آن را با دسترسی مدیر اجرا کنید."),
|
||||
("elevated_foreground_window_warning", "به طور موقت استفاده از ماوس و صفحه کلید امکان پذیر نیست زیرا پنجره دسکتاپ از راه دور فعلی برای کار کردن به دسترسی های بالاتر نیاز دارد، می توانید از کاربر راه دور بخواهید که پنجره فعلی را به حداقل برساند. برای جلوگیری از این مشکل، توصیه می شود نرم افزار را روی یک دستگاه راه دور نصب کنید یا آن را با دسترسی مدیر اجرا کنید"),
|
||||
("Please wait for confirmation of UAC...", ""),
|
||||
("elevated_foreground_window_tip", ""),
|
||||
("Disconnected", "قطع ارتباط"),
|
||||
("Other", "دیگر"),
|
||||
("Confirm before closing multiple tabs", "بستن چندین برگه را تأیید کنید"),
|
||||
|
@ -371,9 +371,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Deny LAN Discovery", "Interdir la découverte réseau local"),
|
||||
("Write a message", "Ecrire un message"),
|
||||
("Prompt", ""),
|
||||
("elevation_prompt", ""),
|
||||
("uac_warning", ""),
|
||||
("elevated_foreground_window_warning", ""),
|
||||
("Please wait for confirmation of UAC...", ""),
|
||||
("elevated_foreground_window_tip", ""),
|
||||
("Disconnected", "Déconnecté"),
|
||||
("Other", "Divers"),
|
||||
("Confirm before closing multiple tabs", "Confirmer avant de fermer plusieurs onglets"),
|
||||
@ -389,5 +388,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("This PC", "Ce PC"),
|
||||
("or", "ou"),
|
||||
("Continue with", "Continuer avec"),
|
||||
("Elevate", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -371,9 +371,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Deny LAN Discovery", "Felfedezés tiltása"),
|
||||
("Write a message", "Üzenet írása"),
|
||||
("Prompt", ""),
|
||||
("elevation_prompt", "A szoftver jogosultságnövelés nélküli futtatása problémákat okozhat, ha távoli felhasználók bizonyos ablakokat működtetnek."),
|
||||
("uac_warning", "Kérjük, várja meg, amíg a távoli felhasználó elfogadja az UAC párbeszédpanelt. A probléma elkerülése érdekében javasoljuk, hogy telepítse a szoftvert a távoli eszközre, vagy futtassa rendszergazdai jogosultságokkal."),
|
||||
("elevated_foreground_window_warning", "Átmenetileg nem tudja használni az egeret és a billentyűzetet, mert a távoli asztal aktuális ablakának működéséhez magasabb jogosultság szükséges, ezért kérheti a távoli felhasználót, hogy minimalizálja az aktuális ablakot. A probléma elkerülése érdekében javasoljuk, hogy telepítse a szoftvert a távoli eszközre, vagy futtassa rendszergazdai jogosultságokkal."),
|
||||
("Please wait for confirmation of UAC...", ""),
|
||||
("elevated_foreground_window_tip", ""),
|
||||
("Disconnected", "Szétkapcsolva"),
|
||||
("Other", "Egyéb"),
|
||||
("Confirm before closing multiple tabs", "Biztos, hogy bezárja az összes lapot?"),
|
||||
@ -389,5 +388,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("This PC", "Ez a számítógép"),
|
||||
("or", "vagy"),
|
||||
("Continue with", "Folytatás a következővel"),
|
||||
("Elevate", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -371,9 +371,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Deny LAN Discovery", "Tolak Penemuan LAN"),
|
||||
("Write a message", "Menulis pesan"),
|
||||
("Prompt", ""),
|
||||
("elevation_prompt", ""),
|
||||
("uac_warning", ""),
|
||||
("elevated_foreground_window_warning", ""),
|
||||
("Please wait for confirmation of UAC...", ""),
|
||||
("elevated_foreground_window_tip", ""),
|
||||
("Disconnected", "Terputus"),
|
||||
("Other", "Lainnya"),
|
||||
("Confirm before closing multiple tabs", "Konfirmasi sebelum menutup banyak tab"),
|
||||
@ -389,5 +388,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("This PC", ""),
|
||||
("or", ""),
|
||||
("Continue with", ""),
|
||||
("Elevate", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -371,9 +371,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Deny LAN Discovery", ""),
|
||||
("Write a message", ""),
|
||||
("Prompt", ""),
|
||||
("elevation_prompt", ""),
|
||||
("uac_warning", ""),
|
||||
("elevated_foreground_window_warning", ""),
|
||||
("Please wait for confirmation of UAC...", ""),
|
||||
("elevated_foreground_window_tip", ""),
|
||||
("Disconnected", ""),
|
||||
("Other", ""),
|
||||
("Confirm before closing multiple tabs", ""),
|
||||
@ -389,5 +388,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("This PC", ""),
|
||||
("or", ""),
|
||||
("Continue with", ""),
|
||||
("Elevate", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -371,9 +371,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Deny LAN Discovery", ""),
|
||||
("Write a message", ""),
|
||||
("Prompt", ""),
|
||||
("elevation_prompt", ""),
|
||||
("uac_warning", ""),
|
||||
("elevated_foreground_window_warning", ""),
|
||||
("Please wait for confirmation of UAC...", ""),
|
||||
("elevated_foreground_window_tip", ""),
|
||||
("Disconnected", ""),
|
||||
("Other", "他の"),
|
||||
("Confirm before closing multiple tabs", "同時に複数のタブを閉じる前に確認する"),
|
||||
@ -389,5 +388,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("This PC", ""),
|
||||
("or", ""),
|
||||
("Continue with", ""),
|
||||
("Elevate", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -371,9 +371,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Deny LAN Discovery", ""),
|
||||
("Write a message", ""),
|
||||
("Prompt", ""),
|
||||
("elevation_prompt", ""),
|
||||
("uac_warning", ""),
|
||||
("elevated_foreground_window_warning", ""),
|
||||
("Please wait for confirmation of UAC...", ""),
|
||||
("elevated_foreground_window_tip", ""),
|
||||
("Disconnected", ""),
|
||||
("Other", ""),
|
||||
("Confirm before closing multiple tabs", ""),
|
||||
@ -389,5 +388,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("This PC", ""),
|
||||
("or", ""),
|
||||
("Continue with", ""),
|
||||
("Elevate", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -371,9 +371,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Deny LAN Discovery", ""),
|
||||
("Write a message", ""),
|
||||
("Prompt", ""),
|
||||
("elevation_prompt", ""),
|
||||
("uac_warning", ""),
|
||||
("elevated_foreground_window_warning", ""),
|
||||
("Please wait for confirmation of UAC...", ""),
|
||||
("elevated_foreground_window_tip", ""),
|
||||
("Disconnected", ""),
|
||||
("Other", ""),
|
||||
("Confirm before closing multiple tabs", ""),
|
||||
@ -389,5 +388,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("This PC", ""),
|
||||
("or", ""),
|
||||
("Continue with", ""),
|
||||
("Elevate", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -371,9 +371,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Deny LAN Discovery", "Zablokuj Wykrywanie LAN"),
|
||||
("Write a message", "Napisz wiadomość"),
|
||||
("Prompt", "Monit"),
|
||||
("elevation_prompt", "Monit o podwyższeniu uprawnień"),
|
||||
("uac_warning", "Ostrzeżenie UAC"),
|
||||
("elevated_foreground_window_warning", "Pierwszoplanowe okno ostrzeżenia o podwyższeniu uprawnień"),
|
||||
("Please wait for confirmation of UAC...", ""),
|
||||
("elevated_foreground_window_tip", ""),
|
||||
("Disconnected", "Rozłączone"),
|
||||
("Other", "Inne"),
|
||||
("Confirm before closing multiple tabs", "Potwierdź przed zamknięciem wielu kart"),
|
||||
@ -389,5 +388,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("This PC", "Ten komputer"),
|
||||
("or", "albo"),
|
||||
("Continue with", "Kontynuuj z"),
|
||||
("Elevate", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -371,9 +371,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Deny LAN Discovery", ""),
|
||||
("Write a message", ""),
|
||||
("Prompt", ""),
|
||||
("elevation_prompt", ""),
|
||||
("uac_warning", ""),
|
||||
("elevated_foreground_window_warning", ""),
|
||||
("Please wait for confirmation of UAC...", ""),
|
||||
("elevated_foreground_window_tip", ""),
|
||||
("Disconnected", "Desconectado"),
|
||||
("Other", "Outro"),
|
||||
("Confirm before closing multiple tabs", "Confirme antes de fechar vários separadores"),
|
||||
@ -389,5 +388,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("This PC", ""),
|
||||
("or", ""),
|
||||
("Continue with", ""),
|
||||
("Elevate", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -371,9 +371,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Deny LAN Discovery", "Negar descoberta da LAN"),
|
||||
("Write a message", "Escrever uma mensagem"),
|
||||
("Prompt", "Prompt de comando"),
|
||||
("elevation_prompt", "Prompt de comando (Admin)"),
|
||||
("uac_warning", "Aviso UAC"),
|
||||
("elevated_foreground_window_warning", "Aviso de janela de primeiro plano elevado"),
|
||||
("Please wait for confirmation of UAC...", ""),
|
||||
("elevated_foreground_window_tip", ""),
|
||||
("Disconnected", "Desconectado"),
|
||||
("Other", "Outro"),
|
||||
("Confirm before closing multiple tabs", "Confirmar antes de fechar múltiplas abas"),
|
||||
@ -389,5 +388,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("This PC", "Este PC"),
|
||||
("or", "ou"),
|
||||
("Continue with", "Continuar com"),
|
||||
("Elevate", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -371,9 +371,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Deny LAN Discovery", "Запретить обнаружение в локальной сети"),
|
||||
("Write a message", "Написать сообщение"),
|
||||
("Prompt", "Подсказка"),
|
||||
("elevation_prompt", "Запуск программного обеспечения без повышения привилегий может вызвать проблемы, когда удалённые пользователи работают с определёнными окнами."),
|
||||
("uac_warning", "Временно отказано в доступе из-за запроса на повышение прав. Подождите, пока удалённый пользователь примет диалоговое окно UAC. Чтобы избежать этой проблемы, рекомендуется устанавливать программное обеспечение на удалённое устройство или запускать его с правами администратора."),
|
||||
("elevated_foreground_window_warning", "Временно невозможно использовать мышь и клавиатуру, поскольку текущее окно удалённого рабочего стола требует более высоких привилегий для работы, вы можете попросить удалённого пользователя свернуть текущее окно. Чтобы избежать этой проблемы, рекомендуется устанавливать программное обеспечение на удалённое устройство или запускать его с правами администратора."),
|
||||
("Please wait for confirmation of UAC...", ""),
|
||||
("elevated_foreground_window_tip", ""),
|
||||
("Disconnected", "Отключено"),
|
||||
("Other", "Другое"),
|
||||
("Confirm before closing multiple tabs", "Подтверждение закрытия несколько вкладок"),
|
||||
@ -389,5 +388,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("This PC", "Этот компьютер"),
|
||||
("or", "или"),
|
||||
("Continue with", "Продолжить с"),
|
||||
("Elevate", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -371,9 +371,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Deny LAN Discovery", ""),
|
||||
("Write a message", ""),
|
||||
("Prompt", ""),
|
||||
("elevation_prompt", ""),
|
||||
("uac_warning", ""),
|
||||
("elevated_foreground_window_warning", ""),
|
||||
("Please wait for confirmation of UAC...", ""),
|
||||
("elevated_foreground_window_tip", ""),
|
||||
("Disconnected", ""),
|
||||
("Other", ""),
|
||||
("Confirm before closing multiple tabs", ""),
|
||||
@ -389,5 +388,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("This PC", ""),
|
||||
("or", ""),
|
||||
("Continue with", ""),
|
||||
("Elevate", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -371,9 +371,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Deny LAN Discovery", ""),
|
||||
("Write a message", ""),
|
||||
("Prompt", ""),
|
||||
("elevation_prompt", ""),
|
||||
("uac_warning", ""),
|
||||
("elevated_foreground_window_warning", ""),
|
||||
("Please wait for confirmation of UAC...", ""),
|
||||
("elevated_foreground_window_tip", ""),
|
||||
("Disconnected", ""),
|
||||
("Other", ""),
|
||||
("Confirm before closing multiple tabs", ""),
|
||||
@ -389,5 +388,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("This PC", ""),
|
||||
("or", ""),
|
||||
("Continue with", ""),
|
||||
("Elevate", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -371,9 +371,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Deny LAN Discovery", ""),
|
||||
("Write a message", ""),
|
||||
("Prompt", ""),
|
||||
("elevation_prompt", ""),
|
||||
("uac_warning", ""),
|
||||
("elevated_foreground_window_warning", ""),
|
||||
("Please wait for confirmation of UAC...", ""),
|
||||
("elevated_foreground_window_tip", ""),
|
||||
("Disconnected", ""),
|
||||
("Other", ""),
|
||||
("Confirm before closing multiple tabs", ""),
|
||||
@ -389,5 +388,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("This PC", ""),
|
||||
("or", ""),
|
||||
("Continue with", ""),
|
||||
("Elevate", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -371,9 +371,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Deny LAN Discovery", "拒絕局域網發現"),
|
||||
("Write a message", "輸入聊天消息"),
|
||||
("Prompt", "提示"),
|
||||
("elevation_prompt", "以當前用戶權限運行軟件,可能導致遠端在訪問本機時,沒有足夠的權限來操作部分窗口。"),
|
||||
("uac_warning", "暂时无法访问远端设备,因为远端设备正在请求用户账户权限,请等待对方关闭UAC窗口。为避免这个问题,建议在远端设备上安装或者以管理员权限运行本软件。"),
|
||||
("elevated_foreground_window_warning", "暫時無法使用鼠標鍵盤,因為遠端桌面的當前窗口需要更高的權限才能操作, 可以請求對方最小化當前窗口。為避免這個問題,建議在遠端設備上安裝或者以管理員權限運行本軟件。"),
|
||||
("Please wait for confirmation of UAC...", "請等待對方確認UAC"),
|
||||
("elevated_foreground_window_tip", "遠端桌面的當前窗口需要更高的權限才能操作, 暫時無法使用鼠標鍵盤, 可以請求對方最小化當前窗口, 或者在連接管理窗口點擊提升。為避免這個問題,建議在遠端設備上安裝本軟件。"),
|
||||
("Disconnected", "會話已結束"),
|
||||
("Other", "其他"),
|
||||
("Confirm before closing multiple tabs", "關閉多個分頁前跟我確認"),
|
||||
@ -389,5 +388,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("This PC", ""),
|
||||
("or", ""),
|
||||
("Continue with", ""),
|
||||
("Elevate", "提權"),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -371,9 +371,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Deny LAN Discovery", "Заборонити виявлення локальної мережі"),
|
||||
("Write a message", "Написати повідомлення"),
|
||||
("Prompt", ""),
|
||||
("elevation_prompt", ""),
|
||||
("uac_warning", ""),
|
||||
("elevated_foreground_window_warning", ""),
|
||||
("Please wait for confirmation of UAC...", ""),
|
||||
("elevated_foreground_window_tip", ""),
|
||||
("Disconnected", ""),
|
||||
("Other", ""),
|
||||
("Confirm before closing multiple tabs", ""),
|
||||
@ -389,5 +388,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("This PC", ""),
|
||||
("or", ""),
|
||||
("Continue with", ""),
|
||||
("Elevate", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -371,9 +371,8 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("Deny LAN Discovery", ""),
|
||||
("Write a message", ""),
|
||||
("Prompt", ""),
|
||||
("elevation_prompt", ""),
|
||||
("uac_warning", ""),
|
||||
("elevated_foreground_window_warning", ""),
|
||||
("Please wait for confirmation of UAC...", ""),
|
||||
("elevated_foreground_window_tip", ""),
|
||||
("Disconnected", ""),
|
||||
("Other", ""),
|
||||
("Confirm before closing multiple tabs", ""),
|
||||
@ -389,5 +388,6 @@ pub static ref T: std::collections::HashMap<&'static str, &'static str> =
|
||||
("This PC", ""),
|
||||
("or", ""),
|
||||
("Continue with", ""),
|
||||
("Elevate", ""),
|
||||
].iter().cloned().collect();
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ pub fn get_cursor() -> ResultType<Option<u64>> {
|
||||
unsafe {
|
||||
let mut ci: CURSORINFO = mem::MaybeUninit::uninit().assume_init();
|
||||
ci.cbSize = std::mem::size_of::<CURSORINFO>() as _;
|
||||
if GetCursorInfo(&mut ci) == FALSE {
|
||||
if crate::portable_service::client::get_cursor_info(&mut ci) == FALSE {
|
||||
return Err(io::Error::last_os_error().into());
|
||||
}
|
||||
if ci.flags & CURSOR_SHOWING == 0 {
|
||||
@ -1480,6 +1480,27 @@ pub fn get_user_token(session_id: u32, as_user: bool) -> HANDLE {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run_background(exe: &str, arg: &str) -> ResultType<bool> {
|
||||
let wexe = wide_string(exe);
|
||||
let warg;
|
||||
unsafe {
|
||||
let ret = ShellExecuteW(
|
||||
NULL as _,
|
||||
NULL as _,
|
||||
wexe.as_ptr() as _,
|
||||
if arg.is_empty() {
|
||||
NULL as _
|
||||
} else {
|
||||
warg = wide_string(arg);
|
||||
warg.as_ptr() as _
|
||||
},
|
||||
NULL as _,
|
||||
SW_HIDE,
|
||||
);
|
||||
return Ok(ret as i32 > 32);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run_uac(exe: &str, arg: &str) -> ResultType<bool> {
|
||||
let wop = wide_string("runas");
|
||||
let wexe = wide_string(exe);
|
||||
@ -1542,9 +1563,11 @@ pub fn elevate_or_run_as_system(is_setup: bool, is_elevate: bool, is_run_as_syst
|
||||
} else {
|
||||
"--run-as-system"
|
||||
};
|
||||
|
||||
if is_root() {
|
||||
log::debug!("portable run as system user");
|
||||
if is_run_as_system {
|
||||
log::info!("run portable service");
|
||||
crate::portable_service::server::run_portable_service();
|
||||
}
|
||||
} else {
|
||||
match is_elevated(None) {
|
||||
Ok(elevated) => {
|
||||
|
@ -49,6 +49,8 @@ pub const NAME_POS: &'static str = "";
|
||||
}
|
||||
|
||||
mod connection;
|
||||
#[cfg(windows)]
|
||||
pub mod portable_service;
|
||||
mod service;
|
||||
mod video_qos;
|
||||
pub mod video_service;
|
||||
@ -60,6 +62,7 @@ type ConnMap = HashMap<i32, ConnInner>;
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
pub static ref CHILD_PROCESS: Childs = Default::default();
|
||||
pub static ref CONN_COUNT: Arc<Mutex<usize>> = Default::default();
|
||||
}
|
||||
|
||||
pub struct Server {
|
||||
@ -259,6 +262,7 @@ impl Server {
|
||||
}
|
||||
}
|
||||
self.connections.insert(conn.id(), conn);
|
||||
*CONN_COUNT.lock().unwrap() = self.connections.len();
|
||||
}
|
||||
|
||||
pub fn remove_connection(&mut self, conn: &ConnInner) {
|
||||
@ -266,6 +270,7 @@ impl Server {
|
||||
s.on_unsubscribe(conn.id());
|
||||
}
|
||||
self.connections.remove(&conn.id());
|
||||
*CONN_COUNT.lock().unwrap() = self.connections.len();
|
||||
}
|
||||
|
||||
pub fn close_connections(&mut self) {
|
||||
|
@ -26,12 +26,9 @@ use hbb_common::{
|
||||
use scrap::android::call_main_service_mouse_input;
|
||||
use serde_json::{json, value::Value};
|
||||
use sha2::{Digest, Sha256};
|
||||
use std::sync::{
|
||||
atomic::AtomicI64,
|
||||
mpsc as std_mpsc,
|
||||
};
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
use std::sync::atomic::Ordering;
|
||||
use std::sync::{atomic::AtomicI64, mpsc as std_mpsc};
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
use system_shutdown;
|
||||
|
||||
@ -236,8 +233,12 @@ impl Connection {
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
std::thread::spawn(move || Self::handle_input(rx_input, tx_cloned));
|
||||
let mut second_timer = time::interval(Duration::from_secs(1));
|
||||
#[cfg(windows)]
|
||||
let mut last_uac = false;
|
||||
#[cfg(windows)]
|
||||
let mut last_foreground_window_elevated = false;
|
||||
#[cfg(windows)]
|
||||
let is_installed = crate::platform::is_installed();
|
||||
|
||||
loop {
|
||||
tokio::select! {
|
||||
@ -341,6 +342,12 @@ impl Connection {
|
||||
};
|
||||
conn.send(msg_out).await;
|
||||
}
|
||||
#[cfg(windows)]
|
||||
ipc::Data::DataPortableService(ipc::DataPortableService::RequestStart) => {
|
||||
if let Err(e) = crate::portable_service::client::start_portable_service() {
|
||||
log::error!("Failed to start portable service from cm:{:?}", e);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
},
|
||||
@ -417,23 +424,36 @@ impl Connection {
|
||||
}
|
||||
},
|
||||
_ = second_timer.tick() => {
|
||||
let uac = crate::video_service::IS_UAC_RUNNING.lock().unwrap().clone();
|
||||
if last_uac != uac {
|
||||
last_uac = uac;
|
||||
let mut misc = Misc::new();
|
||||
misc.set_uac(uac);
|
||||
let mut msg = Message::new();
|
||||
msg.set_misc(misc);
|
||||
conn.inner.send(msg.into());
|
||||
}
|
||||
let foreground_window_elevated = crate::video_service::IS_FOREGROUND_WINDOW_ELEVATED.lock().unwrap().clone();
|
||||
if last_foreground_window_elevated != foreground_window_elevated {
|
||||
last_foreground_window_elevated = foreground_window_elevated;
|
||||
let mut misc = Misc::new();
|
||||
misc.set_foreground_window_elevated(foreground_window_elevated);
|
||||
let mut msg = Message::new();
|
||||
msg.set_misc(misc);
|
||||
conn.inner.send(msg.into());
|
||||
#[cfg(windows)]
|
||||
{
|
||||
if !is_installed {
|
||||
let portable_service_running = crate::portable_service::client::PORTABLE_SERVICE_RUNNING.lock().unwrap().clone();
|
||||
let uac = crate::video_service::IS_UAC_RUNNING.lock().unwrap().clone();
|
||||
if last_uac != uac {
|
||||
last_uac = uac;
|
||||
if !uac || !portable_service_running{
|
||||
let mut misc = Misc::new();
|
||||
misc.set_uac(uac);
|
||||
let mut msg = Message::new();
|
||||
msg.set_misc(misc);
|
||||
conn.inner.send(msg.into());
|
||||
}
|
||||
}
|
||||
let foreground_window_elevated = crate::video_service::IS_FOREGROUND_WINDOW_ELEVATED.lock().unwrap().clone();
|
||||
if last_foreground_window_elevated != foreground_window_elevated {
|
||||
last_foreground_window_elevated = foreground_window_elevated;
|
||||
if !foreground_window_elevated || !portable_service_running {
|
||||
let mut misc = Misc::new();
|
||||
misc.set_foreground_window_elevated(foreground_window_elevated);
|
||||
let mut msg = Message::new();
|
||||
msg.set_misc(misc);
|
||||
conn.inner.send(msg.into());
|
||||
}
|
||||
}
|
||||
let show_elevation = !portable_service_running;
|
||||
conn.send_to_cm(ipc::Data::DataPortableService(ipc::DataPortableService::CmShowElevation(show_elevation)));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
_ = test_delay_timer.tick() => {
|
||||
|
@ -280,14 +280,30 @@ fn get_modifier_state(key: Key, en: &mut Enigo) -> bool {
|
||||
}
|
||||
|
||||
pub fn handle_mouse(evt: &MouseEvent, conn: i32) {
|
||||
if !active_mouse_(conn) {
|
||||
return;
|
||||
}
|
||||
let evt_type = evt.mask & 0x7;
|
||||
if evt_type == 0 {
|
||||
let time = get_time();
|
||||
*LATEST_PEER_INPUT_CURSOR.lock().unwrap() = Input {
|
||||
time,
|
||||
conn,
|
||||
x: evt.x,
|
||||
y: evt.y,
|
||||
};
|
||||
}
|
||||
#[cfg(target_os = "macos")]
|
||||
if !*IS_SERVER {
|
||||
// having GUI, run main GUI thread, otherwise crash
|
||||
let evt = evt.clone();
|
||||
QUEUE.exec_async(move || handle_mouse_(&evt, conn));
|
||||
QUEUE.exec_async(move || handle_mouse_(&evt));
|
||||
return;
|
||||
}
|
||||
handle_mouse_(evt, conn);
|
||||
#[cfg(windows)]
|
||||
crate::portable_service::client::handle_mouse(evt);
|
||||
#[cfg(not(windows))]
|
||||
handle_mouse_(evt);
|
||||
}
|
||||
|
||||
pub fn fix_key_down_timeout_loop() {
|
||||
@ -415,8 +431,7 @@ fn active_mouse_(conn: i32) -> bool {
|
||||
let lock = LATEST_PEER_INPUT_CURSOR.lock().unwrap();
|
||||
(lock.x, lock.y)
|
||||
};
|
||||
let mut can_active =
|
||||
in_actived_dist(last_in_x, x) && in_actived_dist(last_in_y, y);
|
||||
let mut can_active = in_actived_dist(last_in_x, x) && in_actived_dist(last_in_y, y);
|
||||
// The cursor may not have been moved to last input position if system is busy now.
|
||||
// While this is not a common case, we check it again after some time later.
|
||||
if !can_active {
|
||||
@ -425,8 +440,7 @@ fn active_mouse_(conn: i32) -> bool {
|
||||
std::thread::sleep(std::time::Duration::from_micros(10));
|
||||
// Sleep here can also somehow suppress delay accumulation.
|
||||
if let Some((x2, y2)) = crate::get_cursor_pos() {
|
||||
can_active =
|
||||
in_actived_dist(last_in_x, x2) && in_actived_dist(last_in_y, y2);
|
||||
can_active = in_actived_dist(last_in_x, x2) && in_actived_dist(last_in_y, y2);
|
||||
}
|
||||
}
|
||||
if !can_active {
|
||||
@ -440,15 +454,11 @@ fn active_mouse_(conn: i32) -> bool {
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_mouse_(evt: &MouseEvent, conn: i32) {
|
||||
pub fn handle_mouse_(evt: &MouseEvent) {
|
||||
if EXITING.load(Ordering::SeqCst) {
|
||||
return;
|
||||
}
|
||||
|
||||
if !active_mouse_(conn) {
|
||||
return;
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
crate::platform::windows::try_change_desktop();
|
||||
let buttons = evt.mask >> 3;
|
||||
@ -477,14 +487,6 @@ fn handle_mouse_(evt: &MouseEvent, conn: i32) {
|
||||
}
|
||||
match evt_type {
|
||||
0 => {
|
||||
let time = get_time();
|
||||
*LATEST_PEER_INPUT_CURSOR.lock().unwrap() = Input {
|
||||
time,
|
||||
conn,
|
||||
x: evt.x,
|
||||
y: evt.y,
|
||||
};
|
||||
|
||||
en.mouse_move_to(evt.x, evt.y);
|
||||
}
|
||||
1 => match buttons {
|
||||
@ -698,6 +700,9 @@ pub fn handle_key(evt: &KeyEvent) {
|
||||
QUEUE.exec_async(move || handle_key_(&evt));
|
||||
return;
|
||||
}
|
||||
#[cfg(windows)]
|
||||
crate::portable_service::client::handle_key(evt);
|
||||
#[cfg(not(windows))]
|
||||
handle_key_(evt);
|
||||
}
|
||||
|
||||
@ -949,7 +954,7 @@ fn legacy_keyboard_mode(evt: &KeyEvent) {
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_key_(evt: &KeyEvent) {
|
||||
pub fn handle_key_(evt: &KeyEvent) {
|
||||
if EXITING.load(Ordering::SeqCst) {
|
||||
return;
|
||||
}
|
||||
|
787
src/server/portable_service.rs
Normal file
787
src/server/portable_service.rs
Normal file
@ -0,0 +1,787 @@
|
||||
use core::slice;
|
||||
use hbb_common::{
|
||||
allow_err,
|
||||
anyhow::anyhow,
|
||||
bail,
|
||||
config::Config,
|
||||
log,
|
||||
message_proto::{KeyEvent, MouseEvent},
|
||||
protobuf::Message,
|
||||
tokio::{self, sync::mpsc},
|
||||
ResultType,
|
||||
};
|
||||
use scrap::{Capturer, Frame, TraitCapturer};
|
||||
use shared_memory::*;
|
||||
use std::{
|
||||
mem::size_of,
|
||||
ops::{Deref, DerefMut},
|
||||
sync::{Arc, Mutex},
|
||||
time::Duration,
|
||||
};
|
||||
use winapi::{
|
||||
shared::minwindef::{BOOL, FALSE, TRUE},
|
||||
um::winuser::{self, CURSORINFO, PCURSORINFO},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
ipc::{self, new_listener, Connection, Data, DataPortableService},
|
||||
video_service::get_current_display,
|
||||
};
|
||||
|
||||
use super::video_qos;
|
||||
|
||||
const SIZE_COUNTER: usize = size_of::<i32>() * 2;
|
||||
const FRAME_ALIGN: usize = 64;
|
||||
|
||||
const ADDR_CURSOR_PARA: usize = 0;
|
||||
const ADDR_CURSOR_COUNTER: usize = ADDR_CURSOR_PARA + size_of::<CURSORINFO>();
|
||||
|
||||
const ADDR_CAPTURER_PARA: usize = ADDR_CURSOR_COUNTER + SIZE_COUNTER;
|
||||
const ADDR_CAPTURE_FRAME_SIZE: usize = ADDR_CAPTURER_PARA + size_of::<CapturerPara>();
|
||||
const ADDR_CAPTURE_WOULDBLOCK: usize = ADDR_CAPTURE_FRAME_SIZE + size_of::<i32>();
|
||||
const ADDR_CAPTURE_FRAME_COUNTER: usize = ADDR_CAPTURE_WOULDBLOCK + size_of::<i32>();
|
||||
|
||||
const ADDR_CAPTURE_FRAME: usize =
|
||||
(ADDR_CAPTURE_FRAME_COUNTER + SIZE_COUNTER + FRAME_ALIGN - 1) / FRAME_ALIGN * FRAME_ALIGN;
|
||||
|
||||
const IPC_PROFIX: &str = "_portable_service";
|
||||
pub const SHMEM_NAME: &str = "_portable_service";
|
||||
const MAX_NACK: usize = 3;
|
||||
const MAX_DXGI_FAIL_TIME: usize = 5;
|
||||
|
||||
pub struct SharedMemory {
|
||||
inner: Shmem,
|
||||
}
|
||||
|
||||
unsafe impl Send for SharedMemory {}
|
||||
unsafe impl Sync for SharedMemory {}
|
||||
|
||||
impl Deref for SharedMemory {
|
||||
type Target = Shmem;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.inner
|
||||
}
|
||||
}
|
||||
|
||||
impl DerefMut for SharedMemory {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
&mut self.inner
|
||||
}
|
||||
}
|
||||
|
||||
impl SharedMemory {
|
||||
pub fn create(name: &str, size: usize) -> ResultType<Self> {
|
||||
let flink = Self::flink(name.to_string());
|
||||
let shmem = match ShmemConf::new()
|
||||
.size(size)
|
||||
.flink(&flink)
|
||||
.force_create_flink()
|
||||
.create()
|
||||
{
|
||||
Ok(m) => m,
|
||||
Err(ShmemError::LinkExists) => {
|
||||
bail!(
|
||||
"Unable to force create shmem flink {}, which should not happen.",
|
||||
flink
|
||||
)
|
||||
}
|
||||
Err(e) => {
|
||||
bail!("Unable to create shmem flink {} : {}", flink, e);
|
||||
}
|
||||
};
|
||||
log::info!("Create shared memory, size:{}, flink:{}", size, flink);
|
||||
Self::set_all_perm(&flink);
|
||||
Ok(SharedMemory { inner: shmem })
|
||||
}
|
||||
|
||||
pub fn open_existing(name: &str) -> ResultType<Self> {
|
||||
let flink = Self::flink(name.to_string());
|
||||
let shmem = match ShmemConf::new().flink(&flink).allow_raw(true).open() {
|
||||
Ok(m) => m,
|
||||
Err(e) => {
|
||||
bail!("Unable to open existing shmem flink {} : {}", flink, e);
|
||||
}
|
||||
};
|
||||
log::info!("open existing shared memory, flink:{:?}", flink);
|
||||
Ok(SharedMemory { inner: shmem })
|
||||
}
|
||||
|
||||
pub fn write(&self, addr: usize, data: &[u8]) {
|
||||
unsafe {
|
||||
assert!(addr + data.len() <= self.inner.len());
|
||||
let ptr = self.inner.as_ptr().add(addr);
|
||||
let shared_mem_slice = slice::from_raw_parts_mut(ptr, data.len());
|
||||
shared_mem_slice.copy_from_slice(data);
|
||||
}
|
||||
}
|
||||
|
||||
fn flink(name: String) -> String {
|
||||
let mut shmem_flink = format!("shared_memory{}", name);
|
||||
if cfg!(windows) {
|
||||
let df = "C:\\ProgramData";
|
||||
let df = if std::path::Path::new(df).exists() {
|
||||
df.to_owned()
|
||||
} else {
|
||||
std::env::var("TEMP").unwrap_or("C:\\Windows\\TEMP".to_owned())
|
||||
};
|
||||
let df = format!("{}\\{}", df, *hbb_common::config::APP_NAME.read().unwrap());
|
||||
std::fs::create_dir(&df).ok();
|
||||
shmem_flink = format!("{}\\{}", df, shmem_flink);
|
||||
} else {
|
||||
shmem_flink = Config::ipc_path("").replace("ipc", "") + &shmem_flink;
|
||||
}
|
||||
return shmem_flink;
|
||||
}
|
||||
|
||||
fn set_all_perm(_p: &str) {
|
||||
#[cfg(not(windows))]
|
||||
{
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
std::fs::set_permissions(_p, std::fs::Permissions::from_mode(0o0777)).ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mod utils {
|
||||
use core::slice;
|
||||
use std::mem::size_of;
|
||||
|
||||
pub fn i32_to_vec(i: i32) -> Vec<u8> {
|
||||
i.to_ne_bytes().to_vec()
|
||||
}
|
||||
|
||||
pub fn ptr_to_i32(ptr: *const u8) -> i32 {
|
||||
unsafe {
|
||||
let v = slice::from_raw_parts(ptr, size_of::<i32>());
|
||||
i32::from_ne_bytes([v[0], v[1], v[2], v[3]])
|
||||
}
|
||||
}
|
||||
|
||||
pub fn counter_ready(counter: *const u8) -> bool {
|
||||
unsafe {
|
||||
let wptr = counter;
|
||||
let rptr = counter.add(size_of::<i32>());
|
||||
let iw = ptr_to_i32(wptr);
|
||||
let ir = ptr_to_i32(rptr);
|
||||
if ir != iw {
|
||||
std::ptr::copy_nonoverlapping(wptr, rptr as *mut _, size_of::<i32>());
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn counter_equal(counter: *const u8) -> bool {
|
||||
unsafe {
|
||||
let wptr = counter;
|
||||
let rptr = counter.add(size_of::<i32>());
|
||||
let iw = ptr_to_i32(wptr);
|
||||
let ir = ptr_to_i32(rptr);
|
||||
iw == ir
|
||||
}
|
||||
}
|
||||
|
||||
pub fn increase_counter(counter: *mut u8) {
|
||||
unsafe {
|
||||
let wptr = counter;
|
||||
let rptr = counter.add(size_of::<i32>());
|
||||
let iw = ptr_to_i32(counter);
|
||||
let ir = ptr_to_i32(counter);
|
||||
let v = i32_to_vec(iw + 1);
|
||||
std::ptr::copy_nonoverlapping(v.as_ptr(), wptr, size_of::<i32>());
|
||||
if ir == iw + 1 {
|
||||
let v = i32_to_vec(iw);
|
||||
std::ptr::copy_nonoverlapping(v.as_ptr(), rptr, size_of::<i32>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn align(v: usize, align: usize) -> usize {
|
||||
(v + align - 1) / align * align
|
||||
}
|
||||
}
|
||||
|
||||
// functions called in seperate SYSTEM user process.
|
||||
pub mod server {
|
||||
use super::*;
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
static ref EXIT: Arc<Mutex<bool>> = Default::default();
|
||||
}
|
||||
|
||||
pub fn run_portable_service() {
|
||||
let shmem = Arc::new(SharedMemory::open_existing(SHMEM_NAME).unwrap());
|
||||
let shmem1 = shmem.clone();
|
||||
let shmem2 = shmem.clone();
|
||||
let mut threads = vec![];
|
||||
threads.push(std::thread::spawn(|| {
|
||||
run_get_cursor_info(shmem1);
|
||||
}));
|
||||
threads.push(std::thread::spawn(|| {
|
||||
run_capture(shmem2);
|
||||
}));
|
||||
threads.push(std::thread::spawn(|| {
|
||||
run_ipc_client();
|
||||
}));
|
||||
threads.push(std::thread::spawn(|| {
|
||||
run_exit_check();
|
||||
}));
|
||||
for th in threads.drain(..) {
|
||||
th.join().unwrap();
|
||||
log::info!("thread joined");
|
||||
}
|
||||
}
|
||||
|
||||
fn run_exit_check() {
|
||||
loop {
|
||||
if EXIT.lock().unwrap().clone() {
|
||||
std::thread::sleep(Duration::from_secs(1));
|
||||
log::info!("exit from seperate check thread");
|
||||
std::process::exit(0);
|
||||
}
|
||||
std::thread::sleep(Duration::from_secs(1));
|
||||
}
|
||||
}
|
||||
|
||||
fn run_get_cursor_info(shmem: Arc<SharedMemory>) {
|
||||
loop {
|
||||
if EXIT.lock().unwrap().clone() {
|
||||
break;
|
||||
}
|
||||
unsafe {
|
||||
let para = shmem.as_ptr().add(ADDR_CURSOR_PARA) as *mut CURSORINFO;
|
||||
(*para).cbSize = size_of::<CURSORINFO>() as _;
|
||||
let result = winuser::GetCursorInfo(para);
|
||||
if result == TRUE {
|
||||
utils::increase_counter(shmem.as_ptr().add(ADDR_CURSOR_COUNTER));
|
||||
}
|
||||
}
|
||||
// more frequent in case of `Error of mouse_cursor service`
|
||||
std::thread::sleep(Duration::from_millis(15));
|
||||
}
|
||||
}
|
||||
|
||||
fn run_capture(shmem: Arc<SharedMemory>) {
|
||||
let mut c = None;
|
||||
let mut last_current_display = usize::MAX;
|
||||
let mut last_use_yuv = false;
|
||||
let mut last_timeout_ms: i32 = 33;
|
||||
let mut spf = Duration::from_millis(last_timeout_ms as _);
|
||||
let mut first_frame_captured = false;
|
||||
let mut dxgi_failed_times = 0;
|
||||
loop {
|
||||
if EXIT.lock().unwrap().clone() {
|
||||
break;
|
||||
}
|
||||
unsafe {
|
||||
let para_ptr = shmem.as_ptr().add(ADDR_CAPTURER_PARA);
|
||||
let para = para_ptr as *const CapturerPara;
|
||||
let current_display = (*para).current_display;
|
||||
let use_yuv = (*para).use_yuv;
|
||||
let use_yuv_set = (*para).use_yuv_set;
|
||||
let timeout_ms = (*para).timeout_ms;
|
||||
if !use_yuv_set {
|
||||
c = None;
|
||||
std::thread::sleep(spf);
|
||||
continue;
|
||||
}
|
||||
if c.is_none() {
|
||||
*crate::video_service::CURRENT_DISPLAY.lock().unwrap() = current_display;
|
||||
let (_, _current, display) = get_current_display().unwrap();
|
||||
match Capturer::new(display, use_yuv) {
|
||||
Ok(mut v) => {
|
||||
c = {
|
||||
last_current_display = current_display;
|
||||
last_use_yuv = use_yuv;
|
||||
first_frame_captured = false;
|
||||
if dxgi_failed_times > MAX_DXGI_FAIL_TIME {
|
||||
dxgi_failed_times = 0;
|
||||
v.set_gdi();
|
||||
}
|
||||
Some(v)
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
log::error!("Failed to create gdi capturer:{:?}", e);
|
||||
std::thread::sleep(std::time::Duration::from_secs(1));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if current_display != last_current_display || use_yuv != last_use_yuv {
|
||||
log::info!(
|
||||
"display:{}->{}, use_yuv:{}->{}",
|
||||
last_current_display,
|
||||
current_display,
|
||||
last_use_yuv,
|
||||
use_yuv
|
||||
);
|
||||
c = None;
|
||||
continue;
|
||||
}
|
||||
if timeout_ms != last_timeout_ms
|
||||
&& timeout_ms >= 1000 / video_qos::MAX_FPS as i32
|
||||
&& timeout_ms <= 1000 / video_qos::MIN_FPS as i32
|
||||
{
|
||||
last_timeout_ms = timeout_ms;
|
||||
spf = Duration::from_millis(timeout_ms as _);
|
||||
}
|
||||
}
|
||||
if first_frame_captured {
|
||||
if !utils::counter_equal(shmem.as_ptr().add(ADDR_CAPTURE_FRAME_COUNTER)) {
|
||||
std::thread::sleep(spf);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
match c.as_mut().unwrap().frame(spf) {
|
||||
Ok(f) => {
|
||||
let len = f.0.len();
|
||||
let len_slice = utils::i32_to_vec(len as _);
|
||||
shmem.write(ADDR_CAPTURE_FRAME_SIZE, &len_slice);
|
||||
shmem.write(ADDR_CAPTURE_FRAME, f.0);
|
||||
shmem.write(ADDR_CAPTURE_WOULDBLOCK, &utils::i32_to_vec(TRUE));
|
||||
utils::increase_counter(shmem.as_ptr().add(ADDR_CAPTURE_FRAME_COUNTER));
|
||||
first_frame_captured = true;
|
||||
dxgi_failed_times = 0;
|
||||
}
|
||||
Err(e) => {
|
||||
if e.kind() != std::io::ErrorKind::WouldBlock {
|
||||
// DXGI_ERROR_INVALID_CALL after each success on Microsoft GPU driver
|
||||
// log::error!("capture frame failed:{:?}", e);
|
||||
if crate::platform::windows::desktop_changed() {
|
||||
crate::platform::try_change_desktop();
|
||||
c = None;
|
||||
std::thread::sleep(spf);
|
||||
continue;
|
||||
}
|
||||
if !c.as_ref().unwrap().is_gdi() {
|
||||
dxgi_failed_times += 1;
|
||||
}
|
||||
if dxgi_failed_times > MAX_DXGI_FAIL_TIME {
|
||||
c = None;
|
||||
shmem.write(ADDR_CAPTURE_WOULDBLOCK, &utils::i32_to_vec(FALSE));
|
||||
std::thread::sleep(spf);
|
||||
}
|
||||
} else {
|
||||
shmem.write(ADDR_CAPTURE_WOULDBLOCK, &utils::i32_to_vec(TRUE));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
async fn run_ipc_client() {
|
||||
use DataPortableService::*;
|
||||
|
||||
let postfix = IPC_PROFIX;
|
||||
|
||||
match ipc::connect(1000, postfix).await {
|
||||
Ok(mut stream) => {
|
||||
let mut timer = tokio::time::interval(Duration::from_secs(1));
|
||||
let mut nack = 0;
|
||||
loop {
|
||||
tokio::select! {
|
||||
res = stream.next() => {
|
||||
match res {
|
||||
Err(err) => {
|
||||
log::error!(
|
||||
"ipc{} connection closed: {}",
|
||||
postfix,
|
||||
err
|
||||
);
|
||||
break;
|
||||
}
|
||||
Ok(Some(Data::DataPortableService(data))) => match data {
|
||||
Ping => {
|
||||
allow_err!(
|
||||
stream
|
||||
.send(&Data::DataPortableService(Pong))
|
||||
.await
|
||||
);
|
||||
}
|
||||
Pong => {
|
||||
nack = 0;
|
||||
}
|
||||
ConnCount(Some(n)) => {
|
||||
if n == 0 {
|
||||
log::info!("Connnection count equals 0, exit");
|
||||
stream.send(&Data::DataPortableService(WillClose)).await.ok();
|
||||
break;
|
||||
}
|
||||
}
|
||||
Mouse(v) => {
|
||||
if let Ok(evt) = MouseEvent::parse_from_bytes(&v) {
|
||||
crate::input_service::handle_mouse_(&evt);
|
||||
}
|
||||
}
|
||||
Key(v) => {
|
||||
if let Ok(evt) = KeyEvent::parse_from_bytes(&v) {
|
||||
crate::input_service::handle_key_(&evt);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
_ = timer.tick() => {
|
||||
nack+=1;
|
||||
if nack > MAX_NACK {
|
||||
log::info!("max ping nack, exit");
|
||||
break;
|
||||
}
|
||||
stream.send(&Data::DataPortableService(Ping)).await.ok();
|
||||
stream.send(&Data::DataPortableService(ConnCount(None))).await.ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
log::error!("Failed to connect portable service ipc:{:?}", e);
|
||||
}
|
||||
}
|
||||
|
||||
*EXIT.lock().unwrap() = true;
|
||||
}
|
||||
}
|
||||
|
||||
// functions called in main process.
|
||||
pub mod client {
|
||||
use hbb_common::anyhow::Context;
|
||||
|
||||
use super::*;
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
pub static ref PORTABLE_SERVICE_RUNNING: Arc<Mutex<bool>> = Default::default();
|
||||
static ref SHMEM: Arc<Mutex<Option<SharedMemory>>> = Default::default();
|
||||
static ref SENDER : Mutex<mpsc::UnboundedSender<ipc::Data>> = Mutex::new(client::start_ipc_server());
|
||||
}
|
||||
|
||||
pub(crate) fn start_portable_service() -> ResultType<()> {
|
||||
if PORTABLE_SERVICE_RUNNING.lock().unwrap().clone() {
|
||||
bail!("already running");
|
||||
}
|
||||
if SHMEM.lock().unwrap().is_none() {
|
||||
let displays = scrap::Display::all()?;
|
||||
if displays.is_empty() {
|
||||
bail!("no display available!");
|
||||
}
|
||||
let mut max_pixel = 0;
|
||||
let align = 64;
|
||||
for d in displays {
|
||||
let pixel = utils::align(d.width(), align) * utils::align(d.height(), align);
|
||||
if max_pixel < pixel {
|
||||
max_pixel = pixel;
|
||||
}
|
||||
}
|
||||
let shmem_size = utils::align(ADDR_CAPTURE_FRAME + max_pixel * 4, align);
|
||||
// os error 112, no enough space
|
||||
*SHMEM.lock().unwrap() = Some(crate::portable_service::SharedMemory::create(
|
||||
crate::portable_service::SHMEM_NAME,
|
||||
shmem_size,
|
||||
)?);
|
||||
shutdown_hooks::add_shutdown_hook(drop_shmem);
|
||||
}
|
||||
let mut option = SHMEM.lock().unwrap();
|
||||
let shmem = option.as_mut().unwrap();
|
||||
unsafe {
|
||||
libc::memset(shmem.as_ptr() as _, 0, shmem.len() as _);
|
||||
}
|
||||
if crate::platform::run_background(
|
||||
&std::env::current_exe()?.to_string_lossy().to_string(),
|
||||
"--portable-service",
|
||||
)
|
||||
.is_err()
|
||||
{
|
||||
*SHMEM.lock().unwrap() = None;
|
||||
bail!("Failed to run portable service process");
|
||||
}
|
||||
let _sender = SENDER.lock().unwrap();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
extern "C" fn drop_shmem() {
|
||||
log::info!("drop shared memory");
|
||||
*SHMEM.lock().unwrap() = None;
|
||||
}
|
||||
|
||||
pub struct CapturerPortable;
|
||||
|
||||
impl CapturerPortable {
|
||||
pub fn new(current_display: usize, use_yuv: bool) -> Self
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
let mut option = SHMEM.lock().unwrap();
|
||||
let shmem = option.as_mut().unwrap();
|
||||
Self::set_para(
|
||||
shmem,
|
||||
CapturerPara {
|
||||
current_display,
|
||||
use_yuv,
|
||||
use_yuv_set: false,
|
||||
timeout_ms: 33,
|
||||
},
|
||||
);
|
||||
shmem.write(ADDR_CAPTURE_WOULDBLOCK, &utils::i32_to_vec(TRUE));
|
||||
CapturerPortable {}
|
||||
}
|
||||
|
||||
fn set_para(shmem: &mut SharedMemory, para: CapturerPara) {
|
||||
let para_ptr = ¶ as *const CapturerPara as *const u8;
|
||||
let para_data;
|
||||
unsafe {
|
||||
para_data = slice::from_raw_parts(para_ptr, size_of::<CapturerPara>());
|
||||
}
|
||||
shmem.write(ADDR_CAPTURER_PARA, para_data);
|
||||
}
|
||||
}
|
||||
|
||||
impl TraitCapturer for CapturerPortable {
|
||||
fn set_use_yuv(&mut self, use_yuv: bool) {
|
||||
let mut option = SHMEM.lock().unwrap();
|
||||
let shmem = option.as_mut().unwrap();
|
||||
unsafe {
|
||||
let para_ptr = shmem.as_ptr().add(ADDR_CAPTURER_PARA);
|
||||
let para = para_ptr as *const CapturerPara;
|
||||
Self::set_para(
|
||||
shmem,
|
||||
CapturerPara {
|
||||
current_display: (*para).current_display,
|
||||
use_yuv,
|
||||
use_yuv_set: true,
|
||||
timeout_ms: (*para).timeout_ms,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn frame<'a>(&'a mut self, timeout: Duration) -> std::io::Result<Frame<'a>> {
|
||||
let mut option = SHMEM.lock().unwrap();
|
||||
let shmem = option.as_mut().unwrap();
|
||||
unsafe {
|
||||
let base = shmem.as_ptr();
|
||||
let para_ptr = base.add(ADDR_CAPTURER_PARA);
|
||||
let para = para_ptr as *const CapturerPara;
|
||||
if timeout.as_millis() != (*para).timeout_ms as _ {
|
||||
Self::set_para(
|
||||
shmem,
|
||||
CapturerPara {
|
||||
current_display: (*para).current_display,
|
||||
use_yuv: (*para).use_yuv,
|
||||
use_yuv_set: (*para).use_yuv_set,
|
||||
timeout_ms: timeout.as_millis() as _,
|
||||
},
|
||||
);
|
||||
}
|
||||
if utils::counter_ready(base.add(ADDR_CAPTURE_FRAME_COUNTER)) {
|
||||
let frame_len_ptr = base.add(ADDR_CAPTURE_FRAME_SIZE);
|
||||
let frame_len = utils::ptr_to_i32(frame_len_ptr);
|
||||
let frame_ptr = base.add(ADDR_CAPTURE_FRAME);
|
||||
let data = slice::from_raw_parts(frame_ptr, frame_len as usize);
|
||||
Ok(Frame(data))
|
||||
} else {
|
||||
let ptr = base.add(ADDR_CAPTURE_WOULDBLOCK);
|
||||
let wouldblock = utils::ptr_to_i32(ptr);
|
||||
if wouldblock == TRUE {
|
||||
Err(std::io::Error::new(
|
||||
std::io::ErrorKind::WouldBlock,
|
||||
"wouldblock error".to_string(),
|
||||
))
|
||||
} else {
|
||||
Err(std::io::Error::new(
|
||||
std::io::ErrorKind::Other,
|
||||
"other error".to_string(),
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// control by itself
|
||||
fn is_gdi(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn set_gdi(&mut self) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn start_ipc_server() -> mpsc::UnboundedSender<Data> {
|
||||
let (tx, rx) = mpsc::unbounded_channel::<Data>();
|
||||
std::thread::spawn(move || start_ipc_server_async(rx));
|
||||
tx
|
||||
}
|
||||
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
async fn start_ipc_server_async(rx: mpsc::UnboundedReceiver<Data>) {
|
||||
use DataPortableService::*;
|
||||
let rx = Arc::new(tokio::sync::Mutex::new(rx));
|
||||
let postfix = IPC_PROFIX;
|
||||
|
||||
match new_listener(postfix).await {
|
||||
Ok(mut incoming) => loop {
|
||||
{
|
||||
tokio::select! {
|
||||
Some(result) = incoming.next() => {
|
||||
match result {
|
||||
Ok(stream) => {
|
||||
log::info!("Got portable service ipc connection");
|
||||
let rx_clone = rx.clone();
|
||||
tokio::spawn(async move {
|
||||
let mut stream = Connection::new(stream);
|
||||
let postfix = postfix.to_owned();
|
||||
let mut timer = tokio::time::interval(Duration::from_secs(1));
|
||||
let mut nack = 0;
|
||||
let mut rx = rx_clone.lock().await;
|
||||
loop {
|
||||
tokio::select! {
|
||||
res = stream.next() => {
|
||||
match res {
|
||||
Err(err) => {
|
||||
log::info!(
|
||||
"ipc{} connection closed: {}",
|
||||
postfix,
|
||||
err
|
||||
);
|
||||
break;
|
||||
}
|
||||
Ok(Some(Data::DataPortableService(data))) => match data {
|
||||
Ping => {
|
||||
stream.send(&Data::DataPortableService(Pong)).await.ok();
|
||||
}
|
||||
Pong => {
|
||||
nack = 0;
|
||||
*PORTABLE_SERVICE_RUNNING.lock().unwrap() = true;
|
||||
},
|
||||
ConnCount(None) => {
|
||||
let cnt = crate::server::CONN_COUNT.lock().unwrap().clone();
|
||||
stream.send(&Data::DataPortableService(ConnCount(Some(cnt)))).await.ok();
|
||||
},
|
||||
WillClose => {
|
||||
log::info!("portable service will close");
|
||||
break;
|
||||
}
|
||||
_=>{}
|
||||
}
|
||||
_=>{}
|
||||
}
|
||||
}
|
||||
_ = timer.tick() => {
|
||||
nack+=1;
|
||||
if nack > MAX_NACK {
|
||||
// In fact, this will not happen, ipc will be closed before max nack.
|
||||
log::error!("max ipc nack");
|
||||
break;
|
||||
}
|
||||
stream.send(&Data::DataPortableService(Ping)).await.ok();
|
||||
}
|
||||
Some(data) = rx.recv() => {
|
||||
allow_err!(stream.send(&data).await);
|
||||
}
|
||||
}
|
||||
}
|
||||
*PORTABLE_SERVICE_RUNNING.lock().unwrap() = false;
|
||||
});
|
||||
}
|
||||
Err(err) => {
|
||||
log::error!("Couldn't get portable client: {:?}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
Err(err) => {
|
||||
log::error!("Failed to start portable service ipc server: {}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn ipc_send(data: Data) -> ResultType<()> {
|
||||
let sender = SENDER.lock().unwrap();
|
||||
sender
|
||||
.send(data)
|
||||
.map_err(|e| anyhow!("ipc send error:{:?}", e))
|
||||
}
|
||||
|
||||
fn get_cursor_info_(shmem: &mut SharedMemory, pci: PCURSORINFO) -> BOOL {
|
||||
unsafe {
|
||||
let shmem_addr_para = shmem.as_ptr().add(ADDR_CURSOR_PARA);
|
||||
if utils::counter_ready(shmem.as_ptr().add(ADDR_CURSOR_COUNTER)) {
|
||||
std::ptr::copy_nonoverlapping(shmem_addr_para, pci as _, size_of::<CURSORINFO>());
|
||||
return TRUE;
|
||||
}
|
||||
FALSE
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_mouse_(evt: &MouseEvent) -> ResultType<()> {
|
||||
let mut v = vec![];
|
||||
evt.write_to_vec(&mut v)?;
|
||||
ipc_send(Data::DataPortableService(DataPortableService::Mouse(v)))
|
||||
}
|
||||
|
||||
fn handle_key_(evt: &KeyEvent) -> ResultType<()> {
|
||||
let mut v = vec![];
|
||||
evt.write_to_vec(&mut v)?;
|
||||
ipc_send(Data::DataPortableService(DataPortableService::Key(v)))
|
||||
}
|
||||
|
||||
pub fn create_capturer(
|
||||
current_display: usize,
|
||||
display: scrap::Display,
|
||||
use_yuv: bool,
|
||||
portable_service_running: bool,
|
||||
) -> ResultType<Box<dyn TraitCapturer>> {
|
||||
if portable_service_running != PORTABLE_SERVICE_RUNNING.lock().unwrap().clone() {
|
||||
log::info!("portable service status mismatch");
|
||||
}
|
||||
if portable_service_running {
|
||||
log::info!("Create shared memeory capturer");
|
||||
return Ok(Box::new(CapturerPortable::new(current_display, use_yuv)));
|
||||
} else {
|
||||
log::debug!("Create capturer dxgi|gdi");
|
||||
return Ok(Box::new(
|
||||
Capturer::new(display, use_yuv).with_context(|| "Failed to create capturer")?,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_cursor_info(pci: PCURSORINFO) -> BOOL {
|
||||
if PORTABLE_SERVICE_RUNNING.lock().unwrap().clone() {
|
||||
get_cursor_info_(&mut SHMEM.lock().unwrap().as_mut().unwrap(), pci)
|
||||
} else {
|
||||
unsafe { winuser::GetCursorInfo(pci) }
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle_mouse(evt: &MouseEvent) {
|
||||
if PORTABLE_SERVICE_RUNNING.lock().unwrap().clone() {
|
||||
handle_mouse_(evt).ok();
|
||||
} else {
|
||||
crate::input_service::handle_mouse_(evt);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle_key(evt: &KeyEvent) {
|
||||
if PORTABLE_SERVICE_RUNNING.lock().unwrap().clone() {
|
||||
handle_key_(evt).ok();
|
||||
} else {
|
||||
crate::input_service::handle_key_(evt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
struct CapturerPara {
|
||||
current_display: usize,
|
||||
use_yuv: bool,
|
||||
use_yuv_set: bool,
|
||||
timeout_ms: i32,
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
use super::*;
|
||||
use std::time::Duration;
|
||||
const FPS: u8 = 30;
|
||||
const MIN_FPS: u8 = 10;
|
||||
const MAX_FPS: u8 = 120;
|
||||
pub const FPS: u8 = 30;
|
||||
pub const MIN_FPS: u8 = 10;
|
||||
pub const MAX_FPS: u8 = 120;
|
||||
trait Percent {
|
||||
fn as_percent(&self) -> u32;
|
||||
}
|
||||
|
@ -19,6 +19,8 @@
|
||||
// https://slhck.info/video/2017/03/01/rate-control.html
|
||||
|
||||
use super::{video_qos::VideoQoS, *};
|
||||
#[cfg(windows)]
|
||||
use crate::portable_service::client::PORTABLE_SERVICE_RUNNING;
|
||||
use hbb_common::tokio::sync::{
|
||||
mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender},
|
||||
Mutex as TokioMutex,
|
||||
@ -49,7 +51,7 @@ pub const SCRAP_X11_REF_URL: &str = "https://rustdesk.com/docs/en/manual/linux/#
|
||||
pub const NAME: &'static str = "video";
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
static ref CURRENT_DISPLAY: Arc<Mutex<usize>> = Arc::new(Mutex::new(usize::MAX));
|
||||
pub static ref CURRENT_DISPLAY: Arc<Mutex<usize>> = Arc::new(Mutex::new(usize::MAX));
|
||||
static ref LAST_ACTIVE: Arc<Mutex<Instant>> = Arc::new(Mutex::new(Instant::now()));
|
||||
static ref SWITCH: Arc<Mutex<bool>> = Default::default();
|
||||
static ref FRAME_FETCHED_NOTIFIER: (UnboundedSender<(i32, Option<Instant>)>, Arc<TokioMutex<UnboundedReceiver<(i32, Option<Instant>)>>>) = {
|
||||
@ -188,6 +190,8 @@ fn create_capturer(
|
||||
privacy_mode_id: i32,
|
||||
display: Display,
|
||||
use_yuv: bool,
|
||||
current: usize,
|
||||
_portable_service_running: bool,
|
||||
) -> ResultType<Box<dyn TraitCapturer>> {
|
||||
#[cfg(not(windows))]
|
||||
let c: Option<Box<dyn TraitCapturer>> = None;
|
||||
@ -244,17 +248,23 @@ fn create_capturer(
|
||||
}
|
||||
}
|
||||
|
||||
let c = match c {
|
||||
Some(c1) => c1,
|
||||
match c {
|
||||
Some(c1) => return Ok(c1),
|
||||
None => {
|
||||
let c1 =
|
||||
Capturer::new(display, use_yuv).with_context(|| "Failed to create capturer")?;
|
||||
log::debug!("Create capturer dxgi|gdi");
|
||||
Box::new(c1)
|
||||
#[cfg(windows)]
|
||||
return crate::portable_service::client::create_capturer(
|
||||
current,
|
||||
display,
|
||||
use_yuv,
|
||||
_portable_service_running,
|
||||
);
|
||||
#[cfg(not(windows))]
|
||||
return Ok(Box::new(
|
||||
Capturer::new(display, use_yuv).with_context(|| "Failed to create capturer")?,
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
Ok(c)
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
@ -277,8 +287,8 @@ fn ensure_close_virtual_device() -> ResultType<()> {
|
||||
pub fn test_create_capturer(privacy_mode_id: i32, timeout_millis: u64) -> bool {
|
||||
let test_begin = Instant::now();
|
||||
while test_begin.elapsed().as_millis() < timeout_millis as _ {
|
||||
if let Ok((_, _, display)) = get_current_display() {
|
||||
if let Ok(_) = create_capturer(privacy_mode_id, display, true) {
|
||||
if let Ok((_, current, display)) = get_current_display() {
|
||||
if let Ok(_) = create_capturer(privacy_mode_id, display, true, current, false) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -327,7 +337,7 @@ impl DerefMut for CapturerInfo {
|
||||
}
|
||||
}
|
||||
|
||||
fn get_capturer(use_yuv: bool) -> ResultType<CapturerInfo> {
|
||||
fn get_capturer(use_yuv: bool, portable_service_running: bool) -> ResultType<CapturerInfo> {
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
if !scrap::is_x11() {
|
||||
@ -369,7 +379,13 @@ fn get_capturer(use_yuv: bool) -> ResultType<CapturerInfo> {
|
||||
} else {
|
||||
log::info!("In privacy mode, the peer side cannot watch the screen");
|
||||
}
|
||||
let capturer = create_capturer(captuerer_privacy_mode_id, display, use_yuv)?;
|
||||
let capturer = create_capturer(
|
||||
captuerer_privacy_mode_id,
|
||||
display,
|
||||
use_yuv,
|
||||
current,
|
||||
portable_service_running,
|
||||
)?;
|
||||
Ok(CapturerInfo {
|
||||
origin,
|
||||
width,
|
||||
@ -389,8 +405,12 @@ fn run(sp: GenericService) -> ResultType<()> {
|
||||
// ensure_inited() is needed because release_resouce() may be called.
|
||||
#[cfg(target_os = "linux")]
|
||||
super::wayland::ensure_inited()?;
|
||||
#[cfg(windows)]
|
||||
let last_portable_service_running = PORTABLE_SERVICE_RUNNING.lock().unwrap().clone();
|
||||
#[cfg(not(windows))]
|
||||
let last_portable_service_running = false;
|
||||
|
||||
let mut c = get_capturer(true)?;
|
||||
let mut c = get_capturer(true, last_portable_service_running)?;
|
||||
|
||||
let mut video_qos = VIDEO_QOS.lock().unwrap();
|
||||
video_qos.set_size(c.width as _, c.height as _);
|
||||
@ -498,10 +518,16 @@ fn run(sp: GenericService) -> ResultType<()> {
|
||||
if codec_name != Encoder::current_hw_encoder_name() {
|
||||
bail!("SWITCH");
|
||||
}
|
||||
#[cfg(windows)]
|
||||
if last_portable_service_running != PORTABLE_SERVICE_RUNNING.lock().unwrap().clone() {
|
||||
bail!("SWITCH");
|
||||
}
|
||||
check_privacy_mode_changed(&sp, c.privacy_mode_id)?;
|
||||
#[cfg(windows)]
|
||||
{
|
||||
if crate::platform::windows::desktop_changed() {
|
||||
if crate::platform::windows::desktop_changed()
|
||||
&& !PORTABLE_SERVICE_RUNNING.lock().unwrap().clone()
|
||||
{
|
||||
bail!("Desktop changed");
|
||||
}
|
||||
}
|
||||
@ -874,7 +900,7 @@ pub(super) fn get_current_display_2(mut all: Vec<Display>) -> ResultType<(usize,
|
||||
return Ok((n, current, all.remove(current)));
|
||||
}
|
||||
|
||||
fn get_current_display() -> ResultType<(usize, usize, Display)> {
|
||||
pub fn get_current_display() -> ResultType<(usize, usize, Display)> {
|
||||
get_current_display_2(try_get_displays()?)
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ div.permissions {
|
||||
}
|
||||
|
||||
div.permissions > div {
|
||||
size: 48px;
|
||||
size: 42px;
|
||||
background: color(accent);
|
||||
}
|
||||
|
||||
@ -112,20 +112,44 @@ icon.recording {
|
||||
background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAANpJREFUWEftltENAiEMhtsJ1NcynG6gI+gGugEOR591gppeQoIYSDBILxEeydH/57u2FMF4obE+TAOTwLoIhBDOAHBExG2n6rgR0akW640AM0sn4SWMiDycc7s8JjN7Ijro/k8NqAAR5RoeAPZxv2ggP9hCJiWZxtGbq3hqbJiBVHy4gVx8qAER8Yi4JFy6huVAKXemgb8icI+1b5KEitq0DOO/Nm1EEX1TK27p/bVvv36MOhl4EtHHbFF7jq8AoG1z08OAiFycczrkFNe6RrIet26NMQlMAuYEXiayryF/QQktAAAAAElFTkSuQmCC');
|
||||
}
|
||||
|
||||
div.buttons {
|
||||
width: *;
|
||||
border-spacing: 0.5em;
|
||||
text-align: center;
|
||||
div.outer_buttons {
|
||||
flow:vertical;
|
||||
border-spacing:8;
|
||||
}
|
||||
|
||||
div.buttons button {
|
||||
width: 80px;
|
||||
height: 40px;
|
||||
margin: 0.5em;
|
||||
div.inner_buttons {
|
||||
flow:horizontal;
|
||||
border-spacing:8;
|
||||
}
|
||||
|
||||
button.control {
|
||||
width: *;
|
||||
}
|
||||
|
||||
button.elevate {
|
||||
background:green;
|
||||
}
|
||||
|
||||
button.elevate:active {
|
||||
background: rgb(2, 104, 2);
|
||||
border-color: color(hover-border);
|
||||
}
|
||||
|
||||
button.elevate>span {
|
||||
flow:horizontal;
|
||||
width: *;
|
||||
}
|
||||
|
||||
button.elevate>span>span {
|
||||
margin-left:*;
|
||||
margin-right:*;
|
||||
}
|
||||
|
||||
button.elevate>span>span>span {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
button#disconnect {
|
||||
width: 160px;
|
||||
background: color(blood-red);
|
||||
border: none;
|
||||
}
|
||||
|
14
src/ui/cm.rs
14
src/ui/cm.rs
@ -51,6 +51,10 @@ impl InvokeUiCM for SciterHandler {
|
||||
fn change_language(&self) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
fn show_elevation(&self, show: bool) {
|
||||
self.call("showElevation", &make_args!(show));
|
||||
}
|
||||
}
|
||||
|
||||
impl SciterHandler {
|
||||
@ -123,6 +127,14 @@ impl SciterConnectionManager {
|
||||
fn t(&self, name: String) -> String {
|
||||
crate::client::translate(name)
|
||||
}
|
||||
|
||||
fn can_elevate(&self) -> bool {
|
||||
crate::ui_cm_interface::can_elevate()
|
||||
}
|
||||
|
||||
fn elevate_portable(&self, id: i32) {
|
||||
crate::ui_cm_interface::elevate_portable(id);
|
||||
}
|
||||
}
|
||||
|
||||
impl sciter::EventHandler for SciterConnectionManager {
|
||||
@ -141,5 +153,7 @@ impl sciter::EventHandler for SciterConnectionManager {
|
||||
fn authorize(i32);
|
||||
fn switch_permission(i32, String, bool);
|
||||
fn send_msg(i32, String);
|
||||
fn can_elevate();
|
||||
fn elevate_portable(i32);
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ view.windowFrame = is_osx ? #extended : #solid;
|
||||
var body;
|
||||
var connections = [];
|
||||
var show_chat = false;
|
||||
var show_elevation = true;
|
||||
var svg_elevate = <svg t="1667992597853" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1850" width="16" height="16" xmlns:xlink="http://www.w3.org/1999/xlink"><path d="M892.761 160.724v426.504c0 25.588-6.419 51.036-19.177 76.339-12.798 25.336-29.547 49.86-50.254 73.627-20.707 23.79-44.372 46.296-70.97 67.516-26.589 21.244-53.543 40.177-80.921 56.768-27.363 16.623-53.968 30.461-79.801 41.438-25.809 11.008-48.433 18.547-67.871 22.64l-9.203 1.53-8.43-1.53c-19.958-4.093-43.094-11.632-69.432-22.64-26.337-10.969-53.708-24.816-82.080-41.438-28.388-16.591-56.256-35.524-83.618-56.768-27.378-21.219-51.776-43.725-73.265-67.516-21.488-23.759-38.868-48.291-52.155-73.627-13.319-25.305-19.974-50.759-19.974-76.339v-426.504l31.455-4.629 352.892-65.97 359.784 65.97 23.017 4.629zM510.028 151.884l-4.211-0.844-302.89 51.476v269.101h307.102v-319.734zM815.434 471.634h-305.406v383.031c19.682-4.51 41.052-11.411 64.141-20.692 23.033-9.249 45.815-20.234 68.304-32.867 22.513-12.672 44.159-26.739 64.969-42.203 20.818-15.472 39.23-32.047 55.277-49.797 16.024-17.703 28.822-36.131 38.386-55.222 9.549-19.131 14.328-38.553 14.328-58.235v-124.015z" p-id="1851" fill="#ffffff"></path></svg>;
|
||||
|
||||
class Body: Reactor.Component
|
||||
{
|
||||
@ -27,6 +29,7 @@ class Body: Reactor.Component
|
||||
};
|
||||
var right_style = show_chat ? "" : "display: none";
|
||||
var disconnected = c.disconnected;
|
||||
var show_elevation_btn = handler.can_elevate() && show_elevation;
|
||||
// below size:* is work around for Linux, it alreayd set in css, but not work, shit sciter
|
||||
return <div .content style="size:*">
|
||||
<div .left-panel>
|
||||
@ -54,12 +57,17 @@ class Body: Reactor.Component
|
||||
}
|
||||
{c.port_forward ? <div>Port Forwarding: {c.port_forward}</div> : ""}
|
||||
<div style="size:*"/>
|
||||
<div .buttons>
|
||||
{auth ? "" : <button .button tabindex="-1" #accept>{translate('Accept')}</button>}
|
||||
{auth ? "" : <button .button tabindex="-1" .outline #dismiss>{translate('Dismiss')}</button>}
|
||||
{auth && !disconnected ? <button .button tabindex="-1" #disconnect>{translate('Disconnect')}</button> : ""}
|
||||
{auth && disconnected ? <button .button tabindex="-1" #close>{translate('Close')}</button> : ""}
|
||||
<div .outer_buttons>
|
||||
{!auth && !disconnected && show_elevation_btn ? <button #elevate_accept .control .elevate .button><span><span><span>{svg_elevate}</span><span>{translate('Accept')}</span></span></span></button> : "" }
|
||||
{auth && !disconnected && show_elevation_btn ? <button #elevate .control .elevate .button><span><span><span>{svg_elevate}</span><span>{translate('Elevate')}</span></span></span></button> : "" }
|
||||
<div .inner_buttons style={auth ? "display:none;":""}>
|
||||
{!auth ? <button #accept .control .button>{translate('Accept')}</button> : "" }
|
||||
{!auth ? <button #dismiss .control .outline>{translate('Dismiss')}</button> : "" }
|
||||
</div>
|
||||
{auth && !disconnected ? <button #disconnect .control .button>{translate('Disconnect')}</button> : "" }
|
||||
{auth && disconnected ? <button #close .control .button>{translate('Close')}</button> : "" }
|
||||
</div>
|
||||
<div style={!show_elevation_btn ? "height:1 em;" : "display:none;"}></div>
|
||||
{c.is_file_transfer || c.port_forward ? "" : <div .chaticon>{svg_chat}</div>}
|
||||
</div>
|
||||
<div .right-panel style={right_style}>
|
||||
@ -144,6 +152,32 @@ class Body: Reactor.Component
|
||||
});
|
||||
}
|
||||
|
||||
event click $(button#elevate_accept) {
|
||||
var { cid, connection } = this;
|
||||
checkClickTime(function() {
|
||||
connection.authorized = true;
|
||||
show_elevation = false;
|
||||
body.update();
|
||||
handler.elevate_portable(cid);
|
||||
handler.authorize(cid);
|
||||
self.timer(30ms, function() {
|
||||
view.windowState = View.WINDOW_MINIMIZED;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
event click $(button#elevate) {
|
||||
var { cid, connection } = this;
|
||||
checkClickTime(function() {
|
||||
show_elevation = false;
|
||||
body.update();
|
||||
handler.elevate_portable(cid);
|
||||
self.timer(30ms, function() {
|
||||
view.windowState = View.WINDOW_MINIMIZED;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
event click $(button#dismiss) {
|
||||
var cid = this.cid;
|
||||
checkClickTime(function() {
|
||||
@ -386,6 +420,13 @@ handler.newMessage = function(id, text) {
|
||||
update();
|
||||
}
|
||||
|
||||
handler.showElevation = function(show) {
|
||||
if (show != show_elevation) {
|
||||
show_elevation = show;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
view << event statechange {
|
||||
adjustBorder();
|
||||
}
|
||||
|
@ -232,6 +232,7 @@ class ChatBox: Reactor.Component {
|
||||
|
||||
/******************** start of msgbox ****************************************/
|
||||
var remember_password = false;
|
||||
var last_msgbox_tag = "";
|
||||
function msgbox(type, title, content, link="", callback=null, height=180, width=500, hasRetry=false, contentStyle="") {
|
||||
$(body).scrollTo(0, 0);
|
||||
if (!type) {
|
||||
@ -264,6 +265,7 @@ function msgbox(type, title, content, link="", callback=null, height=180, width=
|
||||
} else if (type.indexOf("custom") < 0 && !is_port_forward && !callback) {
|
||||
callback = function() { view.close(); }
|
||||
}
|
||||
last_msgbox_tag = type + "-" + title + "-" + content + "-" + link;
|
||||
$(#msgbox).content(<MsgboxComponent width={width} height={height} auto_login={auto_login} type={type} title={title} content={content} link={link} remember={remember} callback={callback} contentStyle={contentStyle} hasRetry={hasRetry} />);
|
||||
}
|
||||
|
||||
@ -276,6 +278,12 @@ handler.msgbox = function(type, title, text, link = "", hasRetry=false) {
|
||||
self.timer(60ms, function() { msgbox(type, title, text, link, null, 180, 500, hasRetry); });
|
||||
}
|
||||
|
||||
handler.cancel_msgbox = function(tag) {
|
||||
if (last_msgbox_tag == tag) {
|
||||
closeMsgbox();
|
||||
}
|
||||
}
|
||||
|
||||
var reconnectTimeout = 1000;
|
||||
handler.msgbox_retry = function(type, title, text, link, hasRetry) {
|
||||
handler.msgbox(type, title, text, link, hasRetry);
|
||||
|
@ -231,7 +231,14 @@ impl InvokeUiSession for SciterHandler {
|
||||
}
|
||||
|
||||
fn msgbox(&self, msgtype: &str, title: &str, text: &str, link: &str, retry: bool) {
|
||||
self.call2("msgbox_retry", &make_args!(msgtype, title, text, link, retry));
|
||||
self.call2(
|
||||
"msgbox_retry",
|
||||
&make_args!(msgtype, title, text, link, retry),
|
||||
);
|
||||
}
|
||||
|
||||
fn cancel_msgbox(&self, tag: &str) {
|
||||
self.call("cancel_msgbox", &make_args!(tag));
|
||||
}
|
||||
|
||||
fn new_message(&self, msg: String) {
|
||||
|
@ -85,6 +85,8 @@ pub trait InvokeUiCM: Send + Clone + 'static + Sized {
|
||||
fn change_theme(&self, dark: String);
|
||||
|
||||
fn change_language(&self);
|
||||
|
||||
fn show_elevation(&self, show: bool);
|
||||
}
|
||||
|
||||
impl<T: InvokeUiCM> Deref for ConnectionManager<T> {
|
||||
@ -171,6 +173,10 @@ impl<T: InvokeUiCM> ConnectionManager<T> {
|
||||
|
||||
self.ui_handler.remove_connection(id, close);
|
||||
}
|
||||
|
||||
fn show_elevation(&self, show: bool) {
|
||||
self.ui_handler.show_elevation(show);
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -362,6 +368,9 @@ impl<T: InvokeUiCM> IpcTaskRunner<T> {
|
||||
LocalConfig::set_option("lang".to_owned(), lang);
|
||||
self.cm.change_language();
|
||||
}
|
||||
Data::DataPortableService(ipc::DataPortableService::CmShowElevation(show)) => {
|
||||
self.cm.show_elevation(show);
|
||||
}
|
||||
_ => {
|
||||
|
||||
}
|
||||
@ -757,3 +766,28 @@ fn cm_inner_send(id: i32, data: Data) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn can_elevate() -> bool {
|
||||
#[cfg(windows)]
|
||||
{
|
||||
return !crate::platform::is_installed()
|
||||
&& !crate::portable_service::client::PORTABLE_SERVICE_RUNNING
|
||||
.lock()
|
||||
.unwrap()
|
||||
.clone();
|
||||
}
|
||||
#[cfg(not(windows))]
|
||||
return false;
|
||||
}
|
||||
|
||||
pub fn elevate_portable(id: i32) {
|
||||
#[cfg(windows)]
|
||||
{
|
||||
let lock = CLIENTS.read().unwrap();
|
||||
if let Some(s) = lock.get(&id) {
|
||||
allow_err!(s.tx.send(ipc::Data::DataPortableService(
|
||||
ipc::DataPortableService::RequestStart
|
||||
)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,8 +10,7 @@ use hbb_common::password_security;
|
||||
use hbb_common::{
|
||||
allow_err,
|
||||
config::{self, Config, LocalConfig, PeerConfig},
|
||||
directories_next, log,
|
||||
sleep,
|
||||
directories_next, log, sleep,
|
||||
tokio::{self, sync::mpsc, time},
|
||||
};
|
||||
|
||||
@ -376,7 +375,7 @@ pub fn is_installed() -> bool {
|
||||
|
||||
#[cfg(any(target_os = "android", target_os = "ios"))]
|
||||
#[inline]
|
||||
pub fn is_installed() -> bool {
|
||||
pub fn is_installed() -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
|
@ -1,11 +1,11 @@
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
use crate::client::{get_key_state, SERVER_KEYBOARD_ENABLED};
|
||||
use crate::client::io_loop::Remote;
|
||||
use crate::client::{
|
||||
check_if_retry, handle_hash, handle_login_from_ui, handle_test_delay, input_os_password,
|
||||
load_config, send_mouse, start_video_audio_threads, FileManager, Key, LoginConfigHandler,
|
||||
QualityStatus, KEY_MAP,
|
||||
};
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
use crate::client::{get_key_state, SERVER_KEYBOARD_ENABLED};
|
||||
#[cfg(target_os = "linux")]
|
||||
use crate::common::IS_X11;
|
||||
use crate::{client::Data, client::Interface};
|
||||
@ -15,9 +15,9 @@ use hbb_common::rendezvous_proto::ConnType;
|
||||
use hbb_common::tokio::{self, sync::mpsc};
|
||||
use hbb_common::{allow_err, message_proto::*};
|
||||
use hbb_common::{fs, get_version_number, log, Stream};
|
||||
use rdev::{Event, EventType, EventType::*, Key as RdevKey};
|
||||
#[cfg(not(any(target_os = "android", target_os = "ios")))]
|
||||
use rdev::{Keyboard as RdevKeyboard, KeyboardState};
|
||||
use rdev::{Event, EventType, EventType::*, Key as RdevKey};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
|
||||
@ -1120,6 +1120,7 @@ pub trait InvokeUiSession: Send + Sync + Clone + 'static + Sized + Default {
|
||||
fn msgbox(&self, msgtype: &str, title: &str, text: &str, link: &str, retry: bool);
|
||||
#[cfg(any(target_os = "android", target_os = "ios"))]
|
||||
fn clipboard(&self, content: String);
|
||||
fn cancel_msgbox(&self, tag: &str);
|
||||
}
|
||||
|
||||
impl<T: InvokeUiSession> Deref for Session<T> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user