Skip to content

Commit

Permalink
fix: unlisten & blur/focus fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Martichou <[email protected]>
  • Loading branch information
Martichou committed Feb 29, 2024
1 parent e904683 commit a6f52b4
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 71 deletions.
7 changes: 4 additions & 3 deletions fmt.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash

cargo-sort ./core_lib/Cargo.toml
cargo-sort ./frontend/src-tauri/Cargo.toml

for dir in core_lib frontend/src-tauri; do
find "$dir" -name '*.rs' -not -path "*/target/*" -exec rustfmt {} +
done
Expand All @@ -15,6 +18,4 @@ if git diff --name-only HEAD | grep '^frontend/src/' >/dev/null; then
pnpm lint --fix
else
echo "No changes detected in /frontend/src."
fi

cargo-sort core_lib/Cargo.toml frontend/src-tauri/Cargo.toml
fi
139 changes: 71 additions & 68 deletions frontend/src/components/HomePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,6 @@
</div>
</div>
</div>

<div v-if="item.state === 'ReceivingFiles'" class="my-auto">
<div class="hover:bg-gray-200 cursor-pointer p-2 rounded-full active:scale-105 transition duration-150 ease-in-out">
<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24">
<path d="m256-200-56-56 224-224-224-224 56-56 224 224 224-224 56 56-224 224 224 224-56 56-224-224-224 224Z" />
</svg>
</div>
</div>
</div>
</div>
</div>
Expand All @@ -258,7 +250,7 @@

<script lang="ts">
import { ref, nextTick } from 'vue'
import { listen } from '@tauri-apps/api/event'
import { UnlistenFn, listen } from '@tauri-apps/api/event'
import { invoke } from '@tauri-apps/api/tauri'
import { appWindow } from "@tauri-apps/api/window";
import { isPermissionGranted, requestPermission, sendNotification } from '@tauri-apps/api/notification'
Expand Down Expand Up @@ -311,6 +303,7 @@ export default {
outboundPayload: ref<OutboundPayload | undefined>(),
cleanupInterval: opt<NodeJS.Timeout>(),
unlisten: Array<UnlistenFn>()
};
},
Expand Down Expand Up @@ -343,79 +336,87 @@ export default {
});
}, 30000);
await listen('rs2js', (event) => {
const cm = event.payload as ChannelMessage;
console.log("rs2js:", cm);
this.unlisten.push(
await listen('rs2js', (event) => {
const cm = event.payload as ChannelMessage;
console.log("rs2js:", cm);
const idx = this.requests.findIndex((el) => el.id === cm.id);
const idx = this.requests.findIndex((el) => el.id === cm.id);
if (cm.state === "Disconnected") {
this.toDelete.push({
id: cm.id,
triggered: new Date().getTime()
});
}
if (idx !== -1) {
const prev = this.requests.at(idx);
// Update the existing message at index 'idx'
this.requests.splice(idx, 1, {
...cm,
state: cm.state ?? prev!.state,
meta: cm.meta ?? prev!.meta,
});
} else {
if (this.isAppInForeground && permissionGranted && cm.state === 'WaitingForUserConsent') {
sendNotification({ title: 'New transfer request', body: (cm.meta?.source?.name ?? 'Unknown') + ' want to initiate a transfer.' });
if (cm.state === "Disconnected") {
this.toDelete.push({
id: cm.id,
triggered: new Date().getTime()
});
}
// Push the new message if not found
this.requests.push(cm);
}
})
await listen('rs2js_discovery', (event) => {
const ei = event.payload as EndpointInfo;
console.log("rs2js:", ei);
const idx = this.endpointsInfo.findIndex((el) => el.id === ei.id);
if (!ei.present) {
if (idx !== -1) {
this.endpointsInfo.splice(idx, 1);
const prev = this.requests.at(idx);
// Update the existing message at index 'idx'
this.requests.splice(idx, 1, {
...cm,
state: cm.state ?? prev!.state,
meta: cm.meta ?? prev!.meta,
});
} else {
if (this.isAppInForeground && permissionGranted && cm.state === 'WaitingForUserConsent') {
sendNotification({ title: 'RQuickShare', body: (cm.meta?.source?.name ?? 'Unknown') + ' want to initiate a transfer' });
}
// Push the new message if not found
this.requests.push(cm);
}
})
);
return;
}
this.unlisten.push(
await listen('rs2js_discovery', (event) => {
const ei = event.payload as EndpointInfo;
console.log("rs2js:", ei);
if (idx !== -1) {
this.endpointsInfo.splice(idx, 1, ei);
} else {
this.endpointsInfo.push(ei);
}
});
const idx = this.endpointsInfo.findIndex((el) => el.id === ei.id);
if (!ei.present) {
if (idx !== -1) {
this.endpointsInfo.splice(idx, 1);
}
await appWindow.onFileDropEvent(async (event) => {
if (event.payload.type === 'hover') {
this.isDragHovering = true;
} else if (event.payload.type === 'drop') {
console.log("Dropped");
this.isDragHovering = false;
this.outboundPayload = {
Files: event.payload.paths
} as OutboundPayload;
if (!this.discoveryRunning) await invoke('start_discovery');
this.discoveryRunning = true;
} else {
this.isDragHovering = false;
}
});
return;
}
if (idx !== -1) {
this.endpointsInfo.splice(idx, 1, ei);
} else {
this.endpointsInfo.push(ei);
}
})
);
this.unlisten.push(
await appWindow.onFileDropEvent(async (event) => {
if (event.payload.type === 'hover') {
this.isDragHovering = true;
} else if (event.payload.type === 'drop') {
console.log("Dropped");
this.isDragHovering = false;
this.outboundPayload = {
Files: event.payload.paths
} as OutboundPayload;
if (!this.discoveryRunning) await invoke('start_discovery');
this.discoveryRunning = true;
} else {
this.isDragHovering = false;
}
})
);
});
},
unmounted: function() {
window.removeEventListener('focus', this._handleFocus);
window.removeEventListener('blur', this._handleBlur);
this.unlisten.forEach((el) => el());
if (this.cleanupInterval && this.cleanupInterval[Symbol.dispose]) {
this.cleanupInterval[Symbol.dispose]();
}
Expand Down Expand Up @@ -509,10 +510,12 @@ export default {
await invoke('js2rs', { message: cm });
},
_handleFocus: function() {
this.isAppInForeground = true;
this.isAppInForeground = false;
console.log("isAppInForeground: false");
},
_handleBlur: function() {
this.isAppInForeground = false;
this.isAppInForeground = true;
console.log("isAppInForeground: true");
}
},
}
Expand Down

0 comments on commit a6f52b4

Please sign in to comment.