Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
优化体验,修复错误
Browse files Browse the repository at this point in the history
  • Loading branch information
Ran-Xing committed Mar 10, 2024
1 parent 154a78e commit 492208c
Show file tree
Hide file tree
Showing 11 changed files with 1,088 additions and 1,067 deletions.
19 changes: 14 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ jobs:
name: dfuTools_amd64
path: electron/dfuTools_x64

- name: Chmod dfuTools
run: |
chmod +x electron/dfuTools_*
- name: Build Release Files
run: npm run pack
env:
Expand All @@ -64,17 +68,22 @@ jobs:
delete_tag_pattern: ""
env:
GITHUB_TOKEN: ${{ secrets.TOKEN_GITHUB }}

- name: 获取版本号
-
name: 获取版本号
id: get-version
run: |
echo "version=$(jq -r .version package.json)" >> $GITHUB_OUTPUT
version=$(jq -r .version package.json)
echo "version=${version}" >> $GITHUB_OUTPUT
-
name: Make release
uses: softprops/action-gh-release@v1
with:
files: "release/**/*.dmg"
files: |
release/${{ steps.get-version.outputs.version }}/DFU-Tools_x64.dmg
release/${{ steps.get-version.outputs.version }}/DFU-Tools_x64.dmg.blockmap
release/${{ steps.get-version.outputs.version }}/DFU-Tools_arm64.dmg
release/${{ steps.get-version.outputs.version }}/DFU-Tools_arm64.dmg.blockmap
release/${{ steps.get-version.outputs.version }}/latest-mac.yml
body: "Update ${{ steps.get-version.outputs.version }}"
name: ${{ steps.get-version.outputs.version }}
tag_name: ${{ steps.get-version.outputs.version }}
Expand Down
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
release
node_modules
electron/dfuTools*
/release/
/node_modules
/electron/dfuTools*
/macvdmtool/main.o
15 changes: 9 additions & 6 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
## macOS DFU Tools

### 必读 / Must read
> 本项目是一个macOS下的DFU工具,用于快速进入DFU模式、快速重启以及进入Recovery模式(尚未测试)。
>
> This project is a DFU tool under mac OS for fast entry into DFU mode, fast restart, and entry into Recovery mode (not yet tested).
>
> 依赖于 / depend on [AsahiLinux/macvdmtool](https://github.com/AsahiLinux/macvdmtool)
>
> **(Apple -> Apple || Intel -> Intel)** by Apple: 400-666-8800
### Download
### 下载 / Download

> [Github Release](https://github.com/XRSec/DFU-Tools/releases)
>
> [镜像加速(Inter 1.1.0)](https://mirror.ghproxy.com/https://github.com/XRSec/DFU-Tools/releases/download/1.1.5/DFU-Tools_x64.dmg)
> [镜像加速(Inter 1.1.7)](https://mirror.ghproxy.com/https://github.com/XRSec/DFU-Tools/releases/download/1.1.7/DFU-Tools_x64.dmg)
>
> [镜像加速(Apple 1.1.0)](https://mirror.ghproxy.com/https://github.com/XRSec/DFU-Tools/releases/download/1.1.0/DFU-Tools_arm64.dmg)
> [镜像加速(Apple 1.1.7)](https://mirror.ghproxy.com/https://github.com/XRSec/DFU-Tools/releases/download/1.1.7/DFU-Tools_arm64.dmg)
### Usage
### 使用 / Usage

![dashboard](./dashboard_en.png)
![dashboard](./dashboard.png)

## 报错汇总
## 报错汇总 / FAQ

### 已损坏 打不开
### 已损坏 打不开 / Can't open

```bash
sudo xattr -rd com.apple.quarantine /Applications/DFU-Tools.app
Expand Down
3 changes: 3 additions & 0 deletions electron-builder.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
]
}
],
"publish": [
"github"
],
"darkModeSupport": true,
"icon": "electron/icon.icns",
"category": "public.app-category.productivity",
Expand Down
Binary file added electron/alipay.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 10 additions & 4 deletions electron/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="icon" type="image/svg+xml" href="/icon.png">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';">

Expand Down Expand Up @@ -91,7 +90,7 @@
'zh-CN': {
'title': '苹果电脑 刷机助手',
'restart': '重启',
'dfu': 'DFU',
'dfu': '工厂模式 DFU',
'ipsw': '镜像文件',
'bypassMdm': '绕过监管',
'author': '作者',
Expand All @@ -103,6 +102,9 @@
"close": '关闭',
"msg": "提示",
"none": "无内容",
"no_connection": '设备未连接',
"no_admin_permission": "无管理员权限",
"no_dfu_permission": "DFU工具无运行权限"
},
'en': {
'title': 'Apple Flashing Assistant',
Expand All @@ -119,6 +121,9 @@
"close": 'Close',
"msg": "Message",
"none": "None",
"no_connection": 'Devices Not Connection',
"no_admin_permission": "No Administrator Permission",
"no_dfu_permission": "DFU Tool No Permission"
}
};
let isButtonEnabled = true;
Expand Down Expand Up @@ -270,8 +275,9 @@
</div>

<div class="reward">
<img src="./wechat.png" alt="微信">
<img src="./pay.png" alt="打赏码">
<img src="./wechat.png" alt="微信" class="wechat">
<img src="./wechatpay.png" alt="微信打赏码">
<img src="./alipay.png" alt="支付宝打赏码">
</div>

<div class="footer">
Expand Down
129 changes: 97 additions & 32 deletions electron/index.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
const {app, BrowserWindow, ipcMain, Menu, shell} = require('electron')
const sudo = require('sudo-prompt');
const {join} = require("node:path");
const {execSync} = require("child_process");
const {chmodSync} = require("fs");
const options = {
name: "DFU Tools",
icns: join(__dirname, 'icon.icns')
}
let dfuTools = join(__dirname, 'dfuTools')
const {execSync, exec} = require("child_process");
const {chmod, existsSync, lstatSync} = require("fs");
const prompt = require('electron-prompt');

const arch = process.arch === 'arm64' ? 'arm64' : 'x64';
let dfuTools = join(__dirname, `dfuTools_${arch}`),
admin_pass = '',
configuratorStatus = false,
win;

if (__dirname.includes('/Contents/Resources/')) {
dfuTools = join(__dirname, '../dfuTools')
dfuTools = join(__dirname, '../../dfuTools')
}
if (!existsSync(dfuTools) || lstatSync(dfuTools).isDirectory()) {
dfuTools = join(dfuTools, `dfuTools_${arch}`)
}

console.log(dfuTools)
chmodSync(dfuTools, '755', (err) => {
if (err) throw err;
console.debug(`dfuTools: ${dfuTools}`)

chmod(dfuTools, '755', (err) => {
if (err) {
throw err;
} else {
console.debug(`dfuTools chmod success`)
}
});

let configuratorStatus = false;
const createWindow = () => {
const win = new BrowserWindow({
win = new BrowserWindow({
width: 920,
height: 580,
minWidth: 920,
Expand All @@ -29,7 +37,7 @@ const createWindow = () => {
nodeIntegration: true,
contextIsolation: false,
webSecurity: true,
devTools: !app.isPackaged, // 如果是开发模式可以使用devTools 调试
devTools: !app.isPackaged || process.env.DFU_DEBUG, // 如果是开发模式可以使用devTools 调试
scrollBounce: process.platform === "darwin", // 在macos中启用橡皮动画
},
// transparent: true, //设置透明
Expand All @@ -39,45 +47,102 @@ const createWindow = () => {
win.on('closed', () => {
app.quit();
});
!app.isPackaged && win.webContents.openDevTools()
(!app.isPackaged || process.env.DFU_DEBUG) && win.webContents.openDevTools()
win.webContents.on('dom-ready', () => {
if (admin_pass !== "") return;

function testPrivilege() {
exec(`echo '${admin_pass}' | sudo -S whoami`, {encoding: 'utf-8'}).on('exit', (code) => {
(code !== 0) && getPassword();
console.debug('run as admin privilege')
}).on('error', (err) => {
console.debug(err)
getPassword();
})
}

function getPassword() {
prompt({
title: '提示',
label: '请输入您的密码 / Please Enter U Passwd',
value: '',
inputAttrs: {type: 'password'},
type: 'input'
}).then((r) => {
if (r === null) {
console.debug('user cancelled');
} else {
console.debug('pass:', r);
admin_pass = r;
testPrivilege();
}
}).catch(console.error);
}

getPassword()
})
}

Menu.setApplicationMenu(Menu.buildFromTemplate([{
label: 'File',
submenu: [
{role: 'quit'},
{role: 'close'},
]
}]));
Menu.setApplicationMenu(Menu.buildFromTemplate(
[{
label: 'File',
submenu: [
{role: 'quit'},
{role: 'close'},
{
label: 'Toggle Developer Tools',
click: () => {
win.webContents.toggleDevTools();
}
}]
}]
));

app.whenReady().then(() => {
if (BrowserWindow.getAllWindows().length === 0) createWindow();
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
})

ipcMain.on('openReboot', (event) => {
if (!checkConfiguratorRunning()) {
event.returnValue = "configurator_not_running";
return;
}
sudo.exec(`${dfuTools} reboot`, options, function (error, stdout, _stderr) {
if (error) {
event.returnValue = "run_error";
return
exec(`echo '${admin_pass}' | sudo -S ${dfuTools} reboot`, {encoding: 'utf-8'}, function (_error, stdout, _stderr) {
if (stdout.includes('No connection detected')) {
event.returnValue = "no_connection";
return;
} else if (stdout.includes('IOCreatePlugInInterfaceForService failed')) {
event.returnValue = "no_admin_permission";
return;
} else if (_error.toString().includes('command not found')) {
event.returnValue = "no_dfu_permission";
return;
}
console.debug(_error, _stderr)
event.returnValue = stdout;
})
})

ipcMain.on('openDFU', (event) => {
if (!checkConfiguratorRunning()) {
console.debug(`configurator not running`)
event.returnValue = "configurator_not_running";
return;
}
sudo.exec(`${dfuTools} dfu`, options, function (error, stdout, _stderr) {
if (error) {
event.returnValue = "run_error";
return
exec(`echo '${admin_pass}' | sudo -S ${dfuTools} dfu`, {encoding: 'utf-8'}, function (_error, stdout, _stderr) {
if (stdout.includes('No connection detected')) {
event.returnValue = "no_connection";
return;
} else if (stdout.includes('IOCreatePlugInInterfaceForService failed')) {
event.returnValue = "no_admin_permission";
return;
} else if (_error.toString().includes('command not found')) {
event.returnValue = "no_dfu_permission";
return;
}
console.debug(_error, _stderr)
event.returnValue = stdout;
})
})
Expand Down
Binary file removed electron/pay.png
Binary file not shown.
Binary file added electron/wechatpay.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 492208c

Please sign in to comment.