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

deps: update rust and js #122

Merged
merged 3 commits into from
Sep 1, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
234 changes: 119 additions & 115 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ tracing-appender = "0.2"
[target.'cfg(windows)'.dependencies]
win-gsmtc = { path = "lib/win-gsmtc" }
win-wrapper = { path = "lib/win-wrapper" }
windows = "0.39"

[build-dependencies]
actix-web-static-files = "4.0"
6,762 changes: 4,553 additions & 2,209 deletions js/package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
"test": "npm run test --workspaces"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.31.0",
"@typescript-eslint/parser": "^5.31.0",
"eslint": "^8.20.0",
"@typescript-eslint/eslint-plugin": "^5.36.1",
"@typescript-eslint/parser": "^5.36.1",
"eslint": "^8.23.0",
"eslint-plugin-prettier": "^4.2.1",
"prettier": "^2.7.1",
"typescript": "^4.7.4"
"typescript": "^4.8.2"
}
}
4 changes: 2 additions & 2 deletions js/packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"test": "echo 0"
},
"devDependencies": {
"parcel": "^2.6.2",
"typescript": "^4.7.4",
"parcel": "^2.7.0",
"typescript": "^4.8.2",
"tslib": "^2.4.0",
"rimraf": "^3.0.2",
"parcel-resolver-ignore": "^2.1.3"
Expand Down
14 changes: 7 additions & 7 deletions js/packages/extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@
},
"dependencies": {
"beaverjs": "^0.3.1",
"lit": "^2.2.8"
"lit": "^2.3.1"
},
"devDependencies": {
"parcel": "^2.6.2",
"@parcel/config-webextension": "^2.6.2",
"web-ext": "^7.1.1",
"dotenv": "^16.0.1",
"parcel": "^2.7.0",
"@parcel/config-webextension": "^2.7.0",
"web-ext": "^7.2.0",
"dotenv": "^16.0.2",
"@types/firefox-webext-browser": "94.0.1",
"jest": "^28.1.3",
"ts-jest": "^28.0.7",
"@types/jest": "^28.1.6",
"ts-jest": "^28.0.8",
"@types/jest": "^29.0.0",
"rimraf": "^3.0.2"
}
}
2 changes: 1 addition & 1 deletion lib/win-gsmtc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ path = "src/lib.rs"

[dependencies]
tokio = { version = "1.20", features = ["sync", "macros", "rt"] }
windows = { version = "0.38", features = ["Media_Control", "Foundation", "Foundation_Collections", "Storage_Streams"] }
windows = { version = "0.39", features = ["Media_Control", "Foundation", "Foundation_Collections", "Storage_Streams"] }
tracing = "0.1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand Down
4 changes: 2 additions & 2 deletions lib/win-gsmtc/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl SessionManager {

let update_token = {
let loop_tx = Arc::downgrade(&loop_tx);
this.SessionsChanged(TypedEventHandler::new(move |_, _| {
this.SessionsChanged(&TypedEventHandler::new(move |_, _| {
event!(Level::DEBUG, "SessionsChanged");
if let Some(loop_tx) = loop_tx.upgrade() {
loop_tx.send(ManagerCommand::UpdateSessions).ok();
Expand All @@ -66,7 +66,7 @@ impl SessionManager {
};
let current_changed_token = {
let loop_tx = Arc::downgrade(&loop_tx);
this.CurrentSessionChanged(TypedEventHandler::new(move |_, _| {
this.CurrentSessionChanged(&TypedEventHandler::new(move |_, _| {
event!(Level::DEBUG, "Current SessionChanged");
if let Some(loop_tx) = loop_tx.upgrade() {
loop_tx.send(ManagerCommand::CurrentSessionChanged).ok();
Expand Down
12 changes: 6 additions & 6 deletions lib/win-gsmtc/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ impl SessionHandle {
let source = sess.SourceAppUserModelId()?.to_string();
let session_tx = Arc::downgrade(&loop_tx);
let (playback_token, media_token, timeline_token) = (
sess.PlaybackInfoChanged(feed_eventloop_handler(session_tx.clone(), || {
sess.PlaybackInfoChanged(&feed_eventloop_handler(session_tx.clone(), || {
SessionCommand::PlaybackInfoChanged
}))?,
sess.MediaPropertiesChanged(feed_eventloop_handler(session_tx.clone(), || {
sess.MediaPropertiesChanged(&feed_eventloop_handler(session_tx.clone(), || {
SessionCommand::MediaPropertiesChanged
}))?,
sess.TimelinePropertiesChanged(feed_eventloop_handler(session_tx.clone(), || {
sess.TimelinePropertiesChanged(&feed_eventloop_handler(session_tx.clone(), || {
SessionCommand::TimelinePropertiesChanged
}))?,
);
Expand Down Expand Up @@ -217,13 +217,13 @@ fn skip_timeline_emit(model: &SessionModel, new: &TimelineModel) -> bool {
impl Drop for SessionWorker {
fn drop(&mut self) {
self.session
.RemovePlaybackInfoChanged(&self.playback_token)
.RemovePlaybackInfoChanged(self.playback_token)
.ok();
self.session
.RemoveTimelinePropertiesChanged(&self.timeline_token)
.RemoveTimelinePropertiesChanged(self.timeline_token)
.ok();
self.session
.RemoveMediaPropertiesChanged(&self.media_token)
.RemoveMediaPropertiesChanged(self.media_token)
.ok();
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/win-wrapper/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ version = "0.1.0"
edition = "2021"

[dependencies]
windows = { version = "0.38", features = ["Win32_Foundation", "alloc", "Win32_UI_WindowsAndMessaging", "Win32_System_Registry", "Win32_Security", "Win32_UI_Shell", "Win32_System_Threading", "Win32_System_ProcessStatus"] }
windows = { version = "0.39", features = ["Win32_Foundation", "Win32_UI_WindowsAndMessaging", "Win32_System_Registry", "Win32_Security", "Win32_UI_Shell", "Win32_System_Threading", "Win32_System_ProcessStatus"] }
26 changes: 15 additions & 11 deletions lib/win-wrapper/src/autostart.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use std::{env, iter, ops::Deref, os::windows::ffi::OsStrExt, ptr};
use windows::Win32::{
Foundation::{ERROR_MORE_DATA, ERROR_SUCCESS, WIN32_ERROR},
System::Registry::{
RegCloseKey, RegCreateKeyExW, RegGetValueW, RegSetValueExW, HKEY, HKEY_CURRENT_USER,
KEY_CREATE_SUB_KEY, KEY_SET_VALUE, REG_SZ, RRF_RT_REG_SZ,
use windows::{
core::HSTRING,
w,
Win32::{
Foundation::{ERROR_MORE_DATA, ERROR_SUCCESS, WIN32_ERROR},
System::Registry::{
RegCloseKey, RegCreateKeyExW, RegGetValueW, RegSetValueExW, HKEY, HKEY_CURRENT_USER,
KEY_CREATE_SUB_KEY, KEY_SET_VALUE, REG_SZ, RRF_RT_REG_SZ,
},
},
};

Expand Down Expand Up @@ -36,13 +40,13 @@ impl Drop for ManagedHkey {
}
}

pub fn add_self_to_autostart(application_name: &str) -> Result<(), WIN32_ERROR> {
pub fn add_self_to_autostart(application_name: &HSTRING) -> Result<(), WIN32_ERROR> {
unsafe {
let mut hkey = HKEY(0);
let hkey = ManagedHkey::try_new(
RegCreateKeyExW(
HKEY_CURRENT_USER,
"Software\\Microsoft\\Windows\\CurrentVersion\\Run",
windows::w!("Software\\Microsoft\\Windows\\CurrentVersion\\Run"),
0,
None,
REG_OPTION_RESERVED,
Expand Down Expand Up @@ -75,12 +79,12 @@ pub fn add_self_to_autostart(application_name: &str) -> Result<(), WIN32_ERROR>
}
}

pub fn check_autostart(application_name: &str) -> bool {
pub fn check_autostart(application_name: &HSTRING) -> bool {
unsafe {
matches!(
RegGetValueW(
HKEY_CURRENT_USER,
"Software\\Microsoft\\Windows\\CurrentVersion\\Run",
windows::core::w!("Software\\Microsoft\\Windows\\CurrentVersion\\Run"),
application_name,
RRF_RT_REG_SZ,
ptr::null_mut(),
Expand All @@ -92,12 +96,12 @@ pub fn check_autostart(application_name: &str) -> bool {
}
}

pub fn remove_autostart(application_name: &str) {
pub fn remove_autostart(application_name: &HSTRING) {
unsafe {
let mut hkey = HKEY(0);
if RegOpenKeyExW(
HKEY_CURRENT_USER,
"Software\\Microsoft\\Windows\\CurrentVersion\\Run",
w!("Software\\Microsoft\\Windows\\CurrentVersion\\Run"),
0,
KEY_SET_VALUE,
&mut hkey,
Expand Down
99 changes: 38 additions & 61 deletions lib/win-wrapper/src/message_box/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use std::marker::PhantomData;
use windows::Win32::{
Foundation::{GetLastError, WIN32_ERROR},
UI::WindowsAndMessaging::{
MessageBoxA, MB_ICONASTERISK, MB_ICONERROR, MB_ICONEXCLAMATION, MB_ICONHAND,
MB_ICONINFORMATION, MB_ICONQUESTION, MB_ICONSTOP, MB_ICONWARNING, MESSAGEBOX_RESULT,
MESSAGEBOX_STYLE,
use windows::{
core::HSTRING,
Win32::{
Foundation::{GetLastError, WIN32_ERROR},
UI::WindowsAndMessaging::{
MessageBoxW, MB_ICONASTERISK, MB_ICONERROR, MB_ICONEXCLAMATION, MB_ICONHAND,
MB_ICONINFORMATION, MB_ICONQUESTION, MB_ICONSTOP, MB_ICONWARNING, MESSAGEBOX_RESULT,
MESSAGEBOX_STYLE,
},
},
};

Expand Down Expand Up @@ -54,15 +57,27 @@ impl MessageBoxIcon {
}
}

pub struct MessageBox<'text, 'title, T> {
pub struct MessageBox<'a, T> {
icon: MessageBoxIcon,
text: &'text str,
title: Option<&'title str>,
text: &'a HSTRING,
title: Option<&'a HSTRING>,
_response: PhantomData<T>,
}

impl<'text, 'title, T: MessageBoxOption> MessageBox<'text, 'title, T> {
pub fn new(text: &'text str) -> Self {
macro_rules! ctors {
($($ctor:ident, $name:ident => $icon:ident),*) => {
$(pub fn $ctor(self) -> Self {
self.icon(MessageBoxIcon::$icon)
}
pub fn $name(text: &'a HSTRING) -> Self {
Self::new(text).$ctor()
}
)*
};
}

impl<'a, T: MessageBoxOption> MessageBox<'a, T> {
pub fn new(text: &'a HSTRING) -> Self {
Self {
icon: MessageBoxIcon::Information,
text,
Expand All @@ -75,67 +90,29 @@ impl<'text, 'title, T: MessageBoxOption> MessageBox<'text, 'title, T> {
self.icon = icon;
self
}
pub fn with_exclamation(self) -> Self {
self.icon(MessageBoxIcon::Exclamation)
}
pub fn with_warning(self) -> Self {
self.icon(MessageBoxIcon::Warning)
}
pub fn with_information(self) -> Self {
self.icon(MessageBoxIcon::Information)
}
pub fn with_asterisk(self) -> Self {
self.icon(MessageBoxIcon::Asterisk)
}
pub fn with_question(self) -> Self {
self.icon(MessageBoxIcon::Question)
}
pub fn with_stop(self) -> Self {
self.icon(MessageBoxIcon::Stop)
}
pub fn with_error(self) -> Self {
self.icon(MessageBoxIcon::Error)
}
pub fn with_hand(self) -> Self {
self.icon(MessageBoxIcon::Hand)
}

pub fn exclamation(text: &'text str) -> Self {
Self::new(text).with_exclamation()
}
pub fn warning(text: &'text str) -> Self {
Self::new(text).with_warning()
}
pub fn information(text: &'text str) -> Self {
Self::new(text).with_information()
}
pub fn asterisk(text: &'text str) -> Self {
Self::new(text).with_asterisk()
}
pub fn question(text: &'text str) -> Self {
Self::new(text).with_question()
}
pub fn stop(text: &'text str) -> Self {
Self::new(text).with_stop()
}
pub fn error(text: &'text str) -> Self {
Self::new(text).with_error()
}
pub fn hand(text: &'text str) -> Self {
Self::new(text).with_hand()
ctors! {
with_exclamation, exclamation => Exclamation,
with_warning, warning => Warning,
with_information, information => Information,
with_asterisk, asterisk => Asterisk,
with_question, question => Question,
with_stop, stop => Stop,
with_error, error => Error,
with_hand, hand => Hand
}

pub fn with_title(mut self, title: &'title str) -> Self {
pub fn with_title(mut self, title: &'a HSTRING) -> Self {
self.title = Some(title);
self
}

pub fn show(self) -> Result<T, WIN32_ERROR> {
let return_code = unsafe {
if let Some(title) = self.title {
MessageBoxA(None, self.text, title, T::flags() | self.icon.style())
MessageBoxW(None, self.text, title, T::flags() | self.icon.style())
} else {
MessageBoxA(None, self.text, None, T::flags() | self.icon.style())
MessageBoxW(None, self.text, None, T::flags() | self.icon.style())
}
};
match return_code {
Expand Down
6 changes: 3 additions & 3 deletions lib/win-wrapper/src/single_instance.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::pwstr::ManagedPwstr;
use std::{env, mem, ptr};
use windows::{
core::{Error, Result, HRESULT},
core::{Error, Result, HRESULT, HSTRING},
Win32::{
Foundation::{CloseHandle, GetLastError, ERROR_ALREADY_EXISTS, ERROR_NOT_FOUND, MAX_PATH},
System::{
Expand All @@ -19,7 +19,7 @@ use windows::{
/// If the mutex is already locked, then another application locked the mutex and another instance is already running.
///
/// Returns `false` if another instance is already running, and `true` if we are the only instance running.
pub fn try_create_new_instance(unique_instance_id: &str) -> bool {
pub fn try_create_new_instance(unique_instance_id: &HSTRING) -> bool {
unsafe {
match CreateMutexW(ptr::null(), true, unique_instance_id) {
Ok(_) => true,
Expand All @@ -46,7 +46,7 @@ pub fn kill_other_instances_of_this_application() -> Result<()> {
None => return Err(Error::from(HRESULT::from(ERROR_NOT_FOUND))),
};
unsafe {
let handle = OpenProcess(PROCESS_TERMINATE, None, pid)?;
let handle = OpenProcess(PROCESS_TERMINATE, false, pid)?;

if !TerminateProcess(handle, u32::MAX).as_bool() {
return Err(GetLastError().into());
Expand Down
Loading