Skip to content

Commit

Permalink
refactor: 🚀 对目录结构和代码逻辑进行重构
Browse files Browse the repository at this point in the history
  • Loading branch information
viarotel committed Oct 16, 2023
1 parent 218f851 commit 73c6713
Show file tree
Hide file tree
Showing 45 changed files with 336 additions and 142 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/release-assets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ jobs:
with:
draft: true
files: |
dist/*.exe
dist/*.zip
dist/*.dmg
dist/*.AppImage
dist/*.snap
dist/*.deb
dist/*.rpm
dist/*.tar.gz
dist/*.yml
dist/*.blockmap
dist-release/*.exe
dist-release/*.zip
dist-release/*.dmg
dist-release/*.AppImage
dist-release/*.snap
dist-release/*.deb
dist-release/*.rpm
dist-release/*.tar.gz
dist-release/*.yml
dist-release/*.blockmap
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ node_modules
dist
dist-ssr
dist-electron
release
dist-release
*.local

# Editor directories and files
Expand Down
2 changes: 1 addition & 1 deletion binary.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default function CustomPlugin() {
export default function VitePluginPath() {
return {
name: 'vite-plugin-path',
transform(src, id) {
Expand Down
4 changes: 4 additions & 0 deletions dev-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
provider: github
owner: viarotel-org
repo: escrcpy
updaterCacheDirName: escrcpy-updater
51 changes: 51 additions & 0 deletions electron-builder.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"$schema": "https://raw.githubusercontent.com/electron-userland/electron-builder/master/packages/app-builder-lib/scheme.json",
"appId": "org.viarotel.escrcpy",
"asar": true,
"productName": "escrcpy",
"directories": {
"output": "dist-release/${version}",
"buildResources": "electron/resources/build"
},
"files": ["dist", "dist-electron"],
"extraResources": ["electron/resources/extra"],
"publish": {
"provider": "github",
"owner": "viarotel-org",
"repo": "escrcpy",
"updaterCacheDirName": "escrcpy-updater"
},
"mac": {
"target": ["dmg"],
"artifactName": "${productName}-${version}-mac-installer.${ext}"
},
"win": {
"target": [
{
"target": "nsis",
"arch": ["x64"]
},
{
"target": "zip"
},
{
"target": "portable"
}
]
},
"nsis": {
"artifactName": "${productName}-${version}-win-setup.${ext}",
"oneClick": false,
"perMachine": false,
"allowToChangeInstallationDirectory": true,
"deleteAppDataOnUninstall": false
},
"portable": {
"artifactName": "${productName}-${version}-win-portable.${ext}",
"requestExecutionLevel": "user"
},
"linux": {
"target": ["AppImage"],
"artifactName": "${productName}-${version}-linux.${ext}"
}
}
48 changes: 0 additions & 48 deletions electron-builder.json5

This file was deleted.

File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
import path from 'node:path'
import { app, ipcMain } from 'electron'
import { is } from '@electron-toolkit/utils'
import { autoUpdater } from 'electron-updater'
import devPublishPath from '@root/dev-publish.yml?path'

export default (mainWindow) => {
// dev-start, 这里是为了在本地做应用升级测试使用,正式环境请务必删除
if (is.dev && process.env.ELECTRON_RENDERER_URL) {
const updateConfigPath = path.join(process.cwd(), './dev-app-update.yml')
// console.log('updateConfigPath', updateConfigPath)
// if (is.dev && process.env.ELECTRON_RENDERER_URL) {
if (is.dev && process.env.VITE_DEV_SERVER_URL) {
const updateConfigPath = devPublishPath
autoUpdater.updateConfigPath = updateConfigPath
Object.defineProperty(app, 'isPackaged', {
get() {
return true
},
})
}

Object.defineProperty(app, 'isPackaged', {
get() {
return true
},
})
// dev-end

// 触发检查更新(此方法用于被渲染线程调用,例如页面点击检查更新按钮来调用此方法)
ipcMain.on('check-for-update', () => {
console.log('ipcMain:check-for-update')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import path from 'node:path'
import fs from 'node:fs'
import dayjs from 'dayjs'
import { Adb } from '@devicefarmer/adbkit'
import adbPath from '@resources/core/adb.exe?path'

console.log('adbPath', adbPath)
import adbPath from '@resources/extra/core/adb.exe?path'

const exec = util.promisify(child_process.exec)

Expand Down Expand Up @@ -99,7 +97,7 @@ const watch = async (callback) => {
}

export default () => {
client = Adb.createClient({})
client = Adb.createClient({ bin: adbPath })
console.log('client', client)

return {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion electron/plugins/index.js → electron/exposes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import adbkit from './adbkit/index.js'
import scrcpy from './scrcpy/index.js'

export default {
install(expose) {
init(expose) {
expose('nodePath', path)
expose('electron', electron())
expose('adbkit', adbkit())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import util from 'node:util'
import child_process from 'node:child_process'
import adbPath from '@resources/core/adb.exe?path'
import scrcpyPath from '@resources/core/scrcpy.exe?path'
import adbPath from '@resources/extra/core/adb.exe?path'
import scrcpyPath from '@resources/extra/core/scrcpy.exe?path'

const exec = util.promisify(child_process.exec)

Expand Down
175 changes: 175 additions & 0 deletions electron/loading/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
// --------- Preload scripts loading ---------
function domReady(condition = ['complete', 'interactive']) {
return new Promise((resolve) => {
if (condition.includes(document.readyState)) {
resolve(true)
}
else {
document.addEventListener('readystatechange', () => {
if (condition.includes(document.readyState)) {
resolve(true)
}
})
}
})
}

const safeDOM = {
append(parent, child) {
if (!Array.from(parent.children).find(e => e === child)) {
parent.appendChild(child)
}
},
remove(parent, child) {
if (Array.from(parent.children).find(e => e === child)) {
parent.removeChild(child)
}
},
}

/**
* https://tobiasahlin.com/spinkit
* https://connoratherton.com/loaders
* https://projects.lukehaas.me/css-loaders
* https://matejkustec.github.io/SpinThatShit
*/
function useLoading() {
const className = 'electron-loading'
const loginStyles = `
.${className}-core {
font-size: 30px;
text-indent: -9999em;
overflow: hidden;
width: 1em;
height: 1em;
border-radius: 50%;
margin: 72px auto;
position: relative;
-webkit-transform: translateZ(0);
-ms-transform: translateZ(0);
transform: translateZ(0);
-webkit-animation: electron-loading-dots 1.7s infinite ease, electron-loading-spin 1.7s infinite ease;
animation: electron-loading-dots 1.7s infinite ease, electron-loading-spin 1.7s infinite ease;
}
@-webkit-keyframes electron-loading-dots {
0% {
box-shadow: 0 -0.83em 0 -0.4em, 0 -0.83em 0 -0.42em, 0 -0.83em 0 -0.44em, 0 -0.83em 0 -0.46em, 0 -0.83em 0 -0.477em;
}
5%,
95% {
box-shadow: 0 -0.83em 0 -0.4em, 0 -0.83em 0 -0.42em, 0 -0.83em 0 -0.44em, 0 -0.83em 0 -0.46em, 0 -0.83em 0 -0.477em;
}
10%,
59% {
box-shadow: 0 -0.83em 0 -0.4em, -0.087em -0.825em 0 -0.42em, -0.173em -0.812em 0 -0.44em, -0.256em -0.789em 0 -0.46em, -0.297em -0.775em 0 -0.477em;
}
20% {
box-shadow: 0 -0.83em 0 -0.4em, -0.338em -0.758em 0 -0.42em, -0.555em -0.617em 0 -0.44em, -0.671em -0.488em 0 -0.46em, -0.749em -0.34em 0 -0.477em;
}
38% {
box-shadow: 0 -0.83em 0 -0.4em, -0.377em -0.74em 0 -0.42em, -0.645em -0.522em 0 -0.44em, -0.775em -0.297em 0 -0.46em, -0.82em -0.09em 0 -0.477em;
}
100% {
box-shadow: 0 -0.83em 0 -0.4em, 0 -0.83em 0 -0.42em, 0 -0.83em 0 -0.44em, 0 -0.83em 0 -0.46em, 0 -0.83em 0 -0.477em;
}
}
@keyframes electron-loading-dots {
0% {
box-shadow: 0 -0.83em 0 -0.4em, 0 -0.83em 0 -0.42em, 0 -0.83em 0 -0.44em, 0 -0.83em 0 -0.46em, 0 -0.83em 0 -0.477em;
}
5%,
95% {
box-shadow: 0 -0.83em 0 -0.4em, 0 -0.83em 0 -0.42em, 0 -0.83em 0 -0.44em, 0 -0.83em 0 -0.46em, 0 -0.83em 0 -0.477em;
}
10%,
59% {
box-shadow: 0 -0.83em 0 -0.4em, -0.087em -0.825em 0 -0.42em, -0.173em -0.812em 0 -0.44em, -0.256em -0.789em 0 -0.46em, -0.297em -0.775em 0 -0.477em;
}
20% {
box-shadow: 0 -0.83em 0 -0.4em, -0.338em -0.758em 0 -0.42em, -0.555em -0.617em 0 -0.44em, -0.671em -0.488em 0 -0.46em, -0.749em -0.34em 0 -0.477em;
}
38% {
box-shadow: 0 -0.83em 0 -0.4em, -0.377em -0.74em 0 -0.42em, -0.645em -0.522em 0 -0.44em, -0.775em -0.297em 0 -0.46em, -0.82em -0.09em 0 -0.477em;
}
100% {
box-shadow: 0 -0.83em 0 -0.4em, 0 -0.83em 0 -0.42em, 0 -0.83em 0 -0.44em, 0 -0.83em 0 -0.46em, 0 -0.83em 0 -0.477em;
}
}
@-webkit-keyframes electron-loading-spin {
0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
@keyframes electron-loading-spin {
0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
.${className}-wrap {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
z-index: 3000;
background: white;
color: #028D71;
}
.${className}-text {
margin-top: -45px;
}
`

const styleEl = document.createElement('style')
styleEl.id = `${className}-style`
styleEl.innerHTML = loginStyles

const divEl = document.createElement('div')
divEl.className = `${className}-wrap`
divEl.innerHTML = `
<div class="${className}-core"></div>
<div class="${className}-text"> 初始化服务中...</div>
`

return {
appendLoading() {
safeDOM.append(document.head, styleEl)
safeDOM.append(document.body, divEl)
},
removeLoading() {
safeDOM.remove(document.head, styleEl)
safeDOM.remove(document.body, divEl)
},
}
}

// ----------------------------------------------------------------------

const { appendLoading, removeLoading } = useLoading()
domReady().then(appendLoading)

window.onmessage = (ev) => {
ev.data.payload === 'removeLoading' && removeLoading()
}

setTimeout(removeLoading, 4999)
Loading

0 comments on commit 73c6713

Please sign in to comment.