Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

开放 macOS 系统获取设备 UDID 功能 #1418

Merged
merged 2 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions app/controllers/udid_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ def update
def register
apple_key = AppleKey.find(device_params[:apple_keys])
name = device_params[:name]
name = [ 'Zealot', params[:product], SecureRandom.hex(4) ].compact.join('-') if name.blank? # Max 50 chars
udid = params[:udid]
udid = device_params[:udid]
platform = device_params[:platform].downcase.include?('iphone') ? 'IOS' : 'MAC_OS'
name = [ 'Zealot', platform, SecureRandom.hex(4) ].compact.join('-') if name.blank? # Max 50 chars

new_device = apple_key.register_device(udid, name)
new_device = apple_key.register_device(udid, name, platform)
unless new_device.valid?
logger.debug "Register failed with errors: #{new_device.errors}"
error_message = new_device.errors.messages[:devices][0]
Expand Down Expand Up @@ -130,6 +131,6 @@ def set_apple_key
end

def device_params
params.require(:device).permit(:name, :apple_keys, :sync_to_apple_key)
@device_params ||= params.require(:device).permit(:name, :udid, :platform, :apple_keys, :sync_to_apple_key)
end
end
13 changes: 7 additions & 6 deletions app/javascript/controllers/udid_controller.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import { Controller } from "@hotwired/stimulus"
import { uaParser, isiOS, isNonAppleOS } from "./utils"
import { uaParser, isiOS, isMacOS } from "./utils"

export default class extends Controller {
static targets = ["qrcode", "install", "tip", "debug"]
static values = {
appleTip: String,
macosTip: String,
nonappleTip: String
}

connect() {
if (isNonAppleOS()) {
this.installTarget.classList.add("d-none")
this.tipTarget.innerHTML = this.nonappleTipValue
} else if (isiOS()) {
if (isiOS()) {
this.qrcodeTarget.classList.add("d-none")
} else if (isMacOS()) {
this.tipTarget.innerText = this.macosTipValue
} else {
this.installTarget.classList.add("d-none")
this.tipTarget.innerText = this.nonappleTipValue
}

this.renderDebugZone
Expand Down Expand Up @@ -49,4 +50,4 @@ export default class extends Controller {

this.debugTarget.value = message
}
}
}
4 changes: 2 additions & 2 deletions app/models/apple_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ def sync_devices
false
end

def register_device(udid, name = nil)
def register_device(udid, name = nil, platform = 'IOS')
if (existed_device = Device.find_by(udid: udid))
return existed_device
end

response_device = client.create_device(udid, name).to_model
response_device = client.create_device(udid, name, platform: platform).to_model
Device.create_from_api(response_device) do |device|
devices << device

Expand Down
4 changes: 3 additions & 1 deletion app/views/udid/_register_form.html.slim
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
.col-md-12
.card
= simple_form_for(Device.new, url: register_udid_path(udid: udid, product: product)) do |f|
= simple_form_for(Device.new, url: register_udid_path) do |f|
.card-header
h3.card-title
= t("udid.show.register_device")
.card-tools
.card-body
= f.error_notification
= f.input :name
= f.input :udid, as: :hidden, input_html: { value: udid }
= f.input :platform, as: :hidden, input_html: { value: product }
= f.input :apple_keys, collection: AppleTeam.all_names, label_method: :first, value_method: :last, include_blank: false

.card-footer
Expand Down
3 changes: 2 additions & 1 deletion app/views/udid/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
.col-md-12[
data-controller="udid"
data-udid-apple-tip-value="#{t('.apple_tip')}"
data-udid-macos-tip-value="#{t('.macos_tip')}"
data-udid-nonapple-tip-value="#{t('.nonapple_tip')}"
]
.card
Expand All @@ -28,4 +29,4 @@
.card
.card-header.card-border
h3.card-title = t('.help.title')
.card-body = t('.help.body_html')
.card-body = t('.help.body_html')
16 changes: 11 additions & 5 deletions config/locales/zealot/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -689,24 +689,30 @@ en:
title: Fetch UDID
index:
apple_tip: Use iPhone or iPad to scan the QR Code to install
macos_tip: System limited to detect macOS's chip. choose to use the iPhone and iPad scan code or press button to get the device UDID please.
nonapple_tip: :udid.index.apple_tip
fetch_udid: Get your UDID now
help:
title: Why need to install profile to fetch your UDID?
body_html: |
<p>
UDID is an abbreviation for Unique Device Identifier (UDID). The UDID is a feature provided by Apple to identify iOS devices.
Apple uses the UDID to communicate between Apple servers and individual iOS devices. This allows Apple to associate the
Apple uses the UDID to communicate between Apple servers and individual iOS devices or macOS on arm chip. This allows Apple to associate the
Apple ID and the Cloud ID with the corresponding iOS device. Each iOS device has an unique ID.
</p>
<p>
The UDID of your iOS devices is needed if you want to install alpha and beta iOS apps onto your device before they are released to the official apple store.
The UDID of your iOS devices or macOS on arm chip is needed if you want to install alpha and beta apps onto your device before they are released to the official apple store.
</p>
<strong>Following the steps:</strong>
<ol>
<li>Click "Accept" to download profile</li>
<li>Open "Setting.app" -> "Downloaded profile" -> "Fetch device's UDID" -> Install</li>
<li>After install it will open Safari and redirect a result page then delete the profile automatically</li>
<li>Click "Accept" to fetching the profile file.</li>
<li>Open installed Profile.
<ol>
<li>iOS: Open "Setting.app" -> "Downloaded profile" -> "Fetch device's UDID" -> Install.</li>
<li>macOS: Open the profile named <code>install.mobileconfig</code> then open "System Settings" and click "Profile" in left sidebar menu.</li>
</ol>
</li>
<li>After install it will open Safari and redirect a result page then delete the profile automatically.</li>
</ol>
show:
title: Device
Expand Down
8 changes: 7 additions & 1 deletion config/locales/zealot/zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,7 @@ zh-CN:
title: 设备 UDID
index:
apple_tip: 请使用 iPhone 或 iPad 扫描二维码获取
macos_tip: 系统限制无法检测 macOS 芯片类型,请自行选择使用 iPhone、iPad 扫码或点击下面按钮获取设备 UDID
nonapple_tip: :'udid.index.apple_tip'
fetch_udid: 获取设备 UDID
help:
Expand All @@ -696,7 +697,12 @@ zh-CN:
<strong>获取步骤</strong>
<ol>
<li>点击系统会弹窗的 “允许” 下载描述文件</li>
<li>打开手机 “设置” 找到顶部的 “已下载描述文件” 点击可以待安装的 “获取设备UDID” 的描述文件</li>
<li>打开描述文件
<ol>
<li>iOS: 打开手机 “设置” 找到顶部的 “已下载描述文件” 点击可以待安装的 “获取设备UDID” 的描述文件</li>
<li>macOS: 在下载路径双击打开 <code>install.mobileconfig</code>,打开系统设置点击左侧菜单的 "描述文件"</li>
</ol>
</li>
<li>一路点击 “安装” 并输入锁屏密码允许安装描述文件</li>
<li>安装之后描述文件会自动删除并跳转一个结果页面</li>
</ol>
Expand Down
Loading