We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
正常情况下,electron-builder 默认是不会将 font-list 打包的,所以导致无法使用,通过 extraResources 执行处理即可,下面为使用步骤:
electron-builder
font-list
extraResources
package.json
"extraResources": [ "./extraResources/**" ],
extraResources/fontlist
node_modules/font-list
extraResources └─fontlist ├─getSystemFonts.js ├─index.d.ts ├─index.js └─libs ├─darwin ├─linux └─win32
getSystemFonts.js
const { getFonts } = require('./index'); function getSystemFonts() { return new Promise((resolve, reject) => { getFonts({ disableQuoting: true }) .then((fonts) => { fonts = [...new Set(fonts)]; resolve(fonts || []); }) .catch((err) => { resolve([]); }); }); } (async () => { const fonts = await getSystemFonts(); // process 处理 process.send(fonts); // console.log('fonts', fonts); })();
main.ts
getSystemFonts
import path from 'path'; import cp from 'child_process'; const EXTRARESOURCES_PATH = app.isPackaged ? path.join(process.resourcesPath, 'extraResources') : path.join(__dirname, '../../extraResources'); const getExtraResourcesPath = (...paths: string[]): string => { return path.join(EXTRARESOURCES_PATH, ...paths); }; // ... ipcMain.on('getSystemFonts', async () => { const systemFontsScriptPath = getExtraResourcesPath('fontlist/getSystemFonts.js') let fonts: string[] = []; const forked = cp.fork(systemFontsScriptPath); forked.on('message', function (message: string[]) { fonts = message; mainWindow?.webContents.send('getSystemFontsCb', fonts); }); });
utils/common.ts
import { ipcRenderer } from "electron"; export const systemFonts: string[] = []; // 获取系统字体列表 ipcRenderer.send('getSystemFonts'); ipcRenderer.on('getSystemFontsCb', (e, fonts: string[] = []) => { // console.log('fonts', fonts); systemFonts = fonts; });
import { systemFonts } from "utils/common"; console.log('systemFonts', systemFonts) // [ 'Arial', 'Bahnschrift', 'Book Antiqua']
具体commit源码 Beats0/bilive-danmaku@0f3f450
The text was updated successfully, but these errors were encountered:
嗯,我也是手动拷贝了一份,放到一个文件夹里。但是,这只是个workaround
extraResources: [ 'bin/*', ],
Sorry, something went wrong.
No branches or pull requests
正常情况下,
electron-builder
默认是不会将font-list
打包的,所以导致无法使用,通过extraResources
执行处理即可,下面为使用步骤:package.json
中添加extraResources/fontlist
文件夹,将node_modules/font-list
下的文件源码复制到extraResources
下getSystemFonts.js
中为main.ts
中添加触发事件getSystemFonts
utils/common.ts
为例子触发事件具体commit源码 Beats0/bilive-danmaku@0f3f450
The text was updated successfully, but these errors were encountered: