fix(windows): restore Office document entries in Explorer New menu (#491)
* fix(windows): restore Office document entries in Explorer New menu * fix(html2docx): narrow screenshot IDs for strict typechecking --------- Co-authored-by: merrick-2002 <merrick@mainfunc.ai>
This commit is contained in:
@@ -11,14 +11,40 @@
|
||||
|
||||
!define GENOFFICE_PATH_MAX 7900
|
||||
|
||||
; Scope templates to our ProgIDs (electron-builder uses fileAssociations.name).
|
||||
; A shared .ext\ShellNew would overwrite Office/WPS templates. OOXML files
|
||||
; must be copied from valid packages, never created with NullFile.
|
||||
!macro GenOfficeRegisterShellNew EXT PROGID
|
||||
WriteRegStr SHELL_CONTEXT "Software\Classes\.${EXT}\${PROGID}\ShellNew" "FileName" "$INSTDIR\resources\shell-new\blank.${EXT}"
|
||||
!macroend
|
||||
|
||||
!macro GenOfficeUnregisterShellNew EXT PROGID
|
||||
; Only remove our own registration, including when uninstalling for an update.
|
||||
ReadRegStr $0 SHELL_CONTEXT "Software\Classes\.${EXT}\${PROGID}\ShellNew" "FileName"
|
||||
${If} $0 == "$INSTDIR\resources\shell-new\blank.${EXT}"
|
||||
DeleteRegKey SHELL_CONTEXT "Software\Classes\.${EXT}\${PROGID}\ShellNew"
|
||||
DeleteRegKey /ifempty SHELL_CONTEXT "Software\Classes\.${EXT}\${PROGID}"
|
||||
${EndIf}
|
||||
!macroend
|
||||
|
||||
!macro customInstall
|
||||
Push "$INSTDIR\resources\cli"
|
||||
Call GenOfficeAddToUserPath
|
||||
!insertmacro GenOfficeRegisterShellNew "docx" "Word Document"
|
||||
!insertmacro GenOfficeRegisterShellNew "xlsx" "Excel Workbook"
|
||||
!insertmacro GenOfficeRegisterShellNew "pptx" "PowerPoint Presentation"
|
||||
!insertmacro UPDATEFILEASSOC
|
||||
!macroend
|
||||
|
||||
!macro customUnInstall
|
||||
Push "$INSTDIR\resources\cli"
|
||||
Call un.GenOfficeRemoveFromUserPath
|
||||
Push $0
|
||||
!insertmacro GenOfficeUnregisterShellNew "docx" "Word Document"
|
||||
!insertmacro GenOfficeUnregisterShellNew "xlsx" "Excel Workbook"
|
||||
!insertmacro GenOfficeUnregisterShellNew "pptx" "PowerPoint Presentation"
|
||||
Pop $0
|
||||
!insertmacro UPDATEFILEASSOC
|
||||
!macroend
|
||||
|
||||
!ifndef BUILD_UNINSTALLER
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -356,6 +356,7 @@ const config = {
|
||||
{
|
||||
ext: 'docx',
|
||||
name: 'Word Document',
|
||||
description: 'Word Document',
|
||||
role: 'Editor',
|
||||
icon: 'docx',
|
||||
mimeType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||
@@ -363,6 +364,7 @@ const config = {
|
||||
{
|
||||
ext: 'xlsx',
|
||||
name: 'Excel Workbook',
|
||||
description: 'Excel Workbook',
|
||||
role: 'Editor',
|
||||
icon: 'xlsx',
|
||||
mimeType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||
@@ -377,6 +379,7 @@ const config = {
|
||||
{
|
||||
ext: 'pptx',
|
||||
name: 'PowerPoint Presentation',
|
||||
description: 'PowerPoint Presentation',
|
||||
role: 'Editor',
|
||||
icon: 'pptx',
|
||||
mimeType: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
||||
@@ -469,6 +472,11 @@ const config = {
|
||||
from: WIN_SIDECAR,
|
||||
to: 'native/xlsx-sidecar.exe',
|
||||
},
|
||||
{
|
||||
from: 'build/shell-new',
|
||||
to: 'shell-new',
|
||||
filter: ['*.docx', '*.xlsx', '*.pptx'],
|
||||
},
|
||||
],
|
||||
},
|
||||
// Unlike win (which cross-compiles the sidecar to an explicit target
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { createRequire } from 'node:module'
|
||||
import { resolve } from 'node:path'
|
||||
import { runInNewContext } from 'node:vm'
|
||||
import JSZip from 'jszip'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { parseDocx } from '@genoffice/docx-engine'
|
||||
import { openPptx } from '@genoffice/pptx-engine'
|
||||
|
||||
const require = createRequire(import.meta.url)
|
||||
// Inspect packaging metadata without downloading Electron or compiling OCR helpers.
|
||||
// Template files themselves are read from disk below.
|
||||
const configModule = { exports: {} as ReturnType<typeof require> }
|
||||
runInNewContext(readFileSync(resolve(import.meta.dirname, '../electron-builder.cjs'), 'utf8'), {
|
||||
module: configModule,
|
||||
__dirname: resolve(import.meta.dirname, '..'),
|
||||
process: { platform: 'linux', arch: 'x64', env: {} },
|
||||
require: (id: string) =>
|
||||
id === 'node:fs' ? { ...require(id), existsSync: () => true } : require(id),
|
||||
})
|
||||
const config = configModule.exports
|
||||
|
||||
function template(ext: string): Buffer {
|
||||
const resource = config.win.extraResources.find(
|
||||
(entry: { to: string }) => entry.to === 'shell-new',
|
||||
)
|
||||
expect(resource, 'Windows package must ship the Explorer templates').toBeDefined()
|
||||
return readFileSync(resolve(import.meta.dirname, '..', resource.from, `blank.${ext}`))
|
||||
}
|
||||
|
||||
describe('Windows Explorer New templates', () => {
|
||||
it('opens the packaged Word template as one empty paragraph', async () => {
|
||||
const doc = await parseDocx(template('docx'))
|
||||
const visible = doc.blocks.filter((block) => !block.hidden)
|
||||
expect(visible).toHaveLength(1)
|
||||
expect(visible[0].type).toBe('paragraph')
|
||||
expect(doc.styles.has('Heading1')).toBe(true)
|
||||
})
|
||||
|
||||
it('ships an Excel workbook with one empty worksheet', async () => {
|
||||
const zip = await JSZip.loadAsync(template('xlsx'), { checkCRC32: true })
|
||||
const workbook = await zip.file('xl/workbook.xml')!.async('string')
|
||||
expect(workbook.match(/<sheet\s/g)).toHaveLength(1)
|
||||
const sheet = await zip.file('xl/worksheets/sheet1.xml')!.async('string')
|
||||
expect(sheet).toMatch(/<sheetData\s*\/>|<sheetData>\s*<\/sheetData>/)
|
||||
expect(await zip.file('_rels/.rels')!.async('string')).toContain('xl/workbook.xml')
|
||||
})
|
||||
|
||||
it('opens the packaged PowerPoint template as one empty slide', async () => {
|
||||
const opened = await openPptx(template('pptx'))
|
||||
expect(opened.deck.slides).toHaveLength(1)
|
||||
expect(opened.deck.slides[0].elements).toHaveLength(0)
|
||||
})
|
||||
|
||||
it('provides nonempty Windows file type labels for the New menu', () => {
|
||||
for (const ext of ['docx', 'xlsx', 'pptx']) {
|
||||
const association = config.fileAssociations.find(
|
||||
(entry: { ext: string }) => entry.ext === ext,
|
||||
)
|
||||
expect(association.description).toBe(association.name)
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,29 @@
|
||||
/** Regenerate the checked-in Windows Explorer templates: npx tsx tools/gen-shell-new-templates.ts */
|
||||
import { mkdir, writeFile } from 'node:fs/promises'
|
||||
import JSZip from 'jszip'
|
||||
import { buildBlankDocx } from '../packages/docx-engine/src/blank'
|
||||
import { createBlankPptx } from '../packages/pptx-engine/src/blank'
|
||||
import { blankXlsxBuffer } from '../packages/xlsx-gateway/src/gateway/csv-import'
|
||||
|
||||
async function main() {
|
||||
const output = new URL('../apps/shell/build/shell-new/', import.meta.url)
|
||||
await mkdir(output, { recursive: true })
|
||||
const templates = {
|
||||
docx: await buildBlankDocx(),
|
||||
xlsx: await blankXlsxBuffer(),
|
||||
pptx: await createBlankPptx(),
|
||||
}
|
||||
for (const [ext, bytes] of Object.entries(templates)) {
|
||||
const zip = await JSZip.loadAsync(bytes)
|
||||
// Keep regeneration deterministic when only the ZIP timestamps differ.
|
||||
zip.forEach((_, entry) => {
|
||||
entry.date = new Date('2000-01-01T00:00:00Z')
|
||||
})
|
||||
await writeFile(
|
||||
new URL(`blank.${ext}`, output),
|
||||
await zip.generateAsync({ type: 'nodebuffer', compression: 'DEFLATE' }),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
void main()
|
||||
Reference in New Issue
Block a user