+
{{ name }}
@@ -10,7 +10,7 @@ const { name } = defineProps<{
\ No newline at end of file
diff --git a/app-views/src/pages/demo/download.vue b/app-views/src/pages/demo/download.vue
index 251c105..c89787f 100644
--- a/app-views/src/pages/demo/download.vue
+++ b/app-views/src/pages/demo/download.vue
@@ -46,16 +46,16 @@ const taskList = ref
([]);
function download(link: string) {
- window.ipc.send('download-create', link);
+ window.ipc?.send('download-create', link);
}
function downloadTogglePause(item: IDownloadItem) {
if (item.isPause) {
console.log('继续下载')
- window.ipc.send('download-create', item.url);
+ window.ipc?.send('download-create', item.url);
} else {
console.log('暂停下载')
- window.ipc.send('download-pause', item.url);
+ window.ipc?.send('download-pause', item.url);
}
}
@@ -71,16 +71,16 @@ function onDownloadProgress(_: any, item: IDownloadItem) {
}
}
-window.ipc.on('download-update', onDownloadUpdate);
-window.ipc.on('download-progress', onDownloadProgress)
+window.ipc?.on('download-update', onDownloadUpdate);
+window.ipc?.on('download-progress', onDownloadProgress)
onUnmounted(() => {
- window.ipc.off('download-update', onDownloadUpdate);
- window.ipc.off('download-progress', onDownloadProgress)
+ window.ipc?.off('download-update', onDownloadUpdate);
+ window.ipc?.off('download-progress', onDownloadProgress)
})
function downloadAndReadHash() {
- window.ipc.send('start-write-hash');
+ window.ipc?.send('start-write-hash');
}
diff --git a/app-views/src/pages/demo/open-window.vue b/app-views/src/pages/demo/open-window.vue
index 33885cf..3975bc0 100644
--- a/app-views/src/pages/demo/open-window.vue
+++ b/app-views/src/pages/demo/open-window.vue
@@ -5,11 +5,11 @@ const isPackaged = ref(false);
function openChildWin() {
- window.ipc.send('open-child-win')
+ window.ipc?.send('open-child-win')
}
async function winOpen() {
- const url = await window.ipc.invoke('get-window-url');
+ const url = await window.ipc?.invoke('get-window-url');
console.log(url);
window.open(url, '子窗口')
}
@@ -21,14 +21,14 @@ function winOpenOnline() {
onMounted(async () => {
window.addEventListener('contextmenu', (e) => {
e.preventDefault();
- window.ipc.send('show-context-menu');
+ window.ipc?.send('show-context-menu');
});
- window.ipc.on('context-menu-command', (e, command) => {
+ window.ipc?.on('context-menu-command', (e, command) => {
console.log(e, command);
});
- isPackaged.value = await window.ipc.invoke('app-is-packaged')
+ isPackaged.value = await window.ipc?.invoke('app-is-packaged')
})
diff --git a/app-views/src/route.ts b/app-views/src/route.ts
index 809d254..628136a 100644
--- a/app-views/src/route.ts
+++ b/app-views/src/route.ts
@@ -1,50 +1,58 @@
-import { createRouter, createWebHashHistory } from 'vue-router';
-import type { RouteRecordRaw } from 'vue-router';
+import { createRouter, createWebHashHistory } from "vue-router";
+import type { RouteRecordRaw } from "vue-router";
export const routes: RouteRecordRaw[] = [
- {
- path: '/',
- name: 'home',
- redirect: '/demo/download',
- meta: {
- hideInNav: true,
- },
+ {
+ path: "/",
+ name: "home",
+ redirect: "/creator",
+ meta: {
+ hideInNav: true,
},
- {
- path: '/demo/',
- component: () => import('./pages/demo/index.vue'),
- meta: {
- title: '操练场',
- },
- children: [
- {
- path: 'download',
- name: 'download',
- component: () => import('./pages/demo/download.vue'),
- },
- {
- path: 'open-window',
- name: 'open-window',
- component: () => import('./pages/demo/open-window.vue'),
- },
- ],
+ },
+ {
+ path: "/demo/",
+ component: () => import("./pages/demo/index.vue"),
+ meta: {
+ title: "操练场",
},
- {
- path: '/creator',
- name: 'creator 4.0',
- component: () => import('./pages/creator/index.vue'),
+ children: [
+ {
+ path: "download",
+ name: "download",
+ component: () => import("./pages/demo/download.vue"),
+ },
+ {
+ path: "open-window",
+ name: "open-window",
+ component: () => import("./pages/demo/open-window.vue"),
+ },
+ ],
+ },
+ {
+ path: "/creator",
+ name: "creator 4.0",
+ component: () => import("./pages/creator/index.vue"),
+ },
+ {
+ path: "/panel/:name",
+ props: true,
+ component: () => import("./pages/creator/page.vue"),
+ meta: {
+ hideInNav: true,
},
- {
- path: '/panel/:name',
- props: true,
- component: () => import('./pages/creator/panel.vue'),
- meta: {
- hideInNav: true,
- },
+ },
+ {
+ path: "/sub-win/:name/:url",
+ props: true,
+ component: () => import("./pages/creator/sub-window.vue"),
+ meta: {
+ hideInNav: true,
},
+ },
];
export const router = createRouter({
- history: createWebHashHistory(),
- routes,
+ history: createWebHashHistory(),
+ routes,
});
diff --git a/app-views/src/style.css b/app-views/src/style.css
index 0a6e417..adea9e0 100644
--- a/app-views/src/style.css
+++ b/app-views/src/style.css
@@ -1,19 +1,23 @@
:root {
- font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
- line-height: 1.5;
- font-weight: 400;
+ font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
+ line-height: 1.5;
+ font-weight: 400;
- color-scheme: light dark;
- color: rgba(255, 255, 255, 0.87);
- background-color: #242424;
+ color-scheme: light dark;
+ color: rgba(255, 255, 255, 0.87);
+ background-color: #242424;
- font-synthesis: none;
- text-rendering: optimizeLegibility;
- -webkit-font-smoothing: antialiased;
- -moz-osx-font-smoothing: grayscale;
+ font-synthesis: none;
+ text-rendering: optimizeLegibility;
+ -webkit-font-smoothing: antialiased;
+ -moz-osx-font-smoothing: grayscale;
}
body {
- margin: 0;
- min-height: 100vh;
+ margin: 0;
+ min-height: 100vh;
+}
+
+.ant-tabs-nav {
+ margin-bottom: 0 !important;
}
diff --git a/app-views/vite.config.ts b/app-views/vite.config.ts
index faf59d4..1451826 100644
--- a/app-views/vite.config.ts
+++ b/app-views/vite.config.ts
@@ -1,27 +1,27 @@
-import { defineConfig } from 'vite';
-import vue from '@vitejs/plugin-vue';
-import Components from 'unplugin-vue-components/vite';
-import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers';
+import { defineConfig } from "vite";
+import vue from "@vitejs/plugin-vue";
+import Components from "unplugin-vue-components/vite";
+import { AntDesignVueResolver } from "unplugin-vue-components/resolvers";
// https://vitejs.dev/config/
export default defineConfig({
- root: './',
- build: {
- outDir: '../app/node_modules/.views',
- emptyOutDir: true,
- rollupOptions: {
- external: ['electron'],
- },
+ root: "./",
+ base: "./",
+ build: {
+ outDir: "../app/node_modules/.views",
+ emptyOutDir: true,
+ rollupOptions: {
+ external: ["electron"],
},
- plugins: [
- vue(),
- Components({
- resolvers: [
- AntDesignVueResolver({
- importStyle: false, // css in js
- }),
- ],
+ },
+ plugins: [
+ vue(),
+ Components({
+ resolvers: [
+ AntDesignVueResolver({
+ importStyle: false, // css in js
}),
- ],
- base: './',
+ ],
+ }),
+ ],
});
diff --git a/app/package.json b/app/package.json
index a18586f..3d9a9b9 100644
--- a/app/package.json
+++ b/app/package.json
@@ -1,13 +1,14 @@
{
- "name": "electron-app",
- "version": "1.0.0",
- "type": "module",
- "main": "dist/index.js",
- "scripts": {
- "test": "echo \"Error: no test specified\" && exit 1"
- },
- "dependencies": {
- "axios": "^1.7.4",
- "fs-extra": "^11.2.0"
- }
+ "name": "cocos-creator-next",
+ "version": "1.0.0",
+ "type": "module",
+ "main": "dist/index.js",
+ "scripts": {
+ "dev": "npx tsc --watch",
+ "build": "npx tsc"
+ },
+ "dependencies": {
+ "axios": "^1.7.4",
+ "fs-extra": "^11.2.0"
+ }
}
diff --git a/app/src/index.ts b/app/src/index.ts
index 72bfec8..23baada 100644
--- a/app/src/index.ts
+++ b/app/src/index.ts
@@ -1,87 +1,100 @@
-import { app, BrowserWindow, ipcMain } from 'electron';
-import { join, dirname } from 'node:path';
-import { pathToFileURL, fileURLToPath } from 'node:url';
-import './download/index.js';
-import './download/hash-list.js';
+import { app, BrowserWindow, ipcMain } from "electron";
+import { join, dirname } from "node:path";
+import { pathToFileURL, fileURLToPath } from "node:url";
+import "./download/index.js";
+import "./download/hash-list.js";
-import './menu/index.js';
-import './window-center.js';
+import "./menu/index.js";
+import "./window-center.js";
const __dirname = dirname(fileURLToPath(import.meta.url));
-const isPackaged = app.isPackaged || __dirname.includes('asar');
+const isPackaged = app.isPackaged || __dirname.includes("asar");
if (!isPackaged) {
- await import('./devtool.cjs');
+ await import("./devtool.cjs");
}
let main: BrowserWindow | null = null;
const createWindow = () => {
- const mainWindow = new BrowserWindow({
- width: 12000,
- height: 900,
+ const mainWindow = new BrowserWindow({
+ width: 1200,
+ height: 900,
+ webPreferences: {
+ preload: join(__dirname, "../preload.cjs"), // 只能是 cjs
+ sandbox: true,
+ webSecurity: true,
+ },
+ });
+
+ mainWindow.webContents.setWindowOpenHandler(({ url }) => {
+ console.log("渲染进程在打开这个地址:", url);
+ return {
+ action: "allow",
+ overrideBrowserWindowOptions: {
webPreferences: {
- preload: join(__dirname, '../preload.cjs'), // 只能是 cjs
- sandbox: true,
- webSecurity: true,
+ preload: join(__dirname, "../preload.cjs"),
},
- });
+ },
+ };
+ });
- mainWindow.webContents.setWindowOpenHandler(({ url }) => {
- console.log('渲染进程在打开这个地址:', url);
- return {
- action: 'allow',
- overrideBrowserWindowOptions: {
- webPreferences: {
- preload: join(__dirname, '../preload.cjs'),
- },
- },
- };
- });
+ main = mainWindow;
- main = mainWindow;
+ // 加载 index.html
+ if (isPackaged) {
+ const viewLink = join(__dirname, "../node_modules/.views/index.html");
+ mainWindow.loadFile(viewLink);
- // 加载 index.html
- if (isPackaged) {
- const viewLink = join(__dirname, '../node_modules/.views/index.html');
+ mainWindow.webContents.on("will-navigate", (event, url) => {
+ // 如果不是 index.html,则阻止导航并重定向
+ if (!url.startsWith(viewLink)) {
+ event.preventDefault();
mainWindow.loadFile(viewLink);
+ }
+ });
- mainWindow.webContents.on('will-navigate', (event, url) => {
- // 如果不是 index.html,则阻止导航并重定向
- if (!url.startsWith(viewLink)) {
- event.preventDefault();
- mainWindow.loadFile(viewLink);
- }
- });
-
- mainWindow.setTitle('打包模式');
- } else {
- mainWindow.loadURL('http://localhost:5555/');
+ mainWindow.setTitle("打包模式");
+ } else {
+ mainWindow.loadURL("http://localhost:5555/");
- // 打开开发工具
- mainWindow.webContents.openDevTools();
- mainWindow.setTitle('开发模式');
- }
+ // 打开开发工具
+ mainWindow.webContents.openDevTools();
+ mainWindow.setTitle("开发模式");
+ }
};
+setTimeout(() => {
+ const win = new BrowserWindow({
+ width: 800,
+ height: 800,
+ webPreferences: {
+ preload: join(__dirname, "../preload.cjs"), // 只能是 cjs
+ sandbox: true,
+ webSecurity: true,
+ },
+ });
+ win.loadURL("http://localhost:5555/#/sub-win/abc/efg");
+}, 1000 * 3);
+
// 这段程序将会在 Electron 结束初始化
// 和创建浏览器窗口的时候调用
// 部分 API 在 ready 事件触发后才能使用。
app.whenReady().then(() => {
- createWindow();
+ createWindow();
- app.on('activate', () => {
- // 在 macOS 系统内, 如果没有已开启的应用窗口
- // 点击托盘图标时通常会重新创建一个新窗口
- if (BrowserWindow.getAllWindows().length === 0) createWindow();
- });
+ app.on("activate", () => {
+ // 在 macOS 系统内, 如果没有已开启的应用窗口
+ // 点击托盘图标时通常会重新创建一个新窗口
+ if (BrowserWindow.getAllWindows().length === 0) createWindow();
+ });
});
// 除了 macOS 外,当所有窗口都被关闭的时候退出程序。 因此, 通常
// 对应用程序和它们的菜单栏来说应该时刻保持激活状态,
// 直到用户使用 Cmd + Q 明确退出
-app.on('window-all-closed', () => {
- if (process.platform !== 'darwin') app.quit();
+app.on("window-all-closed", () => {
+ if (process.platform !== "darwin") app.quit();
});
-ipcMain.handle('app-is-packaged', () => {
- return isPackaged;
+ipcMain.handle("app-is-packaged", () => {
+ return isPackaged;
});
diff --git a/package.json b/package.json
index 65f62fc..48dc08f 100644
--- a/package.json
+++ b/package.json
@@ -1,24 +1,24 @@
{
- "name": "my-electron-app",
- "type": "module",
- "scripts": {
- "preinstall": "npx only-allow pnpm",
- "make": "pnpm run web:build && pnpm run app:build && node ./scripts/make.mjs",
- "app:dev": "cd ./app && tsc --watch",
- "app:build": "cd ./app && tsc",
- "web:dev": "cd ./app-views && pnpm run dev",
- "web:build": "cd ./app-views && pnpm run build"
- },
- "packageManager": "pnpm@9.0.0",
- "devDependencies": {
- "@electron/asar": "^3.2.8",
- "@types/fs-extra": "^11.0.4",
- "axios": "^1.7.4",
- "electron": "29.0.1",
- "electron-devtools-installer": "^3.2.0",
- "extract-zip": "^2.0.1",
- "fs-extra": "^11.2.0",
- "progress": "^2.0.3",
- "typescript": "^5.5.4"
- }
+ "name": "my-electron-app",
+ "type": "module",
+ "scripts": {
+ "preinstall": "npx only-allow pnpm",
+ "make": "pnpm run web:build && pnpm run app:build && node ./scripts/make.mjs",
+ "app:dev": "cd ./app && pnpm run dev",
+ "app:build": "cd ./app && pnpm run build",
+ "web:dev": "cd ./app-views && pnpm run dev",
+ "web:build": "cd ./app-views && pnpm run build"
+ },
+ "packageManager": "pnpm@9.0.0",
+ "devDependencies": {
+ "@electron/asar": "^3.2.8",
+ "@types/fs-extra": "^11.0.4",
+ "axios": "^1.7.4",
+ "electron": "33.0.2",
+ "electron-devtools-installer": "^3.2.0",
+ "extract-zip": "^2.0.1",
+ "fs-extra": "^11.2.0",
+ "progress": "^2.0.3",
+ "typescript": "^5.6.3"
+ }
}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 113c9f9..bff25e3 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -18,8 +18,8 @@ importers:
specifier: ^1.7.4
version: 1.7.4
electron:
- specifier: 29.0.1
- version: 29.0.1
+ specifier: 33.0.2
+ version: 33.0.2
electron-devtools-installer:
specifier: ^3.2.0
version: 3.2.0
@@ -33,8 +33,8 @@ importers:
specifier: ^2.0.3
version: 2.0.3
typescript:
- specifier: ^5.5.4
- version: 5.5.4
+ specifier: ^5.6.3
+ version: 5.6.3
packages:
@@ -93,6 +93,7 @@ packages:
boolean@3.2.0:
resolution: {integrity: sha512-d0II/GO9uf9lfUHH2BQsjxzRJZBdsjgsBiW4BvhWk/3qoKwQFjIDVN19PfX8F2D/r9PCMTtLWjYVCFrpeYUzsw==}
+ deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
brace-expansion@1.1.11:
resolution: {integrity: sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==}
@@ -160,8 +161,8 @@ packages:
electron-devtools-installer@3.2.0:
resolution: {integrity: sha512-t3UczsYugm4OAbqvdImMCImIMVdFzJAHgbwHpkl5jmfu1izVgUcP/mnrPqJIpEeCK1uZGpt+yHgWEN+9EwoYhQ==}
- electron@29.0.1:
- resolution: {integrity: sha512-hsQr9clm8NCAMv4uhHlXThHn52UAgrHgyz3ubBAxZIPuUcpKVDtg4HPmx4hbmHIbYICI5OyLN3Ztp7rS+Dn4Lw==}
+ electron@33.0.2:
+ resolution: {integrity: sha512-C2WksfP0COsMHbYXSJG68j6S3TjuGDrw/YT42B526yXalIlNQZ2GeAYKryg6AEMkIp3p8TUfDRD0+HyiyCt/nw==}
engines: {node: '>= 12.20.55'}
hasBin: true
@@ -444,8 +445,8 @@ packages:
resolution: {integrity: sha512-34R7HTnG0XIJcBSn5XhDd7nNFPRcXYRZrBB2O2jdKqYODldSzBAqzsWoZYYvduky73toYS/ESqxPvkDf/F0XMg==}
engines: {node: '>=10'}
- typescript@5.5.4:
- resolution: {integrity: sha512-Mtq29sKDAEYP7aljRgtPOpTvOfbwRWlS6dPRzwjdE+C0R4brX/GUyhHSecbHMFLNBLcJIPt9nl9yG5TZ1weH+Q==}
+ typescript@5.6.3:
+ resolution: {integrity: sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw==}
engines: {node: '>=14.17'}
hasBin: true
@@ -626,7 +627,7 @@ snapshots:
tslib: 2.7.0
unzip-crx-3: 0.2.0
- electron@29.0.1:
+ electron@33.0.2:
dependencies:
'@electron/get': 2.0.3
'@types/node': 20.16.1
@@ -939,7 +940,7 @@ snapshots:
type-fest@0.13.1:
optional: true
- typescript@5.5.4: {}
+ typescript@5.6.3: {}
undici-types@6.19.8: {}