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: support Windows hello #5917

Merged
merged 26 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
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
5 changes: 3 additions & 2 deletions apps/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"clean": "rimraf ./build-electron && rimraf .tamagui && rimraf ./build && rimraf ./dist && rimraf __generated__",
"clean:build": "rimraf ./build-electron && rimraf ./build && rimraf ./dist && rimraf ./node_modules/.cache",
"start": "yarn dev",
"dev": "yarn keytar && npx concurrently \"yarn dev:main\" \"yarn dev:renderer\" \"cross-env LAUNCH_ELECTRON=true node scripts/dev.js\"",
"dev": "yarn keytar && npx concurrently \"yarn build:main\" \"yarn dev:renderer\" \"cross-env LAUNCH_ELECTRON=true node scripts/dev.js\"",
huhuanming marked this conversation as resolved.
Show resolved Hide resolved
"dev:main": "electron --inspect=5858 dist/app.js",
"dev:renderer": "TRANSFORM_REGENERATOR_DISABLED=true BROWSER=none WEB_PORT=3001 webpack serve",
"build:main": "rimraf ./dist && cross-env NODE_ENV=production node scripts/build.js",
Expand Down Expand Up @@ -40,7 +40,8 @@
"electron-store": "^8.2.0",
"electron-updater": "6.1.8",
"keytar": "^7.9.0",
"node-fetch": "^2.6.7"
"node-fetch": "^2.6.7",
"windows.security.credentials.ui": "git+https://github.com/huhuanming/windows.security.credentials.ui#91c3534a1b520ea1a78319e63ba2d84b19c37e78"
huhuanming marked this conversation as resolved.
Show resolved Hide resolved
},
"devDependencies": {
"@electron/notarize": "^2.3.0",
Expand Down
39 changes: 38 additions & 1 deletion apps/desktop/src-electron/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
import contextMenu from 'electron-context-menu';
import isDev from 'electron-is-dev';
import logger from 'electron-log/main';
import windowsSecurityCredentialsUiModule, {
UserConsentVerificationResult,
UserConsentVerifierAvailability,
} from 'windows.security.credentials.ui';
huhuanming marked this conversation as resolved.
Show resolved Hide resolved

import {
ONEKEY_APP_DEEP_LINK_NAME,
Expand All @@ -28,7 +32,7 @@
IDesktopAppState,
IDesktopSubModuleInitParams,
IMediaType,
IPrefType,

Check warning on line 35 in apps/desktop/src-electron/app.ts

View workflow job for this annotation

GitHub Actions / lint (20.x)

'IPrefType' is defined but never used
} from '@onekeyhq/shared/types/desktop';

import appDevOnlyApi from './appDevOnlyApi';
Expand Down Expand Up @@ -511,7 +515,22 @@
}
});

ipcMain.on(ipcMessageKeys.TOUCH_ID_CAN_PROMPT, (event) => {
ipcMain.on(ipcMessageKeys.TOUCH_ID_CAN_PROMPT, async (event) => {
if (isWin) {
const result = await new Promise((resolve) => {
windowsSecurityCredentialsUiModule.UserConsentVerifier.checkAvailabilityAsync(
(error, status) => {
if (error) {
resolve(false);
} else {
resolve(status === UserConsentVerifierAvailability.available);
}
},
);
});
event.returnValue = result;
return;
}
huhuanming marked this conversation as resolved.
Show resolved Hide resolved
const result = systemPreferences?.canPromptTouchID?.();
event.returnValue = !!result;
});
Expand Down Expand Up @@ -555,6 +574,24 @@
});

ipcMain.on(ipcMessageKeys.TOUCH_ID_PROMPT, async (event, msg: string) => {
if (isWin) {
windowsSecurityCredentialsUiModule.UserConsentVerifier.requestVerificationAsync(
msg,
(error, status) => {
if (error) {
event.reply(ipcMessageKeys.TOUCH_ID_PROMPT_RES, {
huhuanming marked this conversation as resolved.
Show resolved Hide resolved
success: false,
error: error.message,
});
} else {
event.reply(ipcMessageKeys.TOUCH_ID_PROMPT_RES, {
success: status === UserConsentVerificationResult.verified,
});
}
},
);
return;
}
huhuanming marked this conversation as resolved.
Show resolved Hide resolved
try {
await systemPreferences.promptTouchID(msg);
event.reply(ipcMessageKeys.TOUCH_ID_PROMPT_RES, { success: true });
Expand Down
19 changes: 19 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6695,6 +6695,7 @@ __metadata:
node-fetch: "npm:^2.6.7"
rimraf: "npm:^3"
webpack: "npm:5.90.3"
windows.security.credentials.ui: "git+https://github.com/huhuanming/windows.security.credentials.ui#91c3534a1b520ea1a78319e63ba2d84b19c37e78"
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -28675,6 +28676,15 @@ __metadata:
languageName: node
linkType: hard

"nan@npm:latest":
version: 2.20.0
resolution: "nan@npm:2.20.0"
dependencies:
node-gyp: "npm:latest"
checksum: 10/5f16e4c9953075d9920229c703c1d781c0b74118ce3d9e926b448a4eef92b7d8be5ac6adc748a13a5fafb594436cbfe63250e3471aefdd78e3a0cd14603b9ba7
languageName: node
linkType: hard

"nano-json-stream-parser@npm:^0.1.2":
version: 0.1.2
resolution: "nano-json-stream-parser@npm:0.1.2"
Expand Down Expand Up @@ -38221,6 +38231,15 @@ __metadata:
languageName: node
linkType: hard

"windows.security.credentials.ui@git+https://github.com/huhuanming/windows.security.credentials.ui#91c3534a1b520ea1a78319e63ba2d84b19c37e78":
version: 0.1.7
resolution: "windows.security.credentials.ui@https://github.com/huhuanming/windows.security.credentials.ui.git#commit=91c3534a1b520ea1a78319e63ba2d84b19c37e78"
dependencies:
nan: "npm:latest"
checksum: 10/d6c487953945337dd3f432222e5320b2ae6ad8b3e10d3246b261a11fd84e427297cd22a72b61ffcea36179fd5944b42b10a4aa4bdb01aa87e63844fb467a4e20
languageName: node
linkType: hard

"wonka@npm:^4.0.14":
version: 4.0.15
resolution: "wonka@npm:4.0.15"
Expand Down
Loading