Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: use better approach to Windows services #172679

Merged
merged 1 commit into from Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
58 changes: 7 additions & 51 deletions cli/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cli/Cargo.toml
Expand Up @@ -49,13 +49,13 @@ log = "0.4"
const_format = "0.2"
sha2 = "0.10"
base64 = "0.13"
shell-escape = "0.1.5"

[build-dependencies]
serde = { version = "1.0" }
serde_json = { version = "1.0" }

[target.'cfg(windows)'.dependencies]
windows-service = "0.5"
winreg = "0.10"
winapi = "0.3.9"

Expand Down
3 changes: 3 additions & 0 deletions cli/src/constants.rs
Expand Up @@ -61,6 +61,9 @@ pub const QUALITYLESS_SERVER_NAME: &str = concatcp!(QUALITYLESS_PRODUCT_NAME, "
/// Web URL the editor is hosted at. For VS Code, this is vscode.dev.
pub const EDITOR_WEB_URL: Option<&'static str> = option_env!("VSCODE_CLI_EDITOR_WEB_URL");

/// Name shown in places where we need to tell a user what a process is, e.g. in sleep inhibition.
pub const TUNNEL_ACTIVITY_NAME: &str = concatcp!(PRODUCT_NAME_LONG, " Tunnel");

const NONINTERACTIVE_VAR: &str = "VSCODE_CLI_NONINTERACTIVE";

pub fn get_default_user_agent() -> String {
Expand Down
6 changes: 2 additions & 4 deletions cli/src/tunnels/nosleep_macos.rs
Expand Up @@ -5,12 +5,11 @@

use std::io;

use const_format::concatcp;
use core_foundation::base::TCFType;
use core_foundation::string::{CFString, CFStringRef};
use libc::c_int;

use crate::constants::APPLICATION_NAME;
use crate::constants::TUNNEL_ACTIVITY_NAME;

extern "C" {
pub fn IOPMAssertionCreateWithName(
Expand Down Expand Up @@ -64,8 +63,7 @@ pub struct SleepInhibitor {
impl SleepInhibitor {
pub async fn new() -> io::Result<Self> {
let mut assertions = Vec::with_capacity(NUM_ASSERTIONS);
let assertion_name =
CFString::from_static_string(concatcp!(APPLICATION_NAME, " running tunnel"));
let assertion_name = CFString::from_static_string(concatcp!(TUNNEL_ACTIVITY_NAME));
for typ in ASSERTIONS {
assertions.push(Assertion::make(
&CFString::from_static_string(typ),
Expand Down
7 changes: 2 additions & 5 deletions cli/src/tunnels/nosleep_windows.rs
Expand Up @@ -5,7 +5,6 @@

use std::io;

use const_format::concatcp;
use winapi::{
ctypes::c_void,
um::{
Expand All @@ -19,15 +18,13 @@ use winapi::{
},
};

use crate::constants::APPLICATION_NAME;
use crate::constants::TUNNEL_ACTIVITY_NAME;

struct Request(*mut c_void);

impl Request {
pub fn new() -> io::Result<Self> {
let mut reason: Vec<u16> = concatcp!(APPLICATION_NAME, " running tunnel")
.encode_utf16()
.collect();
let mut reason: Vec<u16> = TUNNEL_ACTIVITY_NAME.encode_utf16().collect();
let mut context = REASON_CONTEXT {
Version: POWER_REQUEST_CONTEXT_VERSION,
Flags: POWER_REQUEST_CONTEXT_SIMPLE_STRING,
Expand Down