diff --git a/packages/ui/src/main/features/first-launch-notice-window.ts b/packages/ui/src/main/features/first-launch-notice-window.ts new file mode 100644 index 0000000..1bd7f56 --- /dev/null +++ b/packages/ui/src/main/features/first-launch-notice-window.ts @@ -0,0 +1,14 @@ +import fs from 'fs' +import os from 'os' +import path from 'path' +import buildInfo from '../../common/build-info.json' + +export const firstLaunchNoticeApproveFlagPath = path.join( + os.homedir(), + '.geekgeekrun/storage', + 'ui-first-launch-notice-flag' +) + +export const isFirstLaunchNoticeApproveFlagExist = () => fs.existsSync(firstLaunchNoticeApproveFlagPath) +export const createFirstLaunchNoticeApproveFlag = () => + fs.writeFileSync(firstLaunchNoticeApproveFlagPath, buildInfo.version) diff --git a/packages/ui/src/main/window/firstLaunchNoticeWindow.ts b/packages/ui/src/main/window/firstLaunchNoticeWindow.ts new file mode 100644 index 0000000..83262e9 --- /dev/null +++ b/packages/ui/src/main/window/firstLaunchNoticeWindow.ts @@ -0,0 +1,49 @@ +import { BrowserWindow, ipcMain } from 'electron' +import path from 'path' +import { createFirstLaunchNoticeApproveFlag } from '../features/first-launch-notice-window' + +export let firstLaunchNoticeWindow: BrowserWindow | null = null +export function createFirstLaunchNoticeWindow( + opt?: Electron.BrowserWindowConstructorOptions +): BrowserWindow { + // Create the browser window. + firstLaunchNoticeWindow = new BrowserWindow({ + width: 720, + height: 640, + resizable: false, + show: false, + webPreferences: { + preload: path.join(__dirname, '../preload/index.js'), + sandbox: false + }, + ...opt + }) + + firstLaunchNoticeWindow.on('ready-to-show', () => { + firstLaunchNoticeWindow!.show() + }) + + // HMR for renderer base on electron-vite cli. + // Load the remote URL for development or the local html file for production. + if (process.env.NODE_ENV === 'development' && process.env['ELECTRON_RENDERER_URL']) { + firstLaunchNoticeWindow.loadURL(process.env['ELECTRON_RENDERER_URL'] + '#/first-run-readme') + } else { + firstLaunchNoticeWindow.loadFile( + path.join(__dirname, '../renderer/index.html') + '#/first-run-readme' + ) + } + + firstLaunchNoticeWindow!.once('closed', () => { + firstLaunchNoticeWindow = null + }) + + return firstLaunchNoticeWindow! +} + +export const initIpc = () => { + ipcMain.handle('first-launch-notice-approve', () => { + createFirstLaunchNoticeApproveFlag() + firstLaunchNoticeWindow?.close() + }) +} +initIpc() diff --git a/packages/ui/src/main/window/mainWindow.ts b/packages/ui/src/main/window/mainWindow.ts index 791fc6d..3998213 100644 --- a/packages/ui/src/main/window/mainWindow.ts +++ b/packages/ui/src/main/window/mainWindow.ts @@ -1,13 +1,15 @@ import { BrowserWindow, shell } from 'electron' import path from 'path' import { openDevTools } from '../commands' +import { createFirstLaunchNoticeWindow } from './firstLaunchNoticeWindow' +import { isFirstLaunchNoticeApproveFlagExist } from '../features/first-launch-notice-window' export let mainWindow: BrowserWindow | null = null -export function createMainWindow(): void { +export function createMainWindow(): BrowserWindow { // Create the browser window. mainWindow = new BrowserWindow({ width: 1024, - height: 640, + height: 720, show: false, autoHideMenuBar: true, ...(process.platform === 'linux' @@ -26,6 +28,14 @@ export function createMainWindow(): void { mainWindow.on('ready-to-show', () => { mainWindow.show() }) + mainWindow.on('ready-to-show', async () => { + !isFirstLaunchNoticeApproveFlagExist() && + createFirstLaunchNoticeWindow({ + parent: mainWindow!, + modal: true, + show: true + }) + }) mainWindow.webContents.setWindowOpenHandler((details) => { shell.openExternal(details.url) @@ -43,4 +53,5 @@ export function createMainWindow(): void { mainWindow!.once('closed', () => { mainWindow = null }) + return mainWindow! } diff --git a/packages/ui/src/renderer/src/page/FirstRunReadme/index.vue b/packages/ui/src/renderer/src/page/FirstRunReadme/index.vue new file mode 100644 index 0000000..6a99644 --- /dev/null +++ b/packages/ui/src/renderer/src/page/FirstRunReadme/index.vue @@ -0,0 +1,158 @@ + + + + + diff --git a/packages/ui/src/renderer/src/router/index.ts b/packages/ui/src/renderer/src/router/index.ts index 542ded8..7b74546 100644 --- a/packages/ui/src/renderer/src/router/index.ts +++ b/packages/ui/src/renderer/src/router/index.ts @@ -2,6 +2,13 @@ import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router' import BootstrapSplash from '@renderer/page/BootstrapSplash/index.vue' const routes: Array = [ + { + path: '/first-run-readme', + component: () => import('@renderer/page/FirstRunReadme/index.vue'), + meta: { + title: '初次使用必读' + } + }, { path: '/cookieAssistant', component: () => import('@renderer/page/CookieAssistant/index.vue'), @@ -65,7 +72,7 @@ const routes: Array = [ }, } ] - }, + } ] const router = createRouter({