Skip to content

Commit

Permalink
Merge pull request #34 from wflixu/next
Browse files Browse the repository at this point in the history
feat: editable new file type
  • Loading branch information
wflixu authored Nov 19, 2024
2 parents d5b83b5 + fd9c2bb commit 075cdeb
Show file tree
Hide file tree
Showing 12 changed files with 339 additions and 82 deletions.
14 changes: 11 additions & 3 deletions FinderSyncExt/FinderSyncExt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,19 @@ class FinderSyncExt: FIFinderSync {
menuItem.toolTip = "\(item.name)"
menuItem.tag = getUniqueTag(for: item.id)

if let img = NSImage(named: item.icon) {
menuItem.image = img
if let app = item.openApp {
menuItem.image = NSWorkspace.shared.icon(forFile: app.path)
} else {
logger.info("")
if !item.icon.starts(with: "icon-") {
menuItem.image = NSImage(systemSymbolName: item.icon, accessibilityDescription: item.icon)!
} else {
if let img = NSImage(named: item.icon) {
menuItem.image = img
}
}

}


submenu.addItem(menuItem)
}
Expand Down
24 changes: 12 additions & 12 deletions RClick.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 11.18.2;
CURRENT_PROJECT_VERSION = 11.19.2;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"RClick/Preview Content\"";
DEVELOPMENT_TEAM = 4L3563XCBN;
Expand All @@ -529,8 +529,8 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 15.0;
MARKETING_VERSION = 1.4.5;
MACOSX_DEPLOYMENT_TARGET = 14.6;
MARKETING_VERSION = 1.4.6;
PRODUCT_BUNDLE_IDENTIFIER = cn.wflixu.RClick;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -549,7 +549,7 @@
CODE_SIGN_IDENTITY = "3rd Party Mac Developer Application";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 11.18.2;
CURRENT_PROJECT_VERSION = 11.19.2;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_ASSET_PATHS = "\"RClick/Preview Content\"";
DEVELOPMENT_TEAM = "";
Expand All @@ -566,8 +566,8 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 15.0;
MARKETING_VERSION = 1.4.5;
MACOSX_DEPLOYMENT_TARGET = 14.6;
MARKETING_VERSION = 1.4.6;
PRODUCT_BUNDLE_IDENTIFIER = cn.wflixu.RClick;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = mac_app_rclick_distribution_store;
Expand All @@ -584,7 +584,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 11.18.2;
CURRENT_PROJECT_VERSION = 11.19.2;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = 4L3563XCBN;
ENABLE_HARDENED_RUNTIME = YES;
Expand All @@ -598,8 +598,8 @@
"@executable_path/../Frameworks",
"@executable_path/../../../../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 15.0;
MARKETING_VERSION = 1.4.5;
MACOSX_DEPLOYMENT_TARGET = 14.6;
MARKETING_VERSION = 1.4.6;
PRODUCT_BUNDLE_IDENTIFIER = cn.wflixu.RClick.FinderSyncExt;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
Expand All @@ -616,7 +616,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "3rd Party Mac Developer Application";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 11.18.2;
CURRENT_PROJECT_VERSION = 11.19.2;
DEAD_CODE_STRIPPING = YES;
DEVELOPMENT_TEAM = "";
"DEVELOPMENT_TEAM[sdk=macosx*]" = 4L3563XCBN;
Expand All @@ -631,8 +631,8 @@
"@executable_path/../Frameworks",
"@executable_path/../../../../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 15.0;
MARKETING_VERSION = 1.4.5;
MACOSX_DEPLOYMENT_TARGET = 14.6;
MARKETING_VERSION = 1.4.6;
PRODUCT_BUNDLE_IDENTIFIER = cn.wflixu.RClick.FinderSyncExt;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
16 changes: 16 additions & 0 deletions RClick/AppState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ class AppState: ObservableObject {
logger.info("save error: \(error.localizedDescription)")
}
}




@MainActor
func updateApp(id: String, itemName: String, arguments: [String], environment: [String: String]) {
Expand All @@ -82,6 +85,19 @@ class AppState: ObservableObject {
})
}

@MainActor func addNewFile(_ item: NewFile) {
logger.info("start add new file type")
newFiles.append(item)

do {
try save()
// 使用 result
} catch {
// 处理错误
logger.info("save error: \(error.localizedDescription)")
}
}

func getActionItem(rid: String) -> RCAction? {
actions.first(where: { rcAtion in
rcAtion.id == rid
Expand Down
33 changes: 33 additions & 0 deletions RClick/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@
}
}
}
},
"Add New File Type" : {

},
"Arguments" : {

Expand All @@ -128,6 +131,9 @@
},
"Cancel" : {

},
"Change App" : {

},
"Copy Path" : {
"extractionState" : "manual",
Expand All @@ -145,6 +151,9 @@
}
}
}
},
"Default Open App" : {

},
"Delete Direct" : {
"extractionState" : "manual",
Expand All @@ -168,6 +177,9 @@
},
"Edit App Properties" : {

},
"Edit File Type" : {

},
"Enable extension" : {
"localizations" : {
Expand All @@ -184,6 +196,12 @@
},
"Environment:" : {

},
"Extension" : {

},
"File Extension (e.g., .txt)" : {

},
"Format: KEY=VALUE, one per line" : {

Expand All @@ -198,6 +216,9 @@
}
}
}
},
"Icon" : {

},
"Invalid Folder Selection" : {
"localizations" : {
Expand All @@ -218,6 +239,9 @@
}
}
}
},
"Name" : {

},
"New File" : {
"localizations" : {
Expand Down Expand Up @@ -274,6 +298,9 @@
}
}
}
},
"Preview:" : {

},
"Quit" : {
"localizations" : {
Expand Down Expand Up @@ -329,6 +356,9 @@
},
"Save" : {

},
"Select App" : {

},
"Settings" : {
"localizations" : {
Expand All @@ -345,6 +375,9 @@
}
}
}
},
"SF Symbol name or custom icon" : {

},
"The operation of the menu can only be executed in authorized folders" : {
"localizations" : {
Expand Down
5 changes: 4 additions & 1 deletion RClick/Model/RCBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ extension RCAction {
static let deleteDirect = RCAction(id: "delete-direct", name: "Delete Direct", idx: 1, icon: "trash")
}


// New File Type
struct NewFile: RCBase {
static func == (lhs: NewFile, rhs: NewFile) -> Bool {
lhs.id == rhs.id
Expand All @@ -166,8 +168,9 @@ struct NewFile: RCBase {
var idx: Int
var icon: String
var id: String
var openApp: URL?

init(ext: String, name: String, enabled: Bool = true, idx: Int, icon: String, id: String = UUID().uuidString) {
init(ext: String, name: String, enabled: Bool = true, idx: Int, icon: String = "document", id: String = UUID().uuidString) {
self.ext = ext
self.name = name
self.enabled = enabled
Expand Down
7 changes: 6 additions & 1 deletion RClick/Settings/ActionSettingsTabView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import SwiftUI
struct ActionSettingsTabView: View {
@EnvironmentObject var appState: AppState

let messager = Messager.shared

var body: some View {
VStack {
HStack {
Expand All @@ -22,7 +24,7 @@ struct ActionSettingsTabView: View {
.font(.body)
}
}

List {
ForEach($appState.actions) { $item in
HStack {
Expand All @@ -35,9 +37,12 @@ struct ActionSettingsTabView: View {
Toggle("", isOn: $item.enabled)
.onChange(of: item.enabled) {
appState.toggleActionItem()
messager.sendMessage(name: "running", data: MessagePayload(action: "running", target: []))
}
.toggleStyle(.switch)
}
.padding(.top, 12)
.padding(.bottom, 4)
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions RClick/Settings/AppsSettingsTabView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ struct AppsSettingsTabView: View {
@State private var editingArguments: String = ""
@State private var editingEnvironment: String = ""

let messager = Messager.shared

var body: some View {
ZStack {
VStack {
Expand Down Expand Up @@ -224,6 +226,7 @@ struct AppsSettingsTabView: View {
arguments: editingArguments.components(separatedBy: ";").map { $0.trimmingCharacters(in: .whitespaces) }.filter { !$0.isEmpty },
environment: parseEnvironmentVariables(editingEnvironment)
)
messager.sendMessage(name: "running", data: MessagePayload(action: "running", target: []))
}

@MainActor private func deleteApp(_ appItem: OpenWithApp) {
Expand All @@ -233,5 +236,6 @@ struct AppsSettingsTabView: View {
expandedAppId = nil
}
}
messager.sendMessage(name: "running", data: MessagePayload(action: "running", target: []))
}
}
Loading

0 comments on commit 075cdeb

Please sign in to comment.