Skip to content

Commit

Permalink
create the output directory if it does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
lihaoyun6 committed Aug 15, 2024
1 parent 0a5a0b5 commit f65d0d8
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 7 deletions.
25 changes: 21 additions & 4 deletions QuickRecorder.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
181724052BE3BEA600F5F539 /* Sparkle in Frameworks */ = {isa = PBXBuildFile; productRef = 181724042BE3BEA600F5F539 /* Sparkle */; };
181724082BE3BF7300F5F539 /* Sparkle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 181724072BE3BF7300F5F539 /* Sparkle.swift */; };
184506CE2C69213400AFDA45 /* MatrixColorSelector in Frameworks */ = {isa = PBXBuildFile; productRef = 184506CD2C69213400AFDA45 /* MatrixColorSelector */; };
184CAEC72BDCCC2300D61D57 /* AVContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 184CAEC62BDCCC2300D61D57 /* AVContext.swift */; };
184CAEC92BDDEC6800D61D57 /* AppBlockSelector.swift in Sources */ = {isa = PBXBuildFile; fileRef = 184CAEC82BDDEC6800D61D57 /* AppBlockSelector.swift */; };
1862BF8D2BD5494E003ED522 /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 1862BF8F2BD5494E003ED522 /* Credits.rtf */; };
Expand Down Expand Up @@ -75,6 +76,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
184506CE2C69213400AFDA45 /* MatrixColorSelector in Frameworks */,
18FDFC912BDA4DB30020E685 /* KeyboardShortcuts in Frameworks */,
181724052BE3BEA600F5F539 /* Sparkle in Frameworks */,
18F40B492BFB988A00F0AC70 /* SwiftLAME in Frameworks */,
Expand Down Expand Up @@ -177,6 +179,7 @@
18FDFC902BDA4DB30020E685 /* KeyboardShortcuts */,
181724042BE3BEA600F5F539 /* Sparkle */,
18F40B482BFB988A00F0AC70 /* SwiftLAME */,
184506CD2C69213400AFDA45 /* MatrixColorSelector */,
);
productName = QuickRecorder;
productReference = 18D3BDE72BCE5DC1006CFFC0 /* QuickRecorder.app */;
Expand Down Expand Up @@ -212,6 +215,7 @@
18FDFC8F2BDA4DB30020E685 /* XCRemoteSwiftPackageReference "KeyboardShortcuts" */,
181724032BE3BEA600F5F539 /* XCRemoteSwiftPackageReference "Sparkle" */,
18F40B472BFB988A00F0AC70 /* XCRemoteSwiftPackageReference "SwiftLAME" */,
184506CC2C69213400AFDA45 /* XCRemoteSwiftPackageReference "MatrixColorSelector" */,
);
productRefGroup = 18D3BDE82BCE5DC1006CFFC0 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -428,7 +432,7 @@
CODE_SIGN_ENTITLEMENTS = QuickRecorder/QuickRecorder.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 145;
CURRENT_PROJECT_VERSION = 146;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"QuickRecorder/Preview Content\"";
DEVELOPMENT_TEAM = L4T783637F;
Expand All @@ -446,7 +450,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 12.3;
MARKETING_VERSION = 1.4.5;
MARKETING_VERSION = 1.4.6;
PRODUCT_BUNDLE_IDENTIFIER = com.lihaoyun6.QuickRecorder;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand All @@ -462,7 +466,7 @@
CODE_SIGN_ENTITLEMENTS = QuickRecorder/QuickRecorder.entitlements;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 145;
CURRENT_PROJECT_VERSION = 146;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"QuickRecorder/Preview Content\"";
DEVELOPMENT_TEAM = L4T783637F;
Expand All @@ -480,7 +484,7 @@
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 12.3;
MARKETING_VERSION = 1.4.5;
MARKETING_VERSION = 1.4.6;
PRODUCT_BUNDLE_IDENTIFIER = com.lihaoyun6.QuickRecorder;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
Expand Down Expand Up @@ -520,6 +524,14 @@
minimumVersion = 2.6.0;
};
};
184506CC2C69213400AFDA45 /* XCRemoteSwiftPackageReference "MatrixColorSelector" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/lihaoyun6/MatrixColorSelector.git";
requirement = {
branch = main;
kind = branch;
};
};
18F40B472BFB988A00F0AC70 /* XCRemoteSwiftPackageReference "SwiftLAME" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/hidden-spectrum/SwiftLAME.git";
Expand All @@ -544,6 +556,11 @@
package = 181724032BE3BEA600F5F539 /* XCRemoteSwiftPackageReference "Sparkle" */;
productName = Sparkle;
};
184506CD2C69213400AFDA45 /* MatrixColorSelector */ = {
isa = XCSwiftPackageProductDependency;
package = 184506CC2C69213400AFDA45 /* XCRemoteSwiftPackageReference "MatrixColorSelector" */;
productName = MatrixColorSelector;
};
18F40B482BFB988A00F0AC70 /* SwiftLAME */ = {
isa = XCSwiftPackageProductDependency;
package = 18F40B472BFB988A00F0AC70 /* XCRemoteSwiftPackageReference "SwiftLAME" */;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"originHash" : "1b1d5eee536d7383fd89cd017b59783f56323dd3ee0eaa42a8fdfe9a288c991c",
"pins" : [
{
"identity" : "keyboardshortcuts",
Expand All @@ -9,6 +10,15 @@
"version" : "2.0.0"
}
},
{
"identity" : "matrixcolorselector",
"kind" : "remoteSourceControl",
"location" : "https://github.com/lihaoyun6/MatrixColorSelector.git",
"state" : {
"branch" : "main",
"revision" : "941dcf7e3f9f3e93db5eb4889b4645fb1f0941f6"
}
},
{
"identity" : "sparkle",
"kind" : "remoteSourceControl",
Expand All @@ -27,5 +37,5 @@
}
}
],
"version" : 2
"version" : 3
}
18 changes: 18 additions & 0 deletions QuickRecorder/RecordEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,24 @@ extension AppDelegate {
case "audio": SCContext.streamType = .systemaudio
default: return // if we don't even know what to record I don't think we should even try
}
var isDirectory: ObjCBool = false
let fileManager = FileManager.default
let outputPath = ud.string(forKey: "saveDirectory")!
if fileManager.fileExists(atPath: outputPath, isDirectory: &isDirectory) {
if !isDirectory.boolValue {
SCContext.streamType = nil
_ = createAlert(title: "Failed to Record".local, message: "The output path is a file instead of a folder!".local, button1: "OK").runModal()
return
}
} else {
do {
try fileManager.createDirectory(atPath: outputPath, withIntermediateDirectories: true, attributes: nil)
} catch {
SCContext.streamType = nil
_ = createAlert(title: "Failed to Record".local, message: "Unable to create output folder!".local, button1: "OK").runModal()
return
}
}
//statusBarItem.menu = nil
SCContext.updateAudioSettings()
// file preparation
Expand Down
5 changes: 3 additions & 2 deletions QuickRecorder/ViewModel/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import SwiftUI
import Sparkle
import ServiceManagement
import KeyboardShortcuts
import MatrixColorSelector

struct SettingsView: View {
@Environment(\.presentationMode) var presentationMode
Expand Down Expand Up @@ -122,7 +123,7 @@ struct SettingsView: View {
.padding([.leading, .trailing], 10)
.disabled(!isMacOS14)
}.frame(maxWidth: .infinity).padding(.top, 10)
ColorPicker("Set custom background color:", selection: $userColor)
MatrixColorSelector("Set custom background color:", selection: $userColor)
.padding([.leading, .trailing], 10)
.onChange(of: userColor) { userColor in ud.setColor(userColor, forKey: "userColor") }
Toggle(isOn: $trimAfterRecord) { Text("Open video trimmer after recording") }
Expand Down Expand Up @@ -262,7 +263,7 @@ struct SettingsView: View {
openPanel.allowedContentTypes = []
openPanel.allowsOtherFileTypes = false
if openPanel.runModal() == NSApplication.ModalResponse.OK {
saveDirectory = openPanel.urls.first?.path
if let path = openPanel.urls.first?.path { saveDirectory = path }
}
}

Expand Down
4 changes: 4 additions & 0 deletions QuickRecorder/zh-Hans.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@
"Stop Play" = "停止播放";
"Export" = "导出";
"Export as MP3" = "导出为 MP3";
"Show Colors..." = "显示颜色…";
"Failed to Record" = "录制失败";
"Unable to create output folder!" = "无法创建输出文件夹!";
"The output path is a file instead of a folder!"= "所选的保存位置是一个文件, 应该是文件夹!";

// Please don't translate the following warning strings, it will make it difficult for me to read the logs
"failed to fetch file for size indicator: %@" = "获取文件大小失败: ";
Expand Down

0 comments on commit f65d0d8

Please sign in to comment.