Skip to content

Commit

Permalink
feat: 合并分支
Browse files Browse the repository at this point in the history
  • Loading branch information
xie392 committed May 31, 2024
1 parent acb5608 commit a813b5d
Show file tree
Hide file tree
Showing 91 changed files with 34,984 additions and 43,326 deletions.
8 changes: 8 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "https://json.schemastore.org/prettierrc",
"semi": false,
"tabWidth": 2,
"singleQuote": true,
"printWidth": 100,
"trailingComma": "none"
}
63 changes: 31 additions & 32 deletions electron-builder.json5
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
// @see - https://www.electron.build/configuration/configuration
{
$schema: 'https://raw.githubusercontent.com/electron-userland/electron-builder/master/packages/app-builder-lib/scheme.json',
appId: 'com.hotsea.coss',
asar: true,
productName: 'coss',
directories: {
output: 'release/${version}'
},
files: ['dist', 'dist-electron'],
mac: {
target: ['dmg'],
artifactName: '${productName}-Mac-${version}-Installer.${ext}'
},
win: {
requestedExecutionLevel: 'highestAvailable',
target: [
{
target: 'nsis',
arch: ['x64', 'ia32']
}
],
artifactName: '${productName}-Windows-${version}-Setup.${ext}'
},
nsis: {
oneClick: false,
perMachine: false,
allowToChangeInstallationDirectory: true,
deleteAppDataOnUninstall: false
},
linux: {
target: ['AppImage'],
artifactName: '${productName}-Linux-${version}.${ext}'
}
$schema: 'https://raw.githubusercontent.com/electron-userland/electron-builder/master/packages/app-builder-lib/scheme.json',
appId: 'YourAppID',
asar: true,
productName: 'COSS',
directories: {
output: 'release/${version}'
},
files: ['dist', 'dist-electron'],
mac: {
target: ['dmg'],
artifactName: '${productName}-Mac-${version}-Installer.${ext}'
},
win: {
target: [
{
target: 'nsis',
arch: ['x64']
}
],
artifactName: '${productName}-Windows-${version}-Setup.${ext}'
},
nsis: {
oneClick: false,
perMachine: false,
allowToChangeInstallationDirectory: true,
deleteAppDataOnUninstall: false
},
linux: {
target: ['AppImage'],
artifactName: '${productName}-Linux-${version}.${ext}'
}
}
79 changes: 41 additions & 38 deletions electron/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,65 +15,68 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url))
// │ │ ├── main.js
// │ │ └── preload.mjs
// │
process.env.APP_ROOT = path.join(__dirname, '../..')
process.env.APP_ROOT = path.join(__dirname, '..')

// 🚧 Use ['ENV_NAME'] avoid vite:define plugin - [email protected]
export const VITE_DEV_SERVER_URL = process.env['VITE_DEV_SERVER_URL']
export const MAIN_DIST = path.join(process.env.APP_ROOT, 'dist-electron')
export const RENDERER_DIST = path.join(process.env.APP_ROOT, 'dist')

process.env.VITE_PUBLIC = VITE_DEV_SERVER_URL ? path.join(process.env.APP_ROOT, 'public') : RENDERER_DIST
process.env.VITE_PUBLIC = VITE_DEV_SERVER_URL
? path.join(process.env.APP_ROOT, 'public')
: RENDERER_DIST

let win: BrowserWindow | null

function createWindow() {
win = new BrowserWindow({
icon: path.join(process.env.VITE_PUBLIC, 'electron-vite.svg'),
webPreferences: {
preload: path.join(__dirname, 'preload.mjs')
// webSecurity: false
// nodeIntegration: true,
// contextIsolation: false
},
width: 1000,
height: 600
// titleBarStyle: 'hidden',
// titleBarOverlay: true,
// show: false
})
win = new BrowserWindow({
icon: path.join(process.env.VITE_PUBLIC, 'electron-vite.svg'),
webPreferences: {
preload: path.join(__dirname, 'preload.mjs')
// webSecurity: false
// nodeIntegration: true,
// contextIsolation: false
},
width: 1000,
height: 600
// titleBarStyle: 'hidden',
// titleBarOverlay: true,
// show: false
})

// Test active push message to Renderer-process.
win.webContents.on('did-finish-load', () => {
win?.webContents.send('main-process-message', new Date().toLocaleString())
})
// Test active push message to Renderer-process.
win.webContents.on('did-finish-load', () => {
win?.webContents.send('main-process-message', new Date().toLocaleString())
})

if (VITE_DEV_SERVER_URL) {
// 开发环境下打开控制台
win.webContents.openDevTools()
win.loadURL(VITE_DEV_SERVER_URL)
// win.loadURL('http://localhost:8081')
} else {
// win.loadFile('dist/index.html')
win.loadFile(path.join(RENDERER_DIST, 'index.html'))
}
if (VITE_DEV_SERVER_URL) {
// 开发环境下打开控制台
win.loadURL(VITE_DEV_SERVER_URL)
// win.loadURL('http://localhost:8081')
} else {
// win.loadFile('dist/index.html')
win.loadFile(path.join(RENDERER_DIST, 'index.html'))
}

win.webContents.openDevTools()
}

// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
// explicitly with Cmd + Q.
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
win = null
}
if (process.platform !== 'darwin') {
app.quit()
win = null
}
})

app.on('activate', () => {
// 在 OS X 上,当出现以下情况时,通常会在应用程序中重新创建一个窗口:
// 单击停靠图标,并且没有打开其他窗口。
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
// 在 OS X 上,当出现以下情况时,通常会在应用程序中重新创建一个窗口:
// 单击停靠图标,并且没有打开其他窗口。
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})

app.whenReady().then(createWindow)
15 changes: 7 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
"react-router"
],
"scripts": {
"dev": "cross-env TARGET=web vite --mode development --host 0.0.0.0",
"dev:electron": "cross-env TARGET=electron vite --mode development",
"dev:android": "cross-env TARGET=development && npm run build:mobile && npx cap copy",
"dev:ios": "cross-env TARGET=development && npm run build:mobile && npx cap copy",
"dev": "vite --mode development --host 0.0.0.0",
"dev:electron": "vite -c vite.electron.config.ts --mode development --host 0.0.0.0",
"dev:android": "npm run build:mobile && npx cap copy",
"dev:ios": "npm run build:mobile && npx cap copy",
"build": "tsc && vite build",
"build:electron": "cross-env TARGET=electron tsc && vite build && electron-builder",
"build:mobile": "cross-env TARGET=production && npm run build && npx cap sync",
"build:electron": "tsc && vite build -c vite.electron.config.ts && electron-builder",
"build:mobile": "npm run build && npx cap sync",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview",
"translate": "node node_modules/vue-auto-translate/server.js",
"format": "prettier --write ./src/**/*.{ts,tsx,js,jsx,json,md,mdx}"
"format": "prettier --write ./src/*"
},
"dependencies": {
"@ant-design/icons": "^5.3.7",
Expand Down Expand Up @@ -69,7 +69,6 @@
"@vitejs/plugin-react": "^4.2.1",
"autoprefixer": "^10.4.19",
"copyfiles": "^2.4.1",
"cross-env": "^7.0.3",
"electron": "^30.0.7",
"electron-builder": "^24.13.3",
"eslint": "^8.57.0",
Expand Down
6 changes: 6 additions & 0 deletions postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
33 changes: 33 additions & 0 deletions src/__test__/sql.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"use strict";
// import initSqlJs from 'sql.js'
// const SQL = await initSqlJs({ locateFile: (file: any) => `/assets/${file}` })
// const db = new SQL.Database()
// 创建表
// const createTable = () => {
// const createTableSQL = `
// CREATE TABLE IF NOT EXISTS items (
// id INTEGER PRIMARY KEY AUTOINCREMENT,
// name TEXT,
// quantity INTEGER
// );
// `
// db.run(createTableSQL)
// }
// const insertItem = (name, quantity) => {
// const insertSQL = `INSERT INTO items (name, quantity) VALUES (?, ?)`
// const statement = db.prepare(insertSQL)
// statement.run([name, quantity])
// statement.free()
// }
// const getItems = () => {
// const selectSQL = `SELECT * FROM items`
// const results = db.exec(selectSQL)
// return results.length ? results[0].values : []
// }
// // createTable()
// export const sqlTest = () => {
// console.log('SQL', SQL)
// // insertItem('apple', 10)
// // insertItem('banana', 5)
// console.log(getItems())
// }
Loading

0 comments on commit a813b5d

Please sign in to comment.