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

Update iced to 13.0 #50

Merged
merged 8 commits into from
Oct 8, 2024
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
679 changes: 298 additions & 381 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions crate/multiworld-gui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ clap = { version = "4", features = ["derive"] }
dark-light = "1"
enum-iterator = "2"
futures = "0.3"
iced = { version = "0.12", default-features = false, features = ["advanced", "image", "svg", "tokio"] }
iced_runtime = "0.12"
iced = { version = "0.13", default-features = false, features = ["advanced", "image", "svg", "tiny-skia", "tokio"] }
if_chain = "1"
image = { version = "0.24", default-features = false, features = ["ico"] } # transitive dependency of iced
itertools = "0.13"
Expand Down
2 changes: 1 addition & 1 deletion crate/multiworld-gui/src/everdrive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ pub(crate) struct Subscription {
impl Recipe for Subscription {
type Output = Message;

fn hash(&self, state: &mut iced::advanced::Hasher) {
fn hash(&self, state: &mut iced::advanced::subscription::Hasher) {
TypeId::of::<Self>().hash(state);
}

Expand Down
2 changes: 1 addition & 1 deletion crate/multiworld-gui/src/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub(crate) struct Subscription(pub(crate) Provider);
impl Recipe for Subscription {
type Output = Message;

fn hash(&self, state: &mut iced::advanced::Hasher) {
fn hash(&self, state: &mut iced::advanced::subscription::Hasher) {
TypeId::of::<Self>().hash(state);
self.0.hash(state);
}
Expand Down
160 changes: 78 additions & 82 deletions crate/multiworld-gui/src/main.rs

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions crate/multiworld-gui/src/subscriptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use {
},
},
iced::advanced::subscription::{
self,
EventStream,
Recipe,
},
Expand Down Expand Up @@ -73,7 +74,7 @@ pub(crate) struct LoggingSubscription<T> {
impl<T: Recipe<Output = Message> + 'static> Recipe for LoggingSubscription<T> {
type Output = Message;

fn hash(&self, state: &mut iced::advanced::Hasher) {
fn hash(&self, state: &mut subscription::Hasher) {
TypeId::of::<Self>().hash(state);
self.inner.hash(state);
}
Expand Down Expand Up @@ -101,7 +102,7 @@ pub(crate) struct Connection {
impl Recipe for Connection {
type Output = Message;

fn hash(&self, state: &mut iced::advanced::Hasher) {
fn hash(&self, state: &mut subscription::Hasher) {
TypeId::of::<Self>().hash(state);
self.connection_id.hash(state);
}
Expand Down Expand Up @@ -141,7 +142,7 @@ pub(crate) struct Listener {
impl Recipe for Listener {
type Output = Message;

fn hash(&self, state: &mut iced::advanced::Hasher) {
fn hash(&self, state: &mut subscription::Hasher) {
TypeId::of::<Self>().hash(state);
self.connection_id.hash(state);
}
Expand Down Expand Up @@ -183,7 +184,7 @@ pub(crate) struct Client {
impl Recipe for Client {
type Output = Message;

fn hash(&self, state: &mut iced::advanced::Hasher) {
fn hash(&self, state: &mut subscription::Hasher) {
TypeId::of::<Self>().hash(state);
}

Expand Down
3 changes: 1 addition & 2 deletions crate/multiworld-installer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ dark-light = "1"
directories = "5"
enum-iterator = "2"
futures = "0.3"
iced = { version = "0.12", default-features = false, features = ["image", "tokio"] }
iced_runtime = "0.12"
iced = { version = "0.13", default-features = false, features = ["image", "tiny-skia", "tokio"] }
image = { version = "0.24", default-features = false, features = ["ico"] } # transitive dependency of iced
itertools = "0.13"
lazy-regex = "3"
Expand Down
63 changes: 27 additions & 36 deletions crate/multiworld-installer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ use {
Future,
},
iced::{
Application,
Command,
Element,
Length,
Settings,
Size,
Task,
Theme,
clipboard,
widget::*,
Expand Down Expand Up @@ -194,13 +192,13 @@ enum Message {
SetOpenEmulator(bool),
}

fn cmd(future: impl Future<Output = Result<Message, Error>> + Send + 'static) -> Command<Message> {
Command::single(iced_runtime::command::Action::Future(Box::pin(async move {
fn cmd(future: impl Future<Output = Result<Message, Error>> + Send + 'static) -> Task<Message> {
Task::future(Box::pin(async move {
match future.await {
Ok(msg) => msg,
Err(e) => Message::Error(Arc::new(e)),
}
})))
}))
}

#[derive(Default, Deserialize, Serialize)]
Expand Down Expand Up @@ -293,17 +291,9 @@ struct State {
open_emulator: bool,
}

impl Application for State {
type Executor = iced::executor::Default;
type Message = Message;
type Theme = Theme;
type Flags = Args;

fn new(Args { mut emulator }: Args) -> (Self, Command<Message>) {
if let Ok(only_emulator) = all().filter(Emulator::is_supported).exactly_one() {
emulator.get_or_insert(only_emulator);
}
(Self {
impl State {
fn new(emulator: Option<Emulator>) -> Self {
Self {
http_client: reqwest::Client::builder()
.user_agent(concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")))
.use_rustls_tls()
Expand All @@ -318,11 +308,7 @@ impl Application for State {
create_multiworld_desktop_shortcut: true,
create_emulator_desktop_shortcut: true,
open_emulator: true,
}, if emulator.is_some() {
cmd(future::ok(Message::Continue))
} else {
Command::none()
})
}
}

fn theme(&self) -> Theme {
Expand All @@ -345,7 +331,7 @@ impl Application for State {

fn title(&self) -> String { format!("Mido's House Multiworld Installer") }

fn update(&mut self, msg: Message) -> Command<Message> {
fn update(&mut self, msg: Message) -> Task<Message> {
match msg {
Message::Back => self.page = match self.page {
Page::Error(_, _) | Page::Elevated | Page::SelectEmulator { .. } => unreachable!(),
Expand Down Expand Up @@ -410,7 +396,7 @@ impl Application for State {
match emulator {
Emulator::EverDrive => {
self.page = Page::EmulatorWarning { emulator, install_emulator, emulator_path: emulator_path.clone(), multiworld_path: multiworld_path.clone() };
return Command::none()
return Task::none()
}
#[cfg(target_os = "linux")] Emulator::Pj64V3 | Emulator::Pj64V4 => unreachable!(),
#[cfg(target_os = "windows")] Emulator::Pj64V3 | Emulator::Pj64V4 if !is_elevated() => {
Expand Down Expand Up @@ -616,7 +602,7 @@ impl Application for State {
match local_bizhawk_version.cmp(&required_bizhawk_version) {
Less => {
self.page = Page::AskBizHawkUpdate { emulator_path: emulator_path.clone(), multiworld_path: multiworld_path.clone() };
return Command::none()
return Task::none()
}
Equal => {}
Greater => return cmd(future::err(Error::BizHawkVersionRegression)),
Expand Down Expand Up @@ -731,7 +717,7 @@ impl Application for State {
}
}
}
return window::close(window::Id::MAIN)
return iced::exit()
}
},
Message::CopyDebugInfo => if let Page::Error(ref e, ref mut debug_info_copied) = self.page {
Expand All @@ -754,7 +740,7 @@ impl Application for State {
},
Message::EmulatorPath(new_path) => if let Page::LocateEmulator { ref mut emulator_path, .. } = self.page { *emulator_path = new_path },
Message::Error(e) => self.page = Page::Error(e, false),
Message::Exit => return window::close(window::Id::MAIN),
Message::Exit => return iced::exit(),
Message::InstallMultiworld => {
let (emulator, emulator_path, multiworld_path) = match self.page {
Page::LocateEmulator { emulator, ref emulator_path, ref multiworld_path, .. } |
Expand Down Expand Up @@ -941,7 +927,7 @@ impl Application for State {
Message::SetInstallEmulator(new_install_emulator) => if let Page::LocateEmulator { ref mut install_emulator, .. } = self.page { *install_emulator = new_install_emulator },
Message::SetOpenEmulator(open_emulator) => self.open_emulator = open_emulator,
}
Command::none()
Task::none()
}

fn view(&self) -> Element<'_, Message> {
Expand Down Expand Up @@ -995,7 +981,7 @@ impl Application for State {
Some({
let mut row = Row::new();
#[cfg(target_os = "windows")] if matches!(emulator, Some(Emulator::Pj64V3 | Emulator::Pj64V4)) && !is_elevated() {
row = row.push(Image::new(image::Handle::from_memory(include_bytes!("../../../assets/uac.png").to_vec())).height(Length::Fixed(20.0)));
row = row.push(Image::new(image::Handle::from_bytes(include_bytes!("../../../assets/uac.png").to_vec())).height(Length::Fixed(20.0)));
}
row = row.push(Text::new("Continue"));
(Into::<Element<'_, Message>>::into(row.spacing(8)), emulator.is_some())
Expand Down Expand Up @@ -1049,7 +1035,7 @@ impl Application for State {
Some({
let mut row = Row::new();
#[cfg(target_os = "windows")] if emulator == Emulator::BizHawk && install_emulator && !is_elevated() {
row = row.push(Image::new(image::Handle::from_memory(include_bytes!("../../../assets/uac.png").to_vec())).height(Length::Fixed(20.0)));
row = row.push(Image::new(image::Handle::from_bytes(include_bytes!("../../../assets/uac.png").to_vec())).height(Length::Fixed(20.0)));
}
row = row.push(if install_emulator { Text::new(format!("Install {emulator}")) } else { Text::new("Continue") });
(Into::<Element<'_, Message>>::into(row.spacing(8)), !emulator_path.is_empty())
Expand Down Expand Up @@ -1181,13 +1167,18 @@ enum MainError {
}

#[wheel::main]
fn main(args: Args) -> Result<(), MainError> {
Ok(State::run(Settings {
window: window::Settings {
fn main(Args { mut emulator }: Args) -> Result<(), MainError> {
if let Ok(only_emulator) = all().filter(Emulator::is_supported).exactly_one() {
emulator.get_or_insert(only_emulator);
}
let task = if emulator.is_some() { cmd(future::ok(Message::Continue)) } else { Task::none() };
Ok(iced::application(State::title, State::update, State::view)
.window(window::Settings {
size: Size { width: 400.0, height: 360.0 },
icon: Some(icon::from_file_data(include_bytes!("../../../assets/icon.ico"), Some(ImageFormat::Ico))?),
..window::Settings::default()
},
..Settings::with_flags(args)
})?)
})
.theme(State::theme)
.run_with(move || (State::new(emulator), task))?
)
}
3 changes: 1 addition & 2 deletions crate/multiworld-updater/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ chrono = { version = "0.4", default-features = false, features = ["clock", "std"
clap = { version = "4", features = ["derive"] }
dark-light = "1"
futures = "0.3"
iced = { version = "0.12", default-features = false, features = ["image", "tokio"] }
iced_runtime = "0.12"
iced = { version = "0.13", default-features = false, features = ["image", "tiny-skia", "tokio"] }
image = { version = "0.24", default-features = false, features = ["ico"] } # recursive dependency of iced
itertools = "0.13"
multiworld = { path = "../multiworld" }
Expand Down
81 changes: 38 additions & 43 deletions crate/multiworld-updater/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ use {
stream::TryStreamExt as _,
},
iced::{
Application,
Command,
Element,
Length,
Settings,
Size,
Task,
Theme,
clipboard,
widget::*,
Expand Down Expand Up @@ -178,13 +176,13 @@ impl Clone for Message {
}
}

fn cmd(future: impl Future<Output = Result<Message, Error>> + Send + 'static) -> Command<Message> {
Command::single(iced_runtime::command::Action::Future(Box::pin(async move {
fn cmd(future: impl Future<Output = Result<Message, Error>> + Send + 'static) -> Task<Message> {
Task::future(Box::pin(async move {
match future.await {
Ok(msg) => msg,
Err(e) => Message::Error(Arc::new(e.into())),
}
})))
}))
}

enum State {
Expand All @@ -209,32 +207,9 @@ struct App {
state: State,
}

impl Application for App {
type Executor = iced::executor::Default;
type Message = Message;
type Theme = Theme;
type Flags = EmuArgs;

fn new(args: EmuArgs) -> (Self, Command<Message>) {
(App {
args: args.clone(),
state: State::WaitExit,
}, cmd(async move {
let mut system = sysinfo::System::default();
match args {
EmuArgs::BizHawk { mw_pid, bizhawk_pid, .. } => {
while system.refresh_processes_specifics(ProcessesToUpdate::Some(&[mw_pid, bizhawk_pid]), ProcessRefreshKind::default()) > 0 {
sleep(Duration::from_secs(1)).await;
}
}
EmuArgs::EverDrive { pid, .. } | EmuArgs::Pj64 { pid, .. } => {
while system.refresh_processes_specifics(ProcessesToUpdate::Some(&[pid]), ProcessRefreshKind::default()) > 0 {
sleep(Duration::from_secs(1)).await;
}
}
}
Ok(Message::Exited)
}))
impl App {
fn new(args: EmuArgs) -> Self {
Self { args, state: State::WaitExit }
}

fn title(&self) -> String { format!("updating Mido's House Multiworld…") }
Expand All @@ -257,7 +232,7 @@ impl Application for App {
}
}

fn update(&mut self, msg: Message) -> Command<Message> {
fn update(&mut self, msg: Message) -> Task<Message> {
match msg {
Message::Error(e) => self.state = State::Error(e, false),
Message::CopyDebugInfo => if let State::Error(ref e, ref mut debug_info_copied) = self.state {
Expand Down Expand Up @@ -485,7 +460,7 @@ impl Application for App {
},
Message::Done => {
self.state = State::Done;
return window::close(window::Id::MAIN)
return iced::exit()
}
Message::DiscordInvite => if let Err(e) = open("https://discord.gg/BGRrKKn") {
self.state = State::Error(Arc::new(Err::<Never, _>(e).at_unknown().never_unwrap_err().into()), false);
Expand All @@ -507,7 +482,7 @@ impl Application for App {
},
Message::Cloned => self.state = State::Error(Arc::new(Error::Cloned), false),
}
Command::none()
Task::none()
}

fn view(&self) -> Element<'_, Message> {
Expand Down Expand Up @@ -648,14 +623,34 @@ enum MainError {
#[wheel::main]
fn main(args: Args) -> Result<(), MainError> {
match args {
Args::Emu(args) => Ok(App::run(Settings {
window: window::Settings {
size: Size { width: 320.0, height: 240.0 },
icon: Some(icon::from_file_data(include_bytes!("../../../assets/icon.ico"), Some(ImageFormat::Ico))?),
..window::Settings::default()
},
..Settings::with_flags(args)
})?),
Args::Emu(args) => Ok(
iced::application(App::title, App::update, App::view)
.window(window::Settings {
size: Size { width: 320.0, height: 240.0 },
icon: Some(icon::from_file_data(include_bytes!("../../../assets/icon.ico"), Some(ImageFormat::Ico))?),
..window::Settings::default()
})
.theme(App::theme)
.run_with(|| (
App::new(args.clone()),
cmd(async move {
let mut system = sysinfo::System::default();
match args {
EmuArgs::BizHawk { mw_pid, bizhawk_pid, .. } => {
while system.refresh_processes_specifics(ProcessesToUpdate::Some(&[mw_pid, bizhawk_pid]), ProcessRefreshKind::default()) > 0 {
sleep(Duration::from_secs(1)).await;
}
}
EmuArgs::EverDrive { pid, .. } | EmuArgs::Pj64 { pid, .. } => {
while system.refresh_processes_specifics(ProcessesToUpdate::Some(&[pid]), ProcessRefreshKind::default()) > 0 {
sleep(Duration::from_secs(1)).await;
}
}
}
Ok(Message::Exited)
}),
))?
),
Args::Pj64Script { src, dst } => match pj64script(&src, &dst) {
Ok(()) => Ok(()),
Err(e) => {
Expand Down