Skip to content

Commit

Permalink
show correct message when port occupied
Browse files Browse the repository at this point in the history
  • Loading branch information
fuji246 committed May 31, 2022
1 parent 8750a2b commit a370e1d
Show file tree
Hide file tree
Showing 51 changed files with 53 additions and 6 deletions.
4 changes: 2 additions & 2 deletions LomoAgent.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_INJECT_BASE_ENTITLEMENTS = NO;
CODE_SIGN_INJECT_BASE_ENTITLEMENTS = YES;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1;
Expand All @@ -758,7 +758,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_INJECT_BASE_ENTITLEMENTS = NO;
CODE_SIGN_INJECT_BASE_ENTITLEMENTS = YES;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1;
Expand Down
4 changes: 2 additions & 2 deletions LomoAgent/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>cd4fc30</string>
<string>8750a2b</string>
<key>CFBundleVersion</key>
<string>2022_05_04.12_05_18.0.cd4fc30</string>
<string>2022_05_31.00_39_22.0.8750a2b</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.utilities</string>
<key>LSMinimumSystemVersion</key>
Expand Down
3 changes: 3 additions & 0 deletions LomoAgent/Localizable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ let errorUnsetBackupLocalized = NSLocalizedString("Error when unsetting backup d
let succUnsetBackupLocalized = NSLocalizedString("Unset backup directory succeed", comment: "")

let invalidPortLocalized = NSLocalizedString("Invalid port", comment: "")
let usedPortLocalized = NSLocalizedString("Port already used, please change another port", comment: "")
let invalidPortTipsLocalized = NSLocalizedString("The port should be a number in range [1024, 49151]", comment: "")
let homeDirRequiredLocalized = NSLocalizedString("Home directory required!", comment: "")
let passwordTooShortLocalized = NSLocalizedString("Password should be no less than 6 characters", comment: "")
Expand All @@ -32,6 +33,8 @@ let createUserSuccLocalized = NSLocalizedString("Create user succeed!", comment:
let createUserFailLocalized = NSLocalizedString("Create user failed!", comment: "")

let userTipsConfigureHomeDirAndWaitStart = NSLocalizedString("Please configure home directory for photo storage and wait for system start", comment: "")
let userTipsReportIssue = NSLocalizedString("Error! Please send log files to support@lomorage.com", comment: "")

let userTipsScanQRCode = NSLocalizedString("If the service can not be found automatically, you can use Lomorage APP to scan QR code to configure the service", comment: "")

let alertOk = NSLocalizedString("OK", comment: "")
Expand Down
19 changes: 17 additions & 2 deletions LomoAgent/PreferencesWindow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ class PreferencesWindow: NSWindowController, NSWindowDelegate {
let p = Int(port)
guard p != nil && p! >= 1024 && p! <= 49151 else {
dialogAlert(message: invalidPortLocalized, info: invalidPortTipsLocalized)
portTextField.stringValue = oldPort!
return
}
guard isPortOpen(port: UInt16(p!)) else {
userTipsLabel.textColor = .red
userTipsLabel.stringValue = usedPortLocalized
portTextField.stringValue = oldPort!
return
}
if oldPort != port {
Expand Down Expand Up @@ -333,8 +340,16 @@ class PreferencesWindow: NSWindowController, NSWindowDelegate {
self.imageQRCode.image = QRCodeImageWith(data: data, size: self.imageQRCode.frame.size.width)
}
} else {
self.userTipsLabel.textColor = .red
self.userTipsLabel.stringValue = userTipsConfigureHomeDirAndWaitStart
if let lomodPort = UInt16(self.portTextField.stringValue), !isPortOpen(port: lomodPort) {
self.userTipsLabel.textColor = .red
self.userTipsLabel.stringValue = usedPortLocalized
} else {
self.userTipsLabel.textColor = .red
self.userTipsLabel.stringValue = userTipsReportIssue
if let logDir = getLogDir() {
NSWorkspace.shared.open(URL(fileURLWithPath: logDir))
}
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions LomoAgent/StatusMenuController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ class StatusMenuController: NSObject {
} else {
DDLogError("Need set home directory first")
lomodTask = nil
preferencesWindow.userTipsLabel.textColor = .red
preferencesWindow.userTipsLabel.stringValue = userTipsConfigureHomeDirAndWaitStart
preferencesWindow.showWindow(nil)
NSApp.activate(ignoringOtherApps: true)
}
Expand Down
1 change: 1 addition & 0 deletions LomoAgent/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"Create user failed!" = "Create user failed!";

"Please configure home directory for photo storage and wait for system start" = "Please configure home directory for photo storage and wait for system start";
"Error! Please send log files to support@lomorage.com" = "Error! Please send log files to support@lomorage.com";
"If the service can not be found automatically, you can use Lomorage APP to scan QR code to configure the service" = "If the service can not be found automatically, you can use Lomorage APP to scan QR code to configure the service";

"OK" = "OK";
Expand Down
25 changes: 25 additions & 0 deletions LomoAgent/utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -317,3 +317,28 @@ func getPerferredLangWithoutRegionAndScript() -> String {
let items2 = langWithoutRegion.split(separator: "-")
return String(items2.first!)
}

func isPortOpen(port: in_port_t) -> Bool {

let socketFileDescriptor = socket(AF_INET, SOCK_STREAM, 0)
if socketFileDescriptor == -1 {
return false
}

var addr = sockaddr_in()
let sizeOfSockkAddr = MemoryLayout<sockaddr_in>.size
addr.sin_len = __uint8_t(sizeOfSockkAddr)
addr.sin_family = sa_family_t(AF_INET)
addr.sin_port = Int(OSHostByteOrder()) == OSLittleEndian ? _OSSwapInt16(port) : port
addr.sin_addr = in_addr(s_addr: inet_addr("0.0.0.0"))
addr.sin_zero = (0, 0, 0, 0, 0, 0, 0, 0)
var bind_addr = sockaddr()
memcpy(&bind_addr, &addr, Int(sizeOfSockkAddr))

if Darwin.bind(socketFileDescriptor, &bind_addr, socklen_t(sizeOfSockkAddr)) == -1 {
return false
}
let isOpen = listen(socketFileDescriptor, SOMAXCONN ) != -1
Darwin.close(socketFileDescriptor)
return isOpen
}
1 change: 1 addition & 0 deletions LomoAgent/zh-Hans.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"Create user failed!" = "创建用户失败!";

"Please configure home directory for photo storage and wait for system start" = "请设置用于照片存储的主目录,并等待系统启动";
"Error! Please send log files to support@lomorage.com" = "启动出错! 请将错误日志发送到support@lomorage.com";
"If the service can not be found automatically, you can use Lomorage APP to scan QR code to configure the service" = "如果不能自动发现服务,您也可以使用Lomorage手机应用扫码来配置服务";

"OK" = "确定";
Expand Down
Binary file not shown.
Binary file not shown.
Binary file modified dependencies/lomod/Contents/Frameworks/lomod/libImath-3_1.29.dylib
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified dependencies/lomod/Contents/Frameworks/lomod/libX11.6.dylib
Binary file not shown.
Binary file modified dependencies/lomod/Contents/Frameworks/lomod/libaom.3.dylib
Binary file not shown.
Binary file modified dependencies/lomod/Contents/Frameworks/lomod/libcfitsio.9.dylib
Binary file not shown.
Binary file modified dependencies/lomod/Contents/Frameworks/lomod/libcgif.0.dylib
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified dependencies/lomod/Contents/Frameworks/lomod/libfribidi.0.dylib
Binary file not shown.
Binary file modified dependencies/lomod/Contents/Frameworks/lomod/libgcc_s.1.dylib
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified dependencies/lomod/Contents/Frameworks/lomod/libltdl.7.dylib
Binary file not shown.
Binary file modified dependencies/lomod/Contents/Frameworks/lomod/libmatio.11.dylib
Binary file not shown.
Binary file modified dependencies/lomod/Contents/Frameworks/lomod/libnss3.dylib
Binary file not shown.
Binary file modified dependencies/lomod/Contents/Frameworks/lomod/libnssutil3.dylib
Binary file not shown.
Binary file modified dependencies/lomod/Contents/Frameworks/lomod/libomp.dylib
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified dependencies/lomod/Contents/Frameworks/lomod/libsmime3.dylib
Binary file not shown.
Binary file modified dependencies/lomod/Contents/Frameworks/lomod/libsqlite3.0.dylib
Binary file not shown.
Binary file modified dependencies/lomod/Contents/Frameworks/lomod/libssl3.dylib
Binary file not shown.
Binary file modified dependencies/lomod/Contents/Frameworks/lomod/libsz.2.dylib
Binary file not shown.
Binary file modified dependencies/lomod/Contents/Frameworks/lomod/libvips.42.dylib
Binary file not shown.
Binary file modified dependencies/lomod/Contents/Frameworks/lomod/libvmaf.1.dylib
Binary file not shown.
Binary file modified dependencies/lomod/Contents/Frameworks/lomod/libxml2.2.dylib
Binary file not shown.
Binary file modified dependencies/lomod/Contents/MacOS/lomod
Binary file not shown.

0 comments on commit a370e1d

Please sign in to comment.