Skip to content

Commit

Permalink
Merge pull request #66 from 3colorr/v1.1.0
Browse files Browse the repository at this point in the history
V1.1.0
  • Loading branch information
3colorr authored Sep 22, 2023
2 parents fa92b51 + 6852a8c commit f7641ee
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 31 deletions.
41 changes: 34 additions & 7 deletions Mizuame/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ struct ContentView: View {
// But, it may not be a feature that this app need.
//@FetchRequest(something)

let delegate: AppDelegate

@ObservedObject var printer = PrinterModel()


@AppStorage(SettingKeys.StickyNote().keyPinNote) private var isPinNote: Bool = SettingKeys.StickyNote().initialPinNote

@AppStorage(SettingKeys.Menubar().keySavingMessage) private var isShowSavingMessage: Bool = SettingKeys.Menubar().initialSavingMessage

@AppStorage(SettingKeys.StickyNote().keyWidth) private var width: Int = SettingKeys.StickyNote().initialWidth
Expand All @@ -35,13 +39,12 @@ struct ContentView: View {
@State private var userAction: MessagebarEnum = .NONE

@State private var isExecutableSave: Bool = true

private let delegate = AppDelegate()


private let io: DataIO
private var data: StickyNote

init() {
init(delegate: AppDelegate) {
self.delegate = delegate
self.io = DataIO()

if let data = self.io.readStickyNote() {
Expand Down Expand Up @@ -86,6 +89,20 @@ struct ContentView: View {
Spacer()
.layoutPriority(1)

if isPinNote {
Image(systemName: "pin")
.foregroundColor(Color.red)
.onTapGesture {
togglePinningNote()
}
} else {
Image(systemName: "pin.slash")
.foregroundColor(Color(bodyForegroundTheme))
.onTapGesture {
togglePinningNote()
}
}

Image(systemName: "eraser")
.foregroundColor(Color(bodyForegroundTheme))
.onTapGesture {
Expand Down Expand Up @@ -140,7 +157,7 @@ struct ContentView: View {
Task {
do {
isExecutableSave = false
try await Task.sleep(nanoseconds: 3 * 1000000000)
try await Task.sleep(nanoseconds: 15 * 100000000)
saveData()

} catch {
Expand Down Expand Up @@ -186,10 +203,20 @@ struct ContentView: View {

isExecutableSave = true
}

private func togglePinningNote() {
isPinNote.toggle()

if isPinNote {
delegate.enablePinning()
} else {
delegate.disablePinning()
}
}
}

struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
ContentView(delegate: AppDelegate())
}
}
43 changes: 39 additions & 4 deletions Mizuame/MizuameApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ struct Mizuame: App {
}
}

class AppDelegate: NSObject, NSApplicationDelegate {
class AppDelegate: NSObject, NSApplicationDelegate, ObservableObject {

@AppStorage(SettingKeys.UserConfirm().keyAgreement) private var viewState: Int = SettingKeys.UserConfirm().initialViewState

@AppStorage(SettingKeys.StickyNote().keyPinNote) private var isPinNote: Bool = SettingKeys.StickyNote().initialPinNote

private var statusItem: NSStatusItem?
private var popover: NSPopover = NSPopover()

private var isOpenNote: Bool = true

func applicationDidFinishLaunching(_ notification: Notification) {
NSApp.setActivationPolicy(.accessory)

Expand All @@ -43,8 +47,13 @@ class AppDelegate: NSObject, NSApplicationDelegate {
button.sendAction(on: [.leftMouseUp, .rightMouseUp])
}

popover.contentViewController = NSHostingController(rootView: ContentView())
popover.behavior = .transient
popover.contentViewController = NSHostingController(rootView: ContentView(delegate: self))

if isPinNote {
enablePinning()
} else {
disablePinning()
}
}

@objc func showPopover(sender: NSStatusBarButton) {
Expand Down Expand Up @@ -82,7 +91,23 @@ class AppDelegate: NSObject, NSApplicationDelegate {
unwrappedStatusItem.menu = nil

} else if currentEvent.type == NSEvent.EventType.leftMouseUp {
popover.show(relativeTo: sender.bounds, of: sender, preferredEdge: NSRectEdge.maxY)

if isPinNote {

isOpenNote.toggle()

if isOpenNote {
popover.show(relativeTo: sender.bounds, of: sender, preferredEdge: NSRectEdge.maxY)
} else {
popover.close()
}
} else {
popover.show(relativeTo: sender.bounds, of: sender, preferredEdge: NSRectEdge.maxY)

// Initialize "isOpenNote" when "pin a note" is enable next time.
isOpenNote = false
}

popover.contentViewController?.view.window?.makeKey()
}
}
Expand All @@ -100,4 +125,14 @@ class AppDelegate: NSObject, NSApplicationDelegate {
// The settings move to front.
NSApp.activate(ignoringOtherApps: true)
}

// when a user tap the desktop, close note if popover.behavior is .transient.
// when a user tap the desktop, NOT close note if popover.behavior is .applicationDefined.
func enablePinning() {
popover.behavior = .applicationDefined
}

func disablePinning() {
popover.behavior = .transient
}
}
3 changes: 3 additions & 0 deletions Mizuame/Settings/SettingKeys.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ struct SettingKeys {
let maxWidth: Int = 1000
let minHeight: Int = 80
let maxHeight: Int = 1000

let keyPinNote: String = "stickyNotePin"
let initialPinNote: Bool = false
}

struct ThemePalette {
Expand Down
38 changes: 37 additions & 1 deletion Mizuame/Settings/TabGeneral.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ import StoreKit

struct TabGeneral: View {

@EnvironmentObject var delegate: AppDelegate

@AppStorage(SettingKeys.Menubar().keySavingMessage) private var isShowSavingMessage: Bool = SettingKeys.Menubar().initialSavingMessage

@AppStorage(SettingKeys.StickyNote().keyPinNote) private var isPinNote: Bool = SettingKeys.StickyNote().initialPinNote

var body: some View {
VStack(alignment: .leading) {
HStack {
Expand All @@ -20,6 +24,33 @@ struct TabGeneral: View {
Text("settings.tab.general.menubar.saving")
}
}

HStack {
Text("settings.tab.general.note")
Toggle(isOn: $isPinNote) {
Text("settings.tab.general.note.pin")
}
.onChange(of: isPinNote) { isPinning in
if isPinning {
delegate.enablePinning()
} else {
delegate.disablePinning()
}
}
}

Spacer()

HStack {
Text("settings.tab.general.reset.title")
Button(action: {
self.isShowSavingMessage = SettingKeys.Menubar().initialSavingMessage
self.isPinNote = SettingKeys.StickyNote().initialPinNote
}) {
Text("settings.tab.general.reset.button.caption")
.padding(EdgeInsets(top: 2, leading: 10, bottom: 2, trailing: 10))
}
}
}
.frame(width: 400, height: 200)
.padding(EdgeInsets(top: 10, leading: 0, bottom: 20, trailing: 0))
Expand All @@ -28,6 +59,11 @@ struct TabGeneral: View {

struct TabStickyNote_Previews: PreviewProvider {
static var previews: some View {
TabGeneral()
let localizations = ["en", "ja"]
ForEach(localizations, id: \.self) { lang in
TabGeneral()
.previewDisplayName("lcal:\(lang)")
.environment(\.locale, .init(identifier: lang))
}
}
}
32 changes: 20 additions & 12 deletions Mizuame/Settings/TabHelp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,20 @@ struct TabHelp: View {
var body: some View {
ScrollView {
VStack(alignment: .leading, spacing: 10) {
Text("settings.tab.help.greeting")
.bold()

Text("settings.tab.help.introduce")

Text("settings.tab.help.attention.title")
.bold()

Text("settings.tab.help.attention.body")

Text("settings.tab.help.menu.title")
.bold()
VStack(alignment: .leading, spacing: 10) {
Text("settings.tab.help.greeting")
.bold()

Text("settings.tab.help.introduce")

Text("settings.tab.help.attention.title")
.bold()

Text("settings.tab.help.attention.body")

Text("settings.tab.help.menu.title")
.bold()
}

HStack {
Image(systemName: "power")
Expand All @@ -36,6 +38,12 @@ struct TabHelp: View {
Text("settings.tab.help.menu.preference.description")
}

HStack {
Image(systemName: "pin")
.padding(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 10))
Text("settings.tab.help.menu.pin.description")
}

HStack {
Image(systemName: "eraser")
.padding(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 10))
Expand Down
4 changes: 2 additions & 2 deletions Mizuame/Settings/TabInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ struct TabInfo: View {
VStack(alignment: .leading, spacing: 20) {

HStack(alignment: .center) {
Image(systemName: "text.bubble").font(.title)
Image("MenubarIcon").font(.title)
Text("Mizuame").font(.title)
Spacer()
}

VStack(alignment: .leading, spacing: 5) {
Text("Version: 1.0.2").font(.body)
Text("Version: 1.1.0").font(.body)
Text("License: MIT license").font(.body)
HStack {
Text("settings.tab.info.src").font(.body)
Expand Down
4 changes: 1 addition & 3 deletions Mizuame/Settings/TermsOfServiceView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import SwiftUI
struct TermsOfServiceView: View {
@Binding var state: Int

private let delegate = AppDelegate()

var body: some View {
ZStack {
Color("UserAgreementBackground")
Expand All @@ -22,7 +20,7 @@ struct TermsOfServiceView: View {

HStack {
Button(action: {
delegate.quitApp()
NSApplication.shared.terminate(self)
}, label: {
Text("agreement.common.quit")
.foregroundColor(.red)
Expand Down
5 changes: 5 additions & 0 deletions Mizuame/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"settings.tab.help.menu.preference.description" = "Open preference window.";
"settings.tab.help.menu.eraser.description" = "Deletes all note contents.";
"settings.tab.help.menu.printer.description" = "Print all note contents.";
"settings.tab.help.menu.pin.description" = "Keep the note open.";

"settings.tab.stickynote.greeting" = "Previews:\nSize is NOT correct. Check the real size. Sorry!";
"settings.tab.stickynote.font.size" = "Font Size: ";
Expand All @@ -77,6 +78,10 @@

"settings.tab.general.menubar" = "Menu bar:";
"settings.tab.general.menubar.saving" = "Display a saving message";
"settings.tab.general.note" = "Note";
"settings.tab.general.note.pin" = "Pinning the note to the front";
"settings.tab.general.reset.title" = "Reset:";
"settings.tab.general.reset.button.caption" = "Reset general settings to initial value";

"settings.tab.print.greeting" = "Print Settings";
"settings.tab.print.margin" = "Margin:";
Expand Down
5 changes: 5 additions & 0 deletions Mizuame/ja.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"settings.tab.help.menu.preference.description" = "設定画面を開きます。";
"settings.tab.help.menu.eraser.description" = "文章を全て消します。";
"settings.tab.help.menu.printer.description" = "ノートの内容を全て印刷します。";
"settings.tab.help.menu.pin.description" = "ノートを開いたままにします。";

"settings.tab.stickynote.greeting" = "プレビュー:\nサイズは不正確です。実際にノートを確認してください。ごめんね!";
"settings.tab.stickynote.font.size" = "文字の大きさ: ";
Expand All @@ -77,6 +78,10 @@

"settings.tab.general.menubar" = "メニューバー:";
"settings.tab.general.menubar.saving" = "保存中のメッセージを表示する";
"settings.tab.general.note" = "ノート";
"settings.tab.general.note.pin" = "ノートを最前面に固定する";
"settings.tab.general.reset.title" = "リセット:";
"settings.tab.general.reset.button.caption" = "一般設定をリセットします";

"settings.tab.print.greeting" = "印刷設定";
"settings.tab.print.margin" = "余白:";
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ However, this app is NOT a high performance note app so that you should use othe
<div align="center" style="display: flex;">
<div style="margin: 0px 10px 0px 10px">
<h4>Light mode</h4>
<img src="sample-light.png" alt="Light Mode." width="256" height="192"/>
<img src="sample-light.png" alt="Light Mode." width="300" height="190"/>
</div>
<div style="margin: 0px 10px 0px 10px">
<h4>Dark mode</h4>
<img src="sample-dark.png" alt="Dark Mode." width="256" height="192"/>
<img src="sample-dark.png" alt="Dark Mode." width="300" height="190"/>
</div>
</div>

Expand Down
Binary file modified sample-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified sample-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f7641ee

Please sign in to comment.