Skip to content
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
20 changes: 20 additions & 0 deletions .github/workflows/build-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,26 @@ jobs:
- name: Enable code signing only for current repo
if: github.event.pull_request.head.repo.full_name == github.repository
run: echo "CSC_FOR_PULL_REQUEST=true" >> $GITHUB_ENV

- name: Set dev version
run: |
echo "Creating patch-version.js"
cat << 'EOF' > patch-version.js
const fs = require('fs');
const pkg = require('./package.json');
const sha = process.env.COMMIT_SHA.slice(0, 7);
const pr = process.env.PR_NUMBER;
const baseVersion = pkg.version.replace(/-dev.*$/, '');
pkg.version = `${baseVersion}-dev.pr${pr}.${sha}`;
fs.writeFileSync('package.json', JSON.stringify(pkg, null, 2));
console.log("Updated version:", pkg.version);
EOF
node patch-version.js
shell: bash
env:
GITHUB_SHA: ${{ github.sha }}
PR_NUMBER: ${{ github.event.pull_request.number }}
COMMIT_SHA: ${{ github.event.pull_request.head.sha }}

- name: Build/release Electron app
uses: samuelmeuli/action-electron-builder@v1
Expand Down
152 changes: 41 additions & 111 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"@nethesis/nethesis-brands-svg-icons": "github:nethesis/Font-Awesome#ns-brands",
"@nethesis/nethesis-light-svg-icons": "github:nethesis/Font-Awesome#ns-light",
"@nethesis/nethesis-solid-svg-icons": "github:nethesis/Font-Awesome#ns-solid",
"@nethesis/phone-island": "^0.13.6",
"@nethesis/phone-island": "^0.14.0",
"@tailwindcss/forms": "^0.5.7",
"@types/lodash": "^4.14.202",
"@types/node": "^18.19.9",
Expand Down
47 changes: 33 additions & 14 deletions src/renderer/src/components/ElectronDraggableWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const ElectronDraggableWindow = ({ children }) => {
const mouseDownEvent = useRef<MouseEvent | null>(null)
const mouseUpEvent = useRef<MouseEvent | null>(null)
const target = useRef<EventTarget | null>(null)
const lastMouseDownTime = useRef<number>(0)

const handleMouseClick = (e: MouseEvent) => {
if (e['pointerId'] !== -1) {
Expand All @@ -28,6 +29,12 @@ export const ElectronDraggableWindow = ({ children }) => {
};

const handleMouseDown = (e: MouseEvent) => {
const now = Date.now();
if (now - lastMouseDownTime.current < 100) {
return;
}
lastMouseDownTime.current = now;

if (!isDrag.current && !mouseDownEvent.current) {
target.current = e.target
passthroughEvent.current = false
Expand All @@ -45,16 +52,28 @@ export const ElectronDraggableWindow = ({ children }) => {
mouseUpEvent.current = e
};

const handleMouseLeave = () => {
if (isDrag.current) {
window.electron.send(IPC_EVENTS.STOP_DRAG);
isDrag.current = false;
mouseDownEvent.current = null;
}
};

const handleWindowBlur = () => {
if (isDrag.current) {
isDrag.current = false;
mouseDownEvent.current = null;
window.electron.send(IPC_EVENTS.STOP_DRAG);
}
};

useEffect(() => {
document.addEventListener('click', handleMouseClick, {
capture: true,
});
document.addEventListener('mousedown', handleMouseDown, {
capture: true,
});
document.addEventListener('mouseup', handleMouseUp, {
capture: true,
});
document.addEventListener('click', handleMouseClick, { capture: true });
document.addEventListener('mousedown', handleMouseDown, { capture: true });
document.addEventListener('mouseup', handleMouseUp, { capture: true });
window.addEventListener('mouseleave', handleMouseLeave);
window.addEventListener('blur', handleWindowBlur);

window.electron.receive(IPC_EVENTS.ENABLE_CLICK, () => {
if (target.current && !passthroughEvent.current) {
Expand All @@ -64,18 +83,19 @@ export const ElectronDraggableWindow = ({ children }) => {
cancelable: true,
view: window,
});
//we create an untrusted event, with this property we ensure that this event was created by us
newEvent['nethlink'] = true
target.current.dispatchEvent(newEvent);
}
})
});

return () => {
document.removeEventListener('click', handleMouseClick);
document.removeEventListener('mousedown', handleMouseDown);
document.removeEventListener('mouseup', handleMouseUp);
window.removeEventListener('mouseleave', handleMouseLeave);
window.removeEventListener('blur', handleWindowBlur);
};
}, [handleMouseUp]);
}, []);

return (
<div
Expand All @@ -84,5 +104,4 @@ export const ElectronDraggableWindow = ({ children }) => {
{children}
</div>
);
};

};