Skip to content
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
40 changes: 18 additions & 22 deletions TypeSwitch/Sources/UI/Views/MenuBar/AppInfoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,30 @@ struct AppInfoView: View {

var body: some View {
Group {
Section {
Button {
updateMonitor.showUpdate(using: updaterController.updater)
} label: {
Label(
updateMonitor.menuTitle,
systemImage: "arrow.triangle.2.circlepath"
)
}
.disabled(!updateMonitor.isMenuActionEnabled)
Button {
updateMonitor.showUpdate(using: updaterController.updater)
} label: {
Label(
updateMonitor.menuTitle,
systemImage: "arrow.triangle.2.circlepath"
)
}
.disabled(!updateMonitor.isMenuActionEnabled)

Button {
AppInfoService.openGitHubRepository()
} label: {
Label(TypeSwitchStrings.Menu.githubRepository, systemImage: "link")
}
Button {
AppInfoService.openGitHubRepository()
} label: {
Label(TypeSwitchStrings.Menu.githubRepository, systemImage: "link")
}

Divider()

Section {
Button(role: .destructive) {
NSApplication.shared.terminate(nil)
} label: {
Label(TypeSwitchStrings.Menu.quit, systemImage: "power")
}
.keyboardShortcut("q", modifiers: .command)
Button(role: .destructive) {
NSApplication.shared.terminate(nil)
} label: {
Label(TypeSwitchStrings.Menu.quit, systemImage: "power")
}
.keyboardShortcut("q", modifiers: .command)
}
}
}
62 changes: 30 additions & 32 deletions TypeSwitch/Sources/UI/Views/MenuBar/ConfiguredAppsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,42 @@ struct ConfiguredAppsView: View {

var body: some View {
if !store.configuredApps.isEmpty {
Section {
Menu {
if store.hasMissingInputMethodRules {
Button(role: .destructive) {
if MenuConfirmation.confirm(
title: TypeSwitchStrings.InputMethod.ClearMissingConfirmation.title,
message: TypeSwitchStrings.InputMethod.ClearMissingConfirmation.message,
confirmButton: TypeSwitchStrings.InputMethod.ClearMissingConfirmation.confirm
) {
store.send(.view(.removeMissingInputMethodRulesTapped))
}
} label: {
Label(
TypeSwitchStrings.InputMethod.clearMissingConfiguration,
systemImage: "trash"
)
Menu {
if store.hasMissingInputMethodRules {
Button(role: .destructive) {
if MenuConfirmation.confirm(
title: TypeSwitchStrings.InputMethod.ClearMissingConfirmation.title,
message: TypeSwitchStrings.InputMethod.ClearMissingConfirmation.message,
confirmButton: TypeSwitchStrings.InputMethod.ClearMissingConfirmation.confirm
) {
store.send(.view(.removeMissingInputMethodRulesTapped))
}

Divider()
} label: {
Label(
TypeSwitchStrings.InputMethod.clearMissingConfiguration,
systemImage: "trash"
)
}

ForEach(store.configuredApps) { item in
AppRowView(
item: item,
inputMethods: store.inputMethods,
onIgnore: {
store.send(.view(.ignoreAppTapped(item.appInfo)))
}
) { strategy in
store.send(.view(.setStrategy(bundleId: item.bundleId, strategy: strategy)))
Divider()
}

ForEach(store.configuredApps) { item in
AppRowView(
item: item,
inputMethods: store.inputMethods,
onIgnore: {
store.send(.view(.ignoreAppTapped(item.appInfo)))
}
) { strategy in
store.send(.view(.setStrategy(bundleId: item.bundleId, strategy: strategy)))
}
} label: {
Label(
TypeSwitchStrings.Apps.Section.configuredCount(store.configuredApps.count),
systemImage: "list.bullet.rectangle"
)
}
} label: {
Label(
TypeSwitchStrings.Apps.Section.configuredCount(store.configuredApps.count),
systemImage: "list.bullet.rectangle"
)
}
}
}
Expand Down
48 changes: 23 additions & 25 deletions TypeSwitch/Sources/UI/Views/MenuBar/IgnoredAppsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,38 @@ struct IgnoredAppsView: View {

var body: some View {
if !store.ignoredAppsForMenu.isEmpty {
Section {
Menu {
Section {
ForEach(store.ignoredAppsForMenu) { app in
Button {
store.send(.view(.restoreIgnoredAppTapped(bundleId: app.bundleId)))
} label: {
Label {
Text(app.name)
} icon: {
app.icon
}
Menu {
Section {
ForEach(store.ignoredAppsForMenu) { app in
Button {
store.send(.view(.restoreIgnoredAppTapped(bundleId: app.bundleId)))
} label: {
Label {
Text(app.name)
} icon: {
app.icon
}
}
} header: {
Text(TypeSwitchStrings.Apps.Ignored.restoreHint)
}
} header: {
Text(TypeSwitchStrings.Apps.Ignored.restoreHint)
}

Divider()
Divider()

Button {
store.send(.view(.restoreAllIgnoredAppsTapped))
} label: {
Label(
TypeSwitchStrings.Apps.Ignored.restoreAll,
systemImage: "arrow.uturn.backward"
)
}
Button {
store.send(.view(.restoreAllIgnoredAppsTapped))
} label: {
Label(
TypeSwitchStrings.Apps.Ignored.menuTitle(store.ignoredAppsForMenu.count),
systemImage: "eye.slash"
TypeSwitchStrings.Apps.Ignored.restoreAll,
systemImage: "arrow.uturn.backward"
)
}
} label: {
Label(
TypeSwitchStrings.Apps.Ignored.menuTitle(store.ignoredAppsForMenu.count),
systemImage: "eye.slash"
)
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions TypeSwitch/Sources/UI/Views/MenuBar/MenuBarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ struct MenuBarView: View {
Group {
CurrentAppView(store: store)
RunningAppsView(store: store)

if store.currentAppMenuItem != nil
|| !store.runningUnconfiguredMenuItems.isEmpty
|| !store.runningConfiguredMenuItems.isEmpty
{
Divider()
}

ConfiguredAppsView(store: store)
UnavailableAppsView(store: store)
IgnoredAppsView(store: store)
Expand Down
70 changes: 34 additions & 36 deletions TypeSwitch/Sources/UI/Views/MenuBar/SettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,45 @@ struct SettingsView: View {
@Bindable var store: StoreOf<AppFeature>

var body: some View {
Section {
Menu {
InputMethodStrategyMenuContent(
context: .fallbackRule,
strategy: store.fallbackStrategy,
inputMethods: store.inputMethods,
defaultOptionLabel: TypeSwitchStrings.InputMethod.fallbackDefaultOption,
followLastOptionLabel: TypeSwitchStrings.InputMethod.followLastEmptyOption
) { strategy in
store.send(.view(.setFallbackStrategy(strategy)))
}
} label: {
Label(
TypeSwitchStrings.Settings.Fallback.defaultInputMethod,
systemImage: "keyboard"
)
if let selectedLabel = store.fallbackSelectedLabel {
Text(selectedLabel)
.foregroundStyle(store.fallbackHasMissingInputMethod ? .secondary : .primary)
}
Menu {
InputMethodStrategyMenuContent(
context: .fallbackRule,
strategy: store.fallbackStrategy,
inputMethods: store.inputMethods,
defaultOptionLabel: TypeSwitchStrings.InputMethod.fallbackDefaultOption,
followLastOptionLabel: TypeSwitchStrings.InputMethod.followLastEmptyOption
) { strategy in
store.send(.view(.setFallbackStrategy(strategy)))
}
} label: {
Label(
TypeSwitchStrings.Settings.Fallback.defaultInputMethod,
systemImage: "keyboard"
)
if let selectedLabel = store.fallbackSelectedLabel {
Text(selectedLabel)
.foregroundStyle(store.fallbackHasMissingInputMethod ? .secondary : .primary)
}
}

Toggle(
TypeSwitchStrings.Settings.General.autoLaunch,
isOn: Binding(
get: { store.launchAtLoginEnabled },
set: { store.send(.view(.setLaunchAtLogin($0))) }
)
Toggle(
TypeSwitchStrings.Settings.General.autoLaunch,
isOn: Binding(
get: { store.launchAtLoginEnabled },
set: { store.send(.view(.setLaunchAtLogin($0))) }
)
.toggleStyle(.checkbox)
)
.toggleStyle(.checkbox)

if store.launchAtLoginRequiresApproval {
Text(TypeSwitchStrings.Settings.General.autoLaunchRequiresApproval)
.font(.footnote)
.foregroundStyle(.secondary)
if store.launchAtLoginRequiresApproval {
Text(TypeSwitchStrings.Settings.General.autoLaunchRequiresApproval)
.font(.footnote)
.foregroundStyle(.secondary)

Button {
LaunchAtLoginService.openSystemSettingsLoginItems()
} label: {
Label(TypeSwitchStrings.Settings.General.openLoginItems, systemImage: "gear")
}
Button {
LaunchAtLoginService.openSystemSettingsLoginItems()
} label: {
Label(TypeSwitchStrings.Settings.General.openLoginItems, systemImage: "gear")
}
}
}
Expand Down
58 changes: 28 additions & 30 deletions TypeSwitch/Sources/UI/Views/MenuBar/SwitchStatisticsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,41 @@ struct SwitchStatisticsView: View {
let store: StoreOf<AppFeature>

var body: some View {
Section {
Menu {
if store.switchStatisticsItems.isEmpty {
Text(TypeSwitchStrings.SwitchStatistics.empty)
.foregroundStyle(.secondary)
} else {
ForEach(store.switchStatisticsItems) { item in
Button {} label: {
if item.path != nil {
AppInfo(bundleId: item.bundleId, name: item.name, path: item.path).icon
}
Text(item.name)
Text(TypeSwitchStrings.SwitchStatistics.appCount(item.count))
Menu {
if store.switchStatisticsItems.isEmpty {
Text(TypeSwitchStrings.SwitchStatistics.empty)
.foregroundStyle(.secondary)
} else {
ForEach(store.switchStatisticsItems) { item in
Button {} label: {
if item.path != nil {
AppInfo(bundleId: item.bundleId, name: item.name, path: item.path).icon
}
.disabled(true)
Text(item.name)
Text(TypeSwitchStrings.SwitchStatistics.appCount(item.count))
}
.disabled(true)
}

Divider()
Divider()

Button(role: .destructive) {
if MenuConfirmation.confirm(
title: TypeSwitchStrings.SwitchStatistics.ClearConfirmation.title,
message: TypeSwitchStrings.SwitchStatistics.ClearConfirmation.message,
confirmButton: TypeSwitchStrings.SwitchStatistics.ClearConfirmation.confirm
) {
store.send(.view(.clearSwitchStatisticsTapped))
}
} label: {
Label(TypeSwitchStrings.SwitchStatistics.clear, systemImage: "trash")
Button(role: .destructive) {
if MenuConfirmation.confirm(
title: TypeSwitchStrings.SwitchStatistics.ClearConfirmation.title,
message: TypeSwitchStrings.SwitchStatistics.ClearConfirmation.message,
confirmButton: TypeSwitchStrings.SwitchStatistics.ClearConfirmation.confirm
) {
store.send(.view(.clearSwitchStatisticsTapped))
}
} label: {
Label(TypeSwitchStrings.SwitchStatistics.clear, systemImage: "trash")
}
} label: {
Label(
TypeSwitchStrings.SwitchStatistics.menuTitle(store.totalSuccessfulSwitchCount),
systemImage: "chart.bar"
)
}
} label: {
Label(
TypeSwitchStrings.SwitchStatistics.menuTitle(store.totalSuccessfulSwitchCount),
systemImage: "chart.bar"
)
}
}
}
Loading
Loading