From 2af4c6c5a39e3f58533127dae3a5cae6fd732686 Mon Sep 17 00:00:00 2001 From: jeasonnow Date: Sun, 25 Jun 2023 10:24:57 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E8=B0=83=E6=95=B4=E6=B3=A8?= =?UTF-8?q?=E5=85=A5=E8=83=BD=E5=8A=9B=E9=80=82=E9=85=8D=E6=96=B0=20cli?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/helpers/merge.ts | 19 ++++++++++++++++++- bin/{helpers => utils}/combine.ts | 0 2 files changed, 18 insertions(+), 1 deletion(-) rename bin/{helpers => utils}/combine.ts (100%) diff --git a/bin/helpers/merge.ts b/bin/helpers/merge.ts index d4095a3..f3794e7 100644 --- a/bin/helpers/merge.ts +++ b/bin/helpers/merge.ts @@ -2,6 +2,7 @@ import path from 'path'; import fsExtra from 'fs-extra'; import { npmDirectory } from '@/utils/dir'; +import combineFiles from '@/utils/combine'; import logger from '@/options/logger'; import { PakeAppOptions, PlatformMap } from '@/types'; @@ -19,6 +20,7 @@ export async function mergeConfig(url: string, options: PakeAppOptions, tauriCon identifier, name, resizable = true, + inject, } = options; const { platform } = process; @@ -68,7 +70,11 @@ export async function mergeConfig(url: string, options: PakeAppOptions, tauriCon } else { tauriConf.pake.windows[0].url_type = 'web'; // Set the secure domain for calling window.__TAURI__ to the application domain that has been set. - tauriConf.tauri.security.dangerousRemoteDomainIpcAccess[0].domain = new URL(url).hostname; + tauriConf.tauri.security.dangerousRemoteDomainIpcAccess = [{ + domain: new URL(url).hostname, + windows: ["pake"], + enableTauriAPI: true, + }]; } const platformMap: PlatformMap = { @@ -172,6 +178,17 @@ export async function mergeConfig(url: string, options: PakeAppOptions, tauriCon tauriConf.tauri.systemTray.iconPath = trayIconPath; + // inject js or css files + if (inject?.length > 0) { + if (!inject.every(item => item.endsWith('.css') || item.endsWith('.js'))) { + logger.error("The injected file must be in either CSS or JS format."); + return; + } + const files = inject.map(relativePath => path.join(process.cwd(), relativePath)); + tauriConf.pake.inject = files; + combineFiles(files); + } + // Save config file. const platformConfigPaths: PlatformMap = { win32: 'src-tauri/tauri.windows.conf.json', diff --git a/bin/helpers/combine.ts b/bin/utils/combine.ts similarity index 100% rename from bin/helpers/combine.ts rename to bin/utils/combine.ts