-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(win32-api): winspool.EnumPrintersW(), winspoolEnumPrinters()
- Loading branch information
1 parent
256e7a9
commit e7c1e01
Showing
10 changed files
with
155 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
|
||
export * from './user32/index.user32.js' | ||
export * from './winspool/index.winspool.js' | ||
export * from './winspool/winspool.types.js' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { M } from './helper.js' | ||
|
||
|
||
export interface EnumPrintersOptions<Lvl extends M.EnumPrinters_Level> { | ||
/** | ||
* PrinterEnumFlags | ||
* @see https://docs.microsoft.com/en-us/windows/win32/printdocs/printer-enum-flags | ||
*/ | ||
Flags: number | ||
Name?: string | ||
// Level: M.EnumPrinters_Level | ||
Level: Lvl | ||
/** | ||
* @default 4096 | ||
*/ | ||
cbBuf?: number | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 0 additions & 9 deletions
9
packages/win32-api/test/winspool/501.GetDefaultPrinter.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import assert from 'node:assert/strict' | ||
|
||
import { fileShortPath } from '@waiting/shared-core' | ||
import { PrinterEnumFlags } from 'win32-def/consts' | ||
|
||
import { | ||
winspoolOpenPrinter, | ||
winspoolEnumPrinters, | ||
EnumPrintersOptions, | ||
} from '../../src/index.fun.js' | ||
import { | ||
DModel as M, | ||
DTypes as W, | ||
DStruct as DS, | ||
StructFactory, | ||
} from '../../src/index.js' | ||
import { githubPrinterNames } from '../config.unittest.js' | ||
import { CI } from '../root.config.js' | ||
|
||
|
||
describe(fileShortPath(import.meta.url), () => { | ||
|
||
describe('Should winspoolEnumPrinters() work', () => { | ||
it('normal', async () => { | ||
const ret = await winspoolEnumPrinters({ | ||
Flags: PrinterEnumFlags.PRINTER_ENUM_LOCAL, | ||
Level: 4, | ||
}) | ||
assertsPInfo(ret, true) | ||
}) | ||
|
||
it('options<4>', async () => { | ||
const opts: EnumPrintersOptions<4> = { | ||
Flags: PrinterEnumFlags.PRINTER_ENUM_LOCAL, | ||
Level: 4, | ||
} | ||
const ret = await winspoolEnumPrinters(opts) | ||
assertsPInfo(ret, false) | ||
}) | ||
|
||
it('options as const', async () => { | ||
const opts = { | ||
Flags: PrinterEnumFlags.PRINTER_ENUM_LOCAL, | ||
Level: 4, | ||
} as const // <-- `as const` | ||
const ret = await winspoolEnumPrinters(opts) | ||
assertsPInfo(ret, false) | ||
}) | ||
|
||
}) | ||
}) | ||
|
||
|
||
function assertsPInfo(infos: M.PRINTER_INFO_X[4][], verbose: boolean): void { | ||
assert(infos.length) | ||
|
||
infos.forEach((info, idx) => { | ||
assert(info) | ||
const { pPrinterName, pServerName, Attributes } = info | ||
assert(info.pPrinterName) | ||
verbose && console.log({ | ||
idx, | ||
pPrinterName, | ||
pServerName, | ||
Attributes, | ||
}) | ||
if (CI) { | ||
githubPrinterNames.includes(pPrinterName) | ||
} | ||
}) | ||
} | ||
|