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

feat: Expose "report_launch_failure" so engine can call it. #97

Merged
merged 1 commit into from
Mar 20, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions example/counter/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ packages:
dependency: transitive
description:
name: characters
sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605"
sha256: e6a326c8af69605aec75ed6c187d06b349707a27fbff8222ca9cc2cff167975c
url: "https://pub.dev"
source: hosted
version: "1.3.0"
version: "1.2.1"
clock:
dependency: transitive
description:
Expand All @@ -37,10 +37,10 @@ packages:
dependency: transitive
description:
name: collection
sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c"
sha256: cfc915e6923fe5ce6e153b0723c753045de46de1b4d63771530504004a45fae0
url: "https://pub.dev"
source: hosted
version: "1.17.1"
version: "1.17.0"
cupertino_icons:
dependency: "direct main"
description:
Expand Down Expand Up @@ -94,10 +94,10 @@ packages:
dependency: transitive
description:
name: js
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
sha256: "5528c2f391ededb7775ec1daa69e65a2d61276f7552de2b5f7b8d34ee9fd4ab7"
url: "https://pub.dev"
source: hosted
version: "0.6.7"
version: "0.6.5"
lints:
dependency: transitive
description:
Expand All @@ -110,10 +110,10 @@ packages:
dependency: transitive
description:
name: matcher
sha256: c94db23593b89766cda57aab9ac311e3616cf87c6fa4e9749df032f66f30dcb8
sha256: "16db949ceee371e9b99d22f88fa3a73c4e59fd0afed0bd25fc336eb76c198b72"
url: "https://pub.dev"
source: hosted
version: "0.12.14"
version: "0.12.13"
material_color_utilities:
dependency: transitive
description:
Expand All @@ -126,18 +126,18 @@ packages:
dependency: transitive
description:
name: meta
sha256: "12307e7f0605ce3da64cf0db90e5fcab0869f3ca03f76be6bb2991ce0a55e82b"
sha256: "6c268b42ed578a53088d834796959e4a1814b5e9e164f147f580a386e5decf42"
url: "https://pub.dev"
source: hosted
version: "1.9.0"
version: "1.8.0"
path:
dependency: transitive
description:
name: path
sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917"
sha256: db9d4f58c908a4ba5953fcee2ae317c94889433e5024c27ce74a37f94267945b
url: "https://pub.dev"
source: hosted
version: "1.8.3"
version: "1.8.2"
sky_engine:
dependency: transitive
description: flutter
Expand Down Expand Up @@ -187,10 +187,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: "6182294da5abf431177fccc1ee02401f6df30f766bc6130a0852c6b6d7ee6b2d"
sha256: ad540f65f92caa91bf21dfc8ffb8c589d6e4dc0c2267818b4cc2792857706206
url: "https://pub.dev"
source: hosted
version: "0.4.18"
version: "0.4.16"
vector_math:
dependency: transitive
description:
Expand All @@ -200,4 +200,4 @@ packages:
source: hosted
version: "2.1.4"
sdks:
dart: ">=2.19.0 <4.0.0"
dart: ">=2.19.0 <3.0.0"
3 changes: 2 additions & 1 deletion updater/dart_bindings/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ environment:
# Add regular dependencies here.
dependencies:
ffi: ^2.0.1
path: ^1.8.3
# path version must match that depended on by Flutter SDK.
path: ^1.8.2

dev_dependencies:
lints: ^2.0.0
Expand Down
3 changes: 2 additions & 1 deletion updater/library/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ log = "0.4.14"
once_cell = "1.17.1"
serde_yaml = "0.9.19"
uuid = { version = "1.3.0", features = ["v4", "fast-rng", "macro-diagnostics", "serde"]}
sha2 = "0.10.6"

[target.'cfg(target_os = "android")'.dependencies]
android_logger = "0.13.0"
log-panics = { version = "2", features = ["with-backtrace"]}


[dev-dependencies]
tempdir = "0.3.7"
tempdir = "0.3.7"
2 changes: 2 additions & 0 deletions updater/library/include/updater.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ SHOREBIRD_EXPORT bool shorebird_check_for_update(void);
*/
SHOREBIRD_EXPORT void shorebird_update(void);

SHOREBIRD_EXPORT void shorebird_report_failed_launch(void);

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus
Expand Down
14 changes: 14 additions & 0 deletions updater/library/src/c_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,17 @@ pub extern "C" fn shorebird_check_for_update() -> bool {
pub extern "C" fn shorebird_update() {
updater::update();
}

/// Report that the app failed to launch. This will cause the updater to
/// attempt to roll back to the previous version if this version has not
/// been launched successfully before.
#[no_mangle]
pub extern "C" fn shorebird_report_failed_launch() {
let result = updater::report_failed_launch();
match result {
Ok(_) => {}
Err(e) => {
error!("Error recording launch failure: {:?}", e);
}
}
}
25 changes: 22 additions & 3 deletions updater/library/src/cache.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This file deals with the cache / state management for the updater.

use std::fs::File;
use std::io::{BufReader, BufWriter};
use std::io::{BufReader, BufWriter, Write};
use std::path::{Path, PathBuf};

use anyhow::Ok;
Expand All @@ -15,7 +15,7 @@ pub struct PatchInfo {
pub number: usize,
}

#[derive(Deserialize, Serialize, Default, Clone)]
#[derive(Deserialize, Serialize, Default, Clone, Debug)]
struct Slot {
/// Path to the slot directory.
path: String,
Expand Down Expand Up @@ -62,6 +62,17 @@ impl UpdaterState {
}
}

// fn compute_hash(path: &Path) -> anyhow::Result<String> {
// use sha2::{Digest, Sha256};
// use std::{fs, io};

// let mut file = fs::File::open(&path)?;
// let mut hasher = Sha256::new();
// let n = io::copy(&mut file, &mut hasher)?;
// let hash = hasher.finalize();
// Ok(format!("{:x}", hash))
// }

impl UpdaterState {
pub fn is_known_good_patch(&self, patch: &PatchInfo) -> bool {
self.successful_patches.iter().any(|v| v == &patch.number)
Expand All @@ -80,6 +91,7 @@ impl UpdaterState {
if self.is_known_bad_patch(patch) {
return;
}
info!("Marking patch {} as bad", patch.number);
self.failed_patches.push(patch.number.clone());
}

Expand All @@ -95,7 +107,7 @@ impl UpdaterState {
self.successful_patches.push(patch.number.clone());
}

pub fn load(cache_dir: &str) -> anyhow::Result<Self> {
fn load(cache_dir: &str) -> anyhow::Result<Self> {
// Load UpdaterState from disk
let path = Path::new(cache_dir).join("state.json");
let file = File::open(path)?;
Expand Down Expand Up @@ -150,6 +162,13 @@ impl UpdaterState {
return true;
}
// TODO: This should also check if the hash matches?
// let hash = compute_hash(&PathBuf::from(&slot.path));
// if let Ok(hash) = hash {
// if hash == slot.hash {
// return true;
// }
// error!("Hash mismatch for slot: {:?}", slot);
// }
false
}

Expand Down