Skip to content

Commit 6aec582

Browse files
committed
update to auto update only
1 parent 28aa254 commit 6aec582

File tree

10 files changed

+66
-17
lines changed

10 files changed

+66
-17
lines changed

crates/fig_desktop/src/install.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ pub async fn run_install(ctx: Arc<Context>, ignore_immediate_update: bool) {
115115
use tokio::time::timeout;
116116
// Check for updates but timeout after 3 seconds to avoid making the user wait too long
117117
// todo: don't download the index file twice
118-
match timeout(Duration::from_secs(3), check_for_updates(true)).await {
118+
match timeout(Duration::from_secs(3), check_for_updates(true, true)).await {
119119
Ok(Ok(Some(_))) => {
120120
crate::update::check_for_update(true, true).await;
121121
},

crates/fig_desktop/src/tray.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ fn tray_update(proxy: &EventLoopProxy) {
9797
ignore_rollout: true,
9898
interactive: true,
9999
relaunch_dashboard: true,
100+
is_auto_update: false,
100101
},
101102
)
102103
.await;
@@ -137,7 +138,7 @@ fn tray_update(proxy: &EventLoopProxy) {
137138
///
138139
/// Returns `true` if we should continue with updating, `false` otherwise.
139140
async fn should_continue_with_update(ctx: &Context, proxy: &EventLoopProxy) -> bool {
140-
match fig_install::check_for_updates(true).await {
141+
match fig_install::check_for_updates(true, false).await {
141142
Ok(Some(pkg)) => {
142143
let file_type = get_file_type(ctx, &Variant::Full)
143144
.await

crates/fig_desktop/src/update.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ pub async fn check_for_update(show_webview: bool, relaunch_dashboard: bool) -> b
101101
ignore_rollout: false,
102102
interactive: show_webview,
103103
relaunch_dashboard,
104+
is_auto_update: true,
104105
})
105106
.await
106107
{

crates/fig_desktop_api/src/requests/update.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ pub async fn update_application(request: UpdateApplicationRequest) -> RequestRes
2020
ignore_rollout: request.ignore_rollout.unwrap_or(true),
2121
interactive: request.interactive.unwrap_or(true),
2222
relaunch_dashboard: request.relaunch_dashboard.unwrap_or(true),
23+
is_auto_update: false,
2324
},
2425
));
2526
RequestResult::success()
2627
}
2728

2829
pub async fn check_for_updates(_request: CheckForUpdatesRequest) -> RequestResult {
29-
fig_install::check_for_updates(true)
30+
fig_install::check_for_updates(true, false)
3031
.await
3132
.map(|res| {
3233
Box::new(ServerOriginatedSubMessage::CheckForUpdatesResponse(

crates/fig_install/src/index.rs

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ impl Index {
111111
let current_version = args.current_version;
112112
let product_name = args.product_name;
113113
let ignore_rollout = args.ignore_rollout;
114+
let is_auto_update = args.is_auto_update;
114115
let threshold_override = args.threshold_override;
115116

116117
if !self.supported.iter().any(|support| {
@@ -143,7 +144,9 @@ impl Index {
143144
.filter(|version| {
144145
version.update_conditions.is_empty()
145146
|| version.update_conditions.iter().all(|cond| match cond {
146-
UpdateCondition::AllowedProductNames(product_names) => product_names.contains(product_name),
147+
UpdateCondition::AllowedAutoUpdateProductNames(product_names) => {
148+
!is_auto_update || product_names.contains(product_name)
149+
},
147150
})
148151
})
149152
.collect::<Vec<&RemoteVersion>>();
@@ -252,6 +255,7 @@ pub struct FindNextVersionArgs<'a> {
252255
pub file_type: Option<&'a FileType>,
253256
pub current_version: &'a str,
254257
pub product_name: &'a ProductName,
258+
pub is_auto_update: bool,
255259
pub ignore_rollout: bool,
256260
pub threshold_override: Option<u8>,
257261
}
@@ -286,7 +290,7 @@ pub(crate) struct RemoteVersion {
286290
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
287291
#[serde(rename_all = "camelCase")]
288292
pub enum UpdateCondition {
289-
AllowedProductNames(Vec<ProductName>),
293+
AllowedAutoUpdateProductNames(Vec<ProductName>),
290294
}
291295

292296
#[derive(Debug, Clone, PartialEq, Eq, EnumString, Display)]
@@ -429,6 +433,7 @@ pub async fn check_for_updates(
429433
variant: &Variant,
430434
file_type: Option<&FileType>,
431435
ignore_rollout: bool,
436+
is_auto_update: bool,
432437
) -> Result<Option<UpdatePackage>, Error> {
433438
const CURRENT_VERSION: &str = env!("CARGO_PKG_VERSION");
434439
let product_name = ProductName::default();
@@ -439,6 +444,7 @@ pub async fn check_for_updates(
439444
current_version: CURRENT_VERSION,
440445
product_name: &product_name,
441446
ignore_rollout,
447+
is_auto_update,
442448
threshold_override: None,
443449
})
444450
}
@@ -528,6 +534,7 @@ mod tests {
528534
&Variant::Full,
529535
Some(FileType::Dmg).as_ref(),
530536
false,
537+
false,
531538
)
532539
.await
533540
.unwrap();
@@ -707,6 +714,7 @@ mod tests {
707714
current_version: "1.2.1",
708715
product_name: &product_name,
709716
ignore_rollout: true,
717+
is_auto_update: false,
710718
threshold_override: None,
711719
})
712720
.unwrap();
@@ -723,6 +731,7 @@ mod tests {
723731
current_version: "1.2.0",
724732
product_name: &ProductName::Unknown("qv2".to_string()),
725733
ignore_rollout: true,
734+
is_auto_update: false,
726735
threshold_override: None,
727736
})
728737
.unwrap()
@@ -740,6 +749,7 @@ mod tests {
740749
current_version: "1.2.1",
741750
product_name: &ProductName::AmazonQ,
742751
ignore_rollout: true,
752+
is_auto_update: false,
743753
threshold_override: None,
744754
});
745755
assert!(next.is_err());
@@ -755,6 +765,7 @@ mod tests {
755765
current_version: "1.0.5",
756766
product_name: &ProductName::Unknown("qv2".to_string()),
757767
ignore_rollout: true,
768+
is_auto_update: false,
758769
threshold_override: None,
759770
})
760771
.unwrap()
@@ -763,7 +774,7 @@ mod tests {
763774
}
764775

765776
#[test]
766-
fn index_test_allowed_product_names_update() {
777+
fn index_test_allowed_autoupdate_product_names_update() {
767778
let mut index = load_test_index();
768779

769780
let next = index
@@ -774,16 +785,34 @@ mod tests {
774785
current_version: "1.0.5",
775786
product_name: &ProductName::AmazonQ,
776787
ignore_rollout: true,
788+
is_auto_update: false,
789+
threshold_override: None,
790+
})
791+
.unwrap()
792+
.expect("should have update package");
793+
assert_eq!(
794+
next.version.to_string().as_str(),
795+
"1.2.1",
796+
"amazon q during manual update should update into 1.2.1"
797+
);
798+
let next = index
799+
.find_next_version(FindNextVersionArgs {
800+
target_triple: &TargetTriple::X86_64UnknownLinuxGnu,
801+
variant: &Variant::Full,
802+
file_type: None,
803+
current_version: "1.0.5",
804+
product_name: &ProductName::AmazonQ,
805+
ignore_rollout: true,
806+
is_auto_update: true,
777807
threshold_override: None,
778808
})
779809
.unwrap()
780810
.expect("should have update package");
781811
assert_eq!(
782812
next.version.to_string().as_str(),
783813
"1.2.0",
784-
"amazon q should update into 1.2.0"
814+
"amazon q during auto update should update into 1.2.0"
785815
);
786-
787816
let next = index
788817
.find_next_version(FindNextVersionArgs {
789818
target_triple: &TargetTriple::X86_64UnknownLinuxGnu,
@@ -792,19 +821,22 @@ mod tests {
792821
current_version: "1.0.5",
793822
product_name: &ProductName::Unknown("qv2".to_string()),
794823
ignore_rollout: true,
824+
is_auto_update: true,
795825
threshold_override: None,
796826
})
797827
.unwrap()
798828
.expect("should have update package");
799829
assert_eq!(
800830
next.version.to_string().as_str(),
801831
"1.2.1",
802-
"qv2 should update into 1.2.1"
832+
"qv2 during auto update should update into 1.2.1"
803833
);
804834

805835
// Push a newer update that allows Amazon Q
806836
let mut last = index.versions.last().cloned().unwrap();
807-
last.update_conditions = vec![UpdateCondition::AllowedProductNames(vec![ProductName::AmazonQ])];
837+
last.update_conditions = vec![UpdateCondition::AllowedAutoUpdateProductNames(vec![
838+
ProductName::AmazonQ,
839+
])];
808840
last.version = Version::from_str("2.0.0").unwrap();
809841
index.versions.push(last);
810842

@@ -816,6 +848,7 @@ mod tests {
816848
current_version: "1.0.5",
817849
product_name: &ProductName::AmazonQ,
818850
ignore_rollout: true,
851+
is_auto_update: true,
819852
threshold_override: None,
820853
})
821854
.unwrap()
@@ -824,11 +857,11 @@ mod tests {
824857
}
825858

826859
#[test]
827-
fn index_test_empty_allowed_product_names_does_not_update() {
860+
fn index_test_empty_allowed_autoupdate_product_names_does_not_update() {
828861
let mut index = load_test_index();
829862

830863
let mut last = index.versions.last().cloned().unwrap();
831-
last.update_conditions = vec![UpdateCondition::AllowedProductNames(vec![])];
864+
last.update_conditions = vec![UpdateCondition::AllowedAutoUpdateProductNames(vec![])];
832865
last.version = Version::from_str("2.0.0").unwrap();
833866
index.versions.push(last);
834867

@@ -840,6 +873,7 @@ mod tests {
840873
current_version: "1.0.5",
841874
product_name: &ProductName::Unknown("qv2".to_string()),
842875
ignore_rollout: true,
876+
is_auto_update: true,
843877
threshold_override: None,
844878
})
845879
.unwrap()

crates/fig_install/src/lib.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ pub fn get_max_channel() -> Channel {
144144
.unwrap()
145145
}
146146

147-
pub async fn check_for_updates(ignore_rollout: bool) -> Result<Option<UpdatePackage>, Error> {
147+
pub async fn check_for_updates(ignore_rollout: bool, is_auto_update: bool) -> Result<Option<UpdatePackage>, Error> {
148148
let manifest = manifest();
149149
let ctx = Context::new();
150150
let file_type = match (&manifest.variant, ctx.platform().os()) {
@@ -157,6 +157,7 @@ pub async fn check_for_updates(ignore_rollout: bool) -> Result<Option<UpdatePack
157157
&manifest.variant,
158158
file_type.as_ref(),
159159
ignore_rollout,
160+
is_auto_update,
160161
)
161162
.await
162163
}
@@ -177,6 +178,8 @@ pub struct UpdateOptions {
177178
pub interactive: bool,
178179
/// If to relaunch into dashboard after update (false will launch in background)
179180
pub relaunch_dashboard: bool,
181+
/// Whether or not the update is being invoked automatically without the user's approval
182+
pub is_auto_update: bool,
180183
}
181184

182185
/// Attempt to update if there is a newer version of Fig
@@ -187,10 +190,11 @@ pub async fn update(
187190
ignore_rollout,
188191
interactive,
189192
relaunch_dashboard,
193+
is_auto_update,
190194
}: UpdateOptions,
191195
) -> Result<bool, Error> {
192196
info!("Checking for updates...");
193-
if let Some(update) = check_for_updates(ignore_rollout).await? {
197+
if let Some(update) = check_for_updates(ignore_rollout, is_auto_update).await? {
194198
info!("Found update: {}", update.version);
195199
debug!("Update info: {:?}", update);
196200

crates/fig_install/test_files/test-index.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@
489489
"version": "1.2.1",
490490
"updateConditions": [
491491
{
492-
"allowedProductNames": ["qv2"]
492+
"allowedAutoUpdateProductNames": ["qv2"]
493493
}
494494
],
495495
"packages": [

crates/figterm/src/update.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub fn check_for_update(context: &Context) {
5555
}
5656

5757
tokio::spawn(async {
58-
match fig_install::check_for_updates(false).await {
58+
match fig_install::check_for_updates(false, true).await {
5959
Ok(Some(pkg)) => {
6060
if let Err(err) = fig_settings::state::set_value(UPDATE_AVAILABLE_KEY, pkg.version.to_string()) {
6161
warn!(?err, "Error setting {UPDATE_AVAILABLE_KEY}: {err}");

crates/q_cli/src/cli/debug/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ pub enum DebugSubcommand {
218218
#[arg(short = 'r', long)]
219219
enable_rollout: bool,
220220
#[arg(short, long)]
221+
is_auto_update: bool,
222+
#[arg(short, long)]
221223
override_threshold: Option<u8>,
222224
#[arg(short, long)]
223225
file_type: String,
@@ -749,6 +751,7 @@ impl DebugSubcommand {
749751
version: current_version,
750752
enable_rollout,
751753
override_threshold,
754+
is_auto_update,
752755
file_type,
753756
} => {
754757
use fig_install::index::{
@@ -771,6 +774,7 @@ impl DebugSubcommand {
771774
current_version,
772775
product_name: &product_name,
773776
ignore_rollout: !enable_rollout,
777+
is_auto_update: *is_auto_update,
774778
threshold_override: *override_threshold,
775779
});
776780

crates/q_cli/src/cli/update.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ impl UpdateArgs {
102102
ignore_rollout: !rollout,
103103
interactive: !non_interactive,
104104
relaunch_dashboard: *relaunch_dashboard,
105+
is_auto_update: false,
105106
},
106107
)
107108
.await;
@@ -129,7 +130,10 @@ impl UpdateArgs {
129130
}
130131

131132
async fn try_linux_update() -> Result<ExitCode> {
132-
match (fig_install::check_for_updates(true).await, bundle_metadata().await) {
133+
match (
134+
fig_install::check_for_updates(true, false).await,
135+
bundle_metadata().await,
136+
) {
133137
(ref update_result @ Ok(Some(ref pkg)), Some(file_type)) => {
134138
if file_type == FileType::AppImage {
135139
let should_continue = dialoguer::Select::with_theme(&dialoguer_theme())

0 commit comments

Comments
 (0)