feat: match different length of mac

This commit is contained in:
2024-08-02 16:30:46 +08:00
parent ff240ae44c
commit c9f559a8ea
9 changed files with 1353 additions and 1658 deletions

View File

@@ -1 +1 @@
8857565900ea1a36112664798db58d03
066112e6c557bd6b8c986b4fd27a4b3f

2899
frontend/pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -29,6 +29,36 @@ import Download from './Download'
import { Separator } from '@/components/ui/separator'
import { Loader2 } from 'lucide-react'
interface MacAddress {
Prefix: string
VendorName: string
IsPrivate: boolean
BlockType: string
LastUpdate: string
}
const addColons = (hexString: string): string => {
// Check if the input string is valid
if (!/^[A-F0-9]{6,12}$/.test(hexString)) {
return ''
}
// Initialize the result array
const result: string[] = []
// Loop through the string and add colons every two characters
for (let i = 0; i < hexString.length; i += 2) {
if (i + 2 < hexString.length) {
result.push(hexString.substring(i, i + 2))
} else {
result.push(hexString.substring(i))
}
}
// Join the result array with colons
return result.join(':')
}
const Panel: React.FC = () => {
const [macInputDisabled, setMacInputDisabled] = useState(false)
@@ -97,9 +127,8 @@ const Panel: React.FC = () => {
if (address.length < 6) {
return
}
address =
address.substring(0, 2) + ':' + address.substring(2, 4) + ':' + address.substring(4, 6)
QueryMacAddressByPrefix(address).then(res => {
address = addColons(address)
QueryMacAddressByPrefix(address).then((res: any) => {
if (res === null) {
setPrefix('Not Found')
setVendorName('')

View File

@@ -0,0 +1,17 @@
export namespace service {
export class MacAddress {
static createFrom(source: any = {}) {
return new MacAddress(source);
}
constructor(source: any = {}) {
if ('string' === typeof source) source = JSON.parse(source);
}
}
}

View File

@@ -233,3 +233,17 @@ export function ClipboardGetText(): Promise<string>;
// [ClipboardSetText](https://wails.io/docs/reference/runtime/clipboard#clipboardsettext)
// Sets a text on the clipboard
export function ClipboardSetText(text: string): Promise<boolean>;
// [OnFileDrop](https://wails.io/docs/reference/runtime/draganddrop#onfiledrop)
// OnFileDrop listens to drag and drop events and calls the callback with the coordinates of the drop and an array of path strings.
export function OnFileDrop(callback: (x: number, y: number ,paths: string[]) => void, useDropTarget: boolean) :void
// [OnFileDropOff](https://wails.io/docs/reference/runtime/draganddrop#dragandddropoff)
// OnFileDropOff removes the drag and drop listeners and handlers.
export function OnFileDropOff() :void
// Check if the file path resolver is available
export function CanResolveFilePaths(): boolean;
// Resolves file paths for an array of files
export function ResolveFilePaths(files: File[]): void

View File

@@ -199,4 +199,40 @@ export function ClipboardGetText() {
export function ClipboardSetText(text) {
return window.runtime.ClipboardSetText(text);
}
/**
* Callback for OnFileDrop returns a slice of file path strings when a drop is finished.
*
* @export
* @callback OnFileDropCallback
* @param {number} x - x coordinate of the drop
* @param {number} y - y coordinate of the drop
* @param {string[]} paths - A list of file paths.
*/
/**
* OnFileDrop listens to drag and drop events and calls the callback with the coordinates of the drop and an array of path strings.
*
* @export
* @param {OnFileDropCallback} callback - Callback for OnFileDrop returns a slice of file path strings when a drop is finished.
* @param {boolean} [useDropTarget=true] - Only call the callback when the drop finished on an element that has the drop target style. (--wails-drop-target)
*/
export function OnFileDrop(callback, useDropTarget) {
return window.runtime.OnFileDrop(callback, useDropTarget);
}
/**
* OnFileDropOff removes the drag and drop listeners and handlers.
*/
export function OnFileDropOff() {
return window.runtime.OnFileDropOff();
}
export function CanResolveFilePaths() {
return window.runtime.CanResolveFilePaths();
}
export function ResolveFilePaths(files) {
return window.runtime.ResolveFilePaths(files);
}