From 672c3f796f4d3e349655adeb49ccb2eea4609c2e Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 11 Oct 2023 10:45:49 +0200 Subject: [PATCH 1/5] added logic to delete all notification storage when an app is uninstalled, added logic to clear systray icon upon opening a happ window if no unread messages of any other apps are left --- src-tauri/src/commands/notifications.rs | 2 +- src/App.vue | 11 +++++++++++ src/store/index.ts | 1 + src/utils.ts | 19 +++++++++++++++++++ src/views/Settings.vue | 2 ++ 5 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src-tauri/src/commands/notifications.rs b/src-tauri/src/commands/notifications.rs index 3d70ba06..abd6c2fc 100644 --- a/src-tauri/src/commands/notifications.rs +++ b/src-tauri/src/commands/notifications.rs @@ -127,7 +127,7 @@ pub async fn clear_happ_notifications( ) -> Result<(), String> { // This tauri command is allowed to be called only by the window of the corresponding app: if window.label() != derive_window_label(&app_id) { - return Err(String::from("Unauthorized: Attempted to notifications for app that this tauri window is not associated to.")) + return Err(String::from("Unauthorized: Attempted to clear notifications for app that this tauri window is not associated to.")) } // Send notifications to admin window to store to localStorage and check diff --git a/src/App.vue b/src/App.vue index cce59c51..9d9bbd52 100644 --- a/src/App.vue +++ b/src/App.vue @@ -187,6 +187,17 @@ export default defineComponent({ async (e: Event) => { await clearHappNotifications(e.payload); this.$store.commit("loadNotificationState"); + // Check whether there are any unread messages left across all apps + // and if not, clear the systray icon dot + const overallUnreadNotifications = Object.entries( + this.$store.state.notificationState + ).filter( + ([_appId, unreadNotifications]) => + unreadNotifications && unreadNotifications.length > 0 + ); + if (overallUnreadNotifications.length === 0) { + await invoke("clear_systray_icon", {}); + } } ); diff --git a/src/store/index.ts b/src/store/index.ts index a18db054..93878c1f 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -415,6 +415,7 @@ export const store = createStore({ async fetchStateInfo({ commit }) { commit("loadStateInfo"); const StateInfo: LauncherStateInfo = await invoke("get_state_info", {}); + commit("loadNotificationState"); commit("setStateInfo", StateInfo); }, diff --git a/src/utils.ts b/src/utils.ts index e5a3dfd5..af541030 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -328,3 +328,22 @@ export function setHappNotificationSettings( ): void { setLocalStorageItem(`happNotificationSettings#${installedAppId}`, settings); } + +/** + * Deletes all notification storage related to an app. To be called upon unsinstalling the app + */ +export function deleteNotificationStorage( + installedAppId: InstalledAppId +): void { + window.localStorage.removeItem(`happNotificationSettings#${installedAppId}`); + window.localStorage.removeItem(`happNotificationsUnread#${installedAppId}`); + // Remove all historical notificationss + Object.keys(window.localStorage).forEach((key) => { + if ( + key.includes("happNotifications#") && + key.includes(`#${installedAppId}`) + ) { + window.localStorage.removeItem(key); + } + }); +} diff --git a/src/views/Settings.vue b/src/views/Settings.vue index d4fc9708..b09a037a 100644 --- a/src/views/Settings.vue +++ b/src/views/Settings.vue @@ -545,6 +545,7 @@ import { isAppRunning, locatorToLocatorB64, capitalizeFirstLetter, + deleteNotificationStorage, } from "../utils"; import { mapGetters } from "vuex"; @@ -915,6 +916,7 @@ export default defineComponent({ try { await invoke("uninstall_app", { appId, holochainId: app.holochainId }); + deleteNotificationStorage(appId); await this.refreshAppStates(); this.showMessage(`Uninstalled ${appId}`); } catch (e) { From 31d0088e9a9f407a0f64416ec0539550e4294564 Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 11 Oct 2023 10:57:01 +0200 Subject: [PATCH 2/5] added logic to listen to focus event for macos --- src-tauri/src/main.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 6398a8d9..2b0a4a6d 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -218,6 +218,15 @@ fn main() { // TODO garbage collect windows in the front-end if they have notificationSettings all turned off RunEvent::WindowEvent { label, event: window_event, .. } => { match window_event { + // On macOS the window remains in the dock even when hidden, i.e. it needs to become visible again + // upon clicking on the icon in the dock + #[cfg(target_os = "macos")] + WindowEvent::Focused(true) => { + let window_option = app_handle.get_window(&label); + if let Some(window) = window_option { + window.show().unwrap(); + } + } WindowEvent::CloseRequested { api, .. } => { let window_option = app_handle.get_window(&label); if let Some(window) = window_option { From bb3c7949aef18d7deb1780946dd86e3a852520fe Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 11 Oct 2023 12:07:40 +0200 Subject: [PATCH 3/5] removed non-working workaround for tauri issue 3084 --- src-tauri/src/main.rs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 2b0a4a6d..6398a8d9 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -218,15 +218,6 @@ fn main() { // TODO garbage collect windows in the front-end if they have notificationSettings all turned off RunEvent::WindowEvent { label, event: window_event, .. } => { match window_event { - // On macOS the window remains in the dock even when hidden, i.e. it needs to become visible again - // upon clicking on the icon in the dock - #[cfg(target_os = "macos")] - WindowEvent::Focused(true) => { - let window_option = app_handle.get_window(&label); - if let Some(window) = window_option { - window.show().unwrap(); - } - } WindowEvent::CloseRequested { api, .. } => { let window_option = app_handle.get_window(&label); if let Some(window) = window_option { From e51d2525d2cf50651f8648aa108820cf233bcd8e Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 11 Oct 2023 12:10:04 +0200 Subject: [PATCH 4/5] added pimped shell script to install holochai and lair binaries --- scripts/setup-binaries.sh | 53 ++++++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/scripts/setup-binaries.sh b/scripts/setup-binaries.sh index 6cb0720c..a709ec7f 100644 --- a/scripts/setup-binaries.sh +++ b/scripts/setup-binaries.sh @@ -1,12 +1,53 @@ #!/bin/bash -rm -rf src-tauri/bins/ -mkdir src-tauri/bins +REQUIRED_HOLOCHAIN_VERSION="0.2.3-beta-rc.1" +REQUIRED_LAIR_VERSION="0.3.0" +# Check that this script is being run from the right location +if [ ! -f "package.json" ] || [ ! -f "src-tauri/tauri.conf.json" ]; +then + echo "Error: You must run this script in the root directory of the launcher repository." + exit 1 +fi + +# Check wheter cargo is available +if [ ! command -v cargo &> /dev/null ] || [ ! command -v rustc &> /dev/null ]; +then + echo "Error: You need to install Rust first." + exit 1 +fi + +# get target architecture triple, e.g. unknown-linux-gnu on Ubuntu 22.04 TARGET_TRIPLE=$(rustc -vV | sed -n 's/^.*host: \(.*\)*$/\1/p') -HOLOCHAIN_PATH=$(which holochain) -cp $HOLOCHAIN_PATH src-tauri/bins/holochain-$TARGET_TRIPLE +# create src-tauri/bins if id doesn't exist +if [ ! -d src-tauri/bins ]; + then mkdir src-tauri/bins +fi + +# check whether correct holochain binary is already in the src-tauri/bins folder +if [ -f "src-tauri/bins/holochain-v${REQUIRED_HOLOCHAIN_VERSION}-$TARGET_TRIPLE" ]; + then echo "Required holochain binary already installed." + else + echo "Installing required holochain binary from crates.io" + echo "Running command 'cargo install holochain --version $REQUIRED_HOLOCHAIN_VERSION --locked --features sqlite-encrypted'" + cargo install holochain --version $REQUIRED_HOLOCHAIN_VERSION --locked --features sqlite-encrypted + echo "Copying holochain binary to src-tauri/bins folder." + HOLOCHAIN_PATH=$(which holochain) + cp $HOLOCHAIN_PATH src-tauri/bins/holochain-v${REQUIRED_HOLOCHAIN_VERSION}-$TARGET_TRIPLE +fi + +# check whether correct lair binary is already in the src-tauri/bins folder +if [ -f "src-tauri/bins/lair-keystore-v${REQUIRED_LAIR_VERSION}-${TARGET_TRIPLE}" ]; + + then echo "Required lair-keystore binary already installed." + else + echo "Installing required lair-keystore binary from crates.io" + echo "Running command 'cargo install lair-keystore --version $REQUIRED_LAIR_VERSION --locked'" + cargo install lair_keystore --version $REQUIRED_LAIR_VERSION --locked + echo "Copying lair-keystore binary to src-tauri/bins folder." + LAIR_PATH=$(which lair-keystore) + cp $LAIR_PATH src-tauri/bins/lair-keystore-v${REQUIRED_LAIR_VERSION}-$TARGET_TRIPLE +fi -LAIR_PATH=$(which lair-keystore) -cp $LAIR_PATH src-tauri/bins/lair-keystore-$TARGET_TRIPLE +echo "done." From c5cb2b17c331c7f760af9aac4486e40ddbfb00c7 Mon Sep 17 00:00:00 2001 From: Matthias Date: Wed, 11 Oct 2023 13:06:21 +0200 Subject: [PATCH 5/5] upadted build:ui script --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b026af29..64e55526 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "start:dev": "npm run build -w @holochain/launcher-api-scripts && npm run tauri dev", "start:dev2": "npm run build -w @holochain/launcher-api-scripts && npm run build:ui && cargo run --manifest-path ./src-tauri/Cargo.toml", "dev": "vite", - "build:ui": "vue-tsc --noEmit && vite build", + "build:ui": "vue-tsc --noEmit && vite build && npm run build -w @holochain/launcher-api-scripts -w @holochain/launcher-api", "build": "npm run build -w @holochain/launcher-api-scripts && npm run tauri -- build -v", "preview": "vite preview", "publish:apps": "ADMIN_PORT=10001 run-singleton \"node scripts/publish-apps.js --inspect\"",