From 96aae146710a887f60ac2fa06376be8e889fafeb Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Fri, 10 Nov 2023 12:41:30 +0800 Subject: [PATCH] Fix build on MacOS --- .../Share/Views/AddNoteSheet.swift | 11 +++- .../Share/Views/EditInfoSheet.swift | 4 +- .../Share/Views/EditLabelsSheet.swift | 17 +++--- .../Share/Views/ShareExtensionView.swift | 28 +++++----- .../App/Views/Home/HomeFeedViewMac.swift | 1 - .../Sources/App/Views/LabelsEntryView.swift | 24 +++++++-- .../Views/WebReader/WebReaderContainer.swift | 4 +- .../Sources/App/Views/WelcomeView.swift | 44 ++++++++------- .../Views/FeedItem/LibraryItemCard.swift | 54 +++++++++---------- .../SafariExtension/Resources/manifest.json | 2 +- .../Resources/scripts/content/toast.js | 2 +- .../ShareExtensionViewController.swift | 9 +++- 12 files changed, 121 insertions(+), 79 deletions(-) diff --git a/apple/OmnivoreKit/Sources/App/AppExtensions/Share/Views/AddNoteSheet.swift b/apple/OmnivoreKit/Sources/App/AppExtensions/Share/Views/AddNoteSheet.swift index f9a0bd759..54d487dcf 100644 --- a/apple/OmnivoreKit/Sources/App/AppExtensions/Share/Views/AddNoteSheet.swift +++ b/apple/OmnivoreKit/Sources/App/AppExtensions/Share/Views/AddNoteSheet.swift @@ -24,7 +24,9 @@ public struct AddNoteSheet: View { public init(viewModel: ShareExtensionViewModel) { _viewModel = StateObject(wrappedValue: viewModel) - UITextView.appearance().textContainerInset = UIEdgeInsets(top: 8, left: 4, bottom: 10, right: 4) + #if os(iOS) + UITextView.appearance().textContainerInset = UIEdgeInsets(top: 8, left: 4, bottom: 10, right: 4) + #endif } func saveNote() { @@ -41,6 +43,7 @@ public struct AddNoteSheet: View { } .background(Color.extensionBackground) .navigationTitle("Add Note") + #if os(iOS) .navigationBarTitleDisplayMode(.inline) .navigationBarItems(leading: Button(action: { dismiss() @@ -53,6 +56,10 @@ public struct AddNoteSheet: View { }, label: { Text("Save").bold() })) - }.navigationViewStyle(StackNavigationViewStyle()) + #endif + } + #if os(iOS) + .navigationViewStyle(StackNavigationViewStyle()) + #endif } } diff --git a/apple/OmnivoreKit/Sources/App/AppExtensions/Share/Views/EditInfoSheet.swift b/apple/OmnivoreKit/Sources/App/AppExtensions/Share/Views/EditInfoSheet.swift index 45dea726b..66ad351a1 100644 --- a/apple/OmnivoreKit/Sources/App/AppExtensions/Share/Views/EditInfoSheet.swift +++ b/apple/OmnivoreKit/Sources/App/AppExtensions/Share/Views/EditInfoSheet.swift @@ -26,7 +26,9 @@ public struct EditInfoSheet: View { public init(viewModel: ShareExtensionViewModel) { _viewModel = StateObject(wrappedValue: viewModel) - UITextView.appearance().textContainerInset = UIEdgeInsets(top: 8, left: 4, bottom: 10, right: 4) + #if os(iOS) + UITextView.appearance().textContainerInset = UIEdgeInsets(top: 8, left: 4, bottom: 10, right: 4) + #endif } // func saveInfo() { diff --git a/apple/OmnivoreKit/Sources/App/AppExtensions/Share/Views/EditLabelsSheet.swift b/apple/OmnivoreKit/Sources/App/AppExtensions/Share/Views/EditLabelsSheet.swift index a39547606..bc77f113a 100644 --- a/apple/OmnivoreKit/Sources/App/AppExtensions/Share/Views/EditLabelsSheet.swift +++ b/apple/OmnivoreKit/Sources/App/AppExtensions/Share/Views/EditLabelsSheet.swift @@ -29,8 +29,9 @@ public struct EditLabelsSheet: View { public init(viewModel: ShareExtensionViewModel, labelsViewModel: LabelsViewModel) { _viewModel = StateObject(wrappedValue: viewModel) _labelsViewModel = StateObject(wrappedValue: labelsViewModel) - - UITextView.appearance().textContainerInset = UIEdgeInsets(top: 5, left: 2, bottom: 5, right: 2) + #if os(iOS) + UITextView.appearance().textContainerInset = UIEdgeInsets(top: 5, left: 2, bottom: 5, right: 2) + #endif } @MainActor @@ -104,6 +105,7 @@ public struct EditLabelsSheet: View { .frame(maxWidth: .infinity, maxHeight: .infinity) .background(Color.extensionBackground) .navigationTitle("Set Labels") + #if os(iOS) .navigationBarTitleDisplayMode(.inline) .navigationBarItems(trailing: Button(action: { if let linkedItem = viewModel.linkedItem, let linkedItemId = linkedItem.id { @@ -116,11 +118,14 @@ public struct EditLabelsSheet: View { }, label: { Text("Done").bold() })) + #endif } - .navigationViewStyle(StackNavigationViewStyle()) + #if os(iOS) + .navigationViewStyle(StackNavigationViewStyle()) + #endif .environmentObject(viewModel.services.dataService) - .task { - await labelsViewModel.loadLabelsFromStore(dataService: viewModel.services.dataService) - } + .task { + await labelsViewModel.loadLabelsFromStore(dataService: viewModel.services.dataService) + } } } diff --git a/apple/OmnivoreKit/Sources/App/AppExtensions/Share/Views/ShareExtensionView.swift b/apple/OmnivoreKit/Sources/App/AppExtensions/Share/Views/ShareExtensionView.swift index 2c5f7f2a9..a501a6e4f 100644 --- a/apple/OmnivoreKit/Sources/App/AppExtensions/Share/Views/ShareExtensionView.swift +++ b/apple/OmnivoreKit/Sources/App/AppExtensions/Share/Views/ShareExtensionView.swift @@ -255,19 +255,21 @@ public struct ShareExtensionView: View { HStack { Spacer() - if UIDevice.isIPad { - Button(action: { - extensionContext?.completeRequest(returningItems: [], completionHandler: nil) - }, label: { - Text("Dismiss") - .font(Font.system(size: 17, weight: .semibold)) - .tint(Color.appGrayText) - .padding(20) - }) - .frame(height: 50) - .cornerRadius(24) - .padding(.bottom, 15) - } + #if os(iOS) + if UIDevice.isIPad { + Button(action: { + extensionContext?.completeRequest(returningItems: [], completionHandler: nil) + }, label: { + Text("Dismiss") + .font(Font.system(size: 17, weight: .semibold)) + .tint(Color.appGrayText) + .padding(20) + }) + .frame(height: 50) + .cornerRadius(24) + .padding(.bottom, 15) + } + #endif Button(action: { viewModel.handleReadNowAction(extensionContext: extensionContext) }, label: { diff --git a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewMac.swift b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewMac.swift index 482d2f191..e96127e08 100644 --- a/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewMac.swift +++ b/apple/OmnivoreKit/Sources/App/Views/Home/HomeFeedViewMac.swift @@ -106,7 +106,6 @@ import Views .contextMenu { menuItems(item) } - Divider().padding(5) } if viewModel.isLoading { diff --git a/apple/OmnivoreKit/Sources/App/Views/LabelsEntryView.swift b/apple/OmnivoreKit/Sources/App/Views/LabelsEntryView.swift index 7a5141799..935b88f7e 100644 --- a/apple/OmnivoreKit/Sources/App/Views/LabelsEntryView.swift +++ b/apple/OmnivoreKit/Sources/App/Views/LabelsEntryView.swift @@ -74,13 +74,27 @@ public struct LabelsEntryView: View { } } + var textFieldString: NSAttributedString { + #if os(iOS) + NSAttributedString( + string: searchTerm, + attributes: [ + NSAttributedString.Key.font: UIFont.systemFont(ofSize: 14) + ] + ) + #else + NSAttributedString( + string: searchTerm, + attributes: [ + NSAttributedString.Key.font: NSFont.systemFont(ofSize: 14) + ] + ) + #endif + } + var deletableTextField: some View { - let str = NSAttributedString( - string: searchTerm, - attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 14)] - ) // Round it up to avoid jitter when typing - let textWidth = max(25.0, Double(Int(str.size().width + 1))) + let textWidth = max(25.0, Double(Int(textFieldString.size().width + 1))) let result = TextField("", text: $searchTerm) .frame(alignment: .topLeading) .frame(height: 25) diff --git a/apple/OmnivoreKit/Sources/App/Views/WebReader/WebReaderContainer.swift b/apple/OmnivoreKit/Sources/App/Views/WebReader/WebReaderContainer.swift index aba8bf1ca..8042fa436 100644 --- a/apple/OmnivoreKit/Sources/App/Views/WebReader/WebReaderContainer.swift +++ b/apple/OmnivoreKit/Sources/App/Views/WebReader/WebReaderContainer.swift @@ -499,7 +499,9 @@ struct WebReaderContainerView: View { showErrorAlertMessage: $showErrorAlertMessage ) } - .navigationViewStyle(StackNavigationViewStyle()) + #if os(iOS) + .navigationViewStyle(StackNavigationViewStyle()) + #endif } .sheet(isPresented: $showHighlightLabelsModal) { if let highlight = Highlight.lookup(byID: self.annotation, inContext: self.dataService.viewContext) { diff --git a/apple/OmnivoreKit/Sources/App/Views/WelcomeView.swift b/apple/OmnivoreKit/Sources/App/Views/WelcomeView.swift index 433cbabed..8fd0be761 100644 --- a/apple/OmnivoreKit/Sources/App/Views/WelcomeView.swift +++ b/apple/OmnivoreKit/Sources/App/Views/WelcomeView.swift @@ -90,16 +90,18 @@ struct WelcomeView: View { NavigationView { BasicWebAppView.privacyPolicyWebView(baseURL: dataService.appEnvironment.webAppBaseURL) .toolbar { - ToolbarItem(placement: .navigationBarTrailing) { - Button( - action: { - showPrivacyModal = false - }, - label: { - Text(LocalText.genericClose) - } - ) - } + #if os(iOS) + ToolbarItem(placement: .navigationBarTrailing) { + Button( + action: { + showPrivacyModal = false + }, + label: { + Text(LocalText.genericClose) + } + ) + } + #endif } } } @@ -107,16 +109,18 @@ struct WelcomeView: View { NavigationView { BasicWebAppView.termsConditionsWebView(baseURL: dataService.appEnvironment.webAppBaseURL) .toolbar { - ToolbarItem(placement: .navigationBarTrailing) { - Button( - action: { - showTermsModal = false - }, - label: { - Text(LocalText.genericClose) - } - ) - } + #if os(iOS) + ToolbarItem(placement: .navigationBarTrailing) { + Button( + action: { + showTermsModal = false + }, + label: { + Text(LocalText.genericClose) + } + ) + } + #endif } } } diff --git a/apple/OmnivoreKit/Sources/Views/FeedItem/LibraryItemCard.swift b/apple/OmnivoreKit/Sources/Views/FeedItem/LibraryItemCard.swift index 2034eea85..eda8660a5 100644 --- a/apple/OmnivoreKit/Sources/Views/FeedItem/LibraryItemCard.swift +++ b/apple/OmnivoreKit/Sources/Views/FeedItem/LibraryItemCard.swift @@ -65,33 +65,33 @@ public struct LibraryItemCard: View { if item.hasLabels { labels } - - if let note = item.noteText { - HStack(alignment: .top, spacing: 10) { - avatarImage - .frame(width: 20, height: 20) - .padding(.vertical, 10) - .padding(.leading, 10) - - Text(note) - .font(Font.system(size: 12)) - .multilineTextAlignment(.leading) - .lineLimit(noteLineLimit) - .frame(minHeight: 20) - .padding(.vertical, 10) - .padding(.trailing, 10) - - Spacer() - } - .frame(maxWidth: .infinity) - .frame(alignment: .topLeading) - .background(Color.noteContainer) - .cornerRadius(5) - .allowsHitTesting(noteLineLimit != nil) - .onTapGesture { - noteLineLimit = nil - } - } +// +// if let note = item.noteText { +// HStack(alignment: .top, spacing: 10) { +// avatarImage +// .frame(width: 20, height: 20) +// .padding(.vertical, 10) +// .padding(.leading, 10) +// +// Text(note) +// .font(Font.system(size: 12)) +// .multilineTextAlignment(.leading) +// .lineLimit(noteLineLimit) +// .frame(minHeight: 20) +// .padding(.vertical, 10) +// .padding(.trailing, 10) +// +// Spacer() +// } +// .frame(maxWidth: .infinity) +// .frame(alignment: .topLeading) +// .background(Color.noteContainer) +// .cornerRadius(5) +// .allowsHitTesting(noteLineLimit != nil) +// .onTapGesture { +// noteLineLimit = nil +// } +// } } .padding(5) .padding(.top, 10) diff --git a/apple/Sources/SafariExtension/Resources/manifest.json b/apple/Sources/SafariExtension/Resources/manifest.json index 9781facf2..b49d79db2 100644 --- a/apple/Sources/SafariExtension/Resources/manifest.json +++ b/apple/Sources/SafariExtension/Resources/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 2, "name": "Omnivore", "short_name": "Omnivore", - "version": "2.6.2", + "version": "2.8.0", "description": "Save PDFs and Articles to your Omnivore library", "author": "Omnivore Media, Inc", "default_locale": "en", diff --git a/apple/Sources/SafariExtension/Resources/scripts/content/toast.js b/apple/Sources/SafariExtension/Resources/scripts/content/toast.js index 2e5b74219..7ee799643 100644 --- a/apple/Sources/SafariExtension/Resources/scripts/content/toast.js +++ b/apple/Sources/SafariExtension/Resources/scripts/content/toast.js @@ -1 +1 @@ -!function(){let e,t,o,n=[],a=!1;const i={spinner:'\n \n \n \n \n \n \n \n \n \n ',success:'\n \n \n \n ',failure:'\n \n \n \n ',close:'',animatedLoader:'\n \n
\n '};function r(){a=!0,o&&clearTimeout(o)}function s(o){if(e)switch(o.ctx&&(t={...t,...o.ctx}),o.target){case"logged_out":r(),l("failure"),c("#omnivore-logged-out-row"),d("#omnivore-logged-out-status","empty","You are not logged in."),["#omnivore-toast-edit-title-btn","#omnivore-toast-edit-labels-btn","#omnivore-toast-read-now-btn","#omnivore-toast-add-note-btn","#omnivore-open-menu-btn"].forEach((t=>{e.shadowRoot.querySelector(t).disabled=!0}));break;case"page":l(o.status);break;case"note":d("#omnivore-add-note-status",o.status,o.message,"success"==o.status?2500:void 0),"success"==o.status&&setTimeout((()=>{c("#omnivore-add-note-status")}),3e3);break;case"title":d("#omnivore-edit-title-status",o.status,o.message,"success"==o.status?2500:void 0),"success"==o.status&&setTimeout((()=>{c("#omnivore-edit-title-status")}),3e3);break;case"labels":d("#omnivore-edit-labels-status",o.status,o.message,"success"==o.status?2500:void 0);break;case"extra":d("#omnivore-extra-status",o.status,o.message,"success"==o.status?2500:void 0),"success"==o.status&&setTimeout((()=>{e.remove()}),3e3)}else console.log("no statusBox to update")}function l(t){const n=e.shadowRoot.querySelector(".omnivore-toast-statusBox");switch(t){case"loading":n.innerHTML=i.animatedLoader;break;case"success":o=setTimeout((function(){console.log("hiding: ",e,a),a||(e.remove(),e=void 0)}),2500),n.innerHTML=i.success;break;case"failure":n.innerHTML=i.failure}}function d(t,o,n,a){const r=e.shadowRoot.querySelector(t),s=(()=>{switch(o){case"loading":return i.animatedLoader;case"success":return i.success;case"failure":return i.failure;case"none":return"";default:return}})();r.innerHTML=s?`${s}${n}`:n,a&&setTimeout((()=>{r.innerHTML=""}),a)}function c(t){if(!e)return;const o=e.shadowRoot.querySelector(t),n=o?.getAttribute("data-state");if(e.shadowRoot.querySelectorAll(".omnivore-toast-func-row").forEach((e=>{e.setAttribute("data-state","closed")})),o&&n){const e="open"===n?"closed":"open";o.setAttribute("data-state",e)}}function u(e){const t=document.createElement("button"),o=document.createElement("span");o.style="width:10px;height:10px;border-radius:1000px;",o.style.setProperty("background-color",e.color);const n=document.createElement("span");n.style="margin-left: 10px;pointer-events: none;",n.innerText=e.name;const a=document.createElement("span");return a.style="margin-left: auto;pointer-events: none;",a.className="checkbox",a.innerHTML='\n \n \n \n ',t.appendChild(o),t.appendChild(n),t.appendChild(a),t.onclick=m,t.onkeydown=f,t.setAttribute("data-label-id",e.id),t.setAttribute("data-label-selected",e.selected?"on":"off"),t.setAttribute("tabIndex","-1"),t}function m(e){e.preventDefault();const t=e.target.getAttribute("data-label-id");b(e,t)}function b(e,t){const o=e.target.getAttribute("data-label-selected");if(!t||!o)return;const a="on"!=o;e.target.setAttribute("data-label-selected",a?"on":"off");const i=n.find((e=>e.id===t));i&&(i.selected=a);const r=e.target.form.querySelector("#label-list"),s=e.target.form.querySelector("#omnivore-edit-label-input");a?h(r,s,i.name):w(r,i.id)}function p(e){const t=e.target.querySelector("#omnivore-edit-label-input");t&&e.target!=t&&t.focus()}function f(e){switch(e.cancelBubble=!0,e.stopPropogation&&e.stopPropogation(),e.target.form&&"backspace"!==e.key.toLowerCase()&&e.target.form.querySelectorAll('.label[data-label-backspaced="on"]').forEach((e=>{e.removeAttribute("data-label-backspaced")})),e.key.toLowerCase()){case"arrowup":{if("omnivore-edit-label-input"==e.target.id)return;if(!e.target.getAttribute("data-label-id"))return;let t=e.target.previousElementSibling;t&&t.getAttribute("data-label-id")?t.focus():e.target.form.querySelector("#omnivore-edit-label-input")?.focus(),e.preventDefault();break}case"arrowdown":{let t;"omnivore-edit-label-input"==e.target.id?(idx=e.target.getAttribute("data-label-id"),t=e.target.closest("#omnivore-edit-labels-form").querySelector("#omnivore-edit-labels-list").querySelector("[data-label-id]")):t=e.target.nextElementSibling,t&&t.getAttribute("data-label-id")&&t.focus(),e.preventDefault();break}case"backspace":"omnivore-edit-label-input"==e.target.id&&0==e.target.value.length&&(e.target.form.querySelector("#label-list"),function(e,t){const o=t.closest("#label-entry-item").previousElementSibling;o&&(o.getAttribute("data-label-backspaced")?w(t.closest("#label-list"),o.getAttribute("data-label-id")):o.setAttribute("data-label-backspaced","on"))}(0,e.target));break;case"enter":{if("omnivore-edit-label-input"==e.target.id)return e.target.value&&h(e.target.form.querySelector("#label-list"),e.target,e.target.value),void e.preventDefault();const t=e.target.getAttribute("data-label-id");b(e,t),e.preventDefault();break}}}async function g(){const o=document.location?`cached-note-${document.location.href}`:void 0;r(),c("#omnivore-add-note-row");const n=e.shadowRoot.querySelector("#omnivore-add-note-textarea");if(n){if(o){const e=await getStorageItem(o);n.value=e}n.value?n.select():n.focus(),n.addEventListener("input",(e=>{(async()=>{const t={};t[o]=e.target.value,await setStorage(t)})()})),n.onkeydown=e=>{e.cancelBubble=!0,e.stopPropogation&&e.stopPropogation(),13==e.keyCode&&(e.metaKey||e.ctrlKey)&&(d("#omnivore-add-note-status","loading","Adding note..."),browserApi.runtime.sendMessage({action:ACTIONS.AddNote,payload:{ctx:t,note:n.value}}))}}e.shadowRoot.querySelector("#omnivore-add-note-form").onsubmit=e=>{d("#omnivore-add-note-status","loading","Adding note..."),browserApi.runtime.sendMessage({action:ACTIONS.AddNote,payload:{ctx:t,note:e.target.elements.title.value}}),e.preventDefault(),e.stopPropogation&&e.stopPropogation()}}function v(){r(),c("#omnivore-edit-title-row");const o=e.shadowRoot.querySelector("#omnivore-edit-title-textarea");o&&(o.focus(),o.onkeydown=e=>{e.cancelBubble=!0,e.stopPropogation&&e.stopPropogation()}),e.shadowRoot.querySelector("#omnivore-edit-title-form").onsubmit=e=>{d("#omnivore-edit-title-status","loading","Updating title..."),browserApi.runtime.sendMessage({action:ACTIONS.EditTitle,payload:{ctx:t,title:e.target.elements.title.value}}),e.preventDefault()}}function h(e,t,o){const a=n.find((e=>e.name===o)),i=a?a.id:([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,(e=>(e^crypto.getRandomValues(new Uint8Array(1))[0]&15>>e/4).toString(16))),r=e.querySelector("#label-entry-item"),s=r.querySelector("#omnivore-edit-label-input");if(a&&e.querySelector(`[data-label-id='${a.id}']`)){const t=e.querySelector(`[data-label-id='${a.id}']`);return t.setAttribute("data-item-highlighted","on"),setTimeout((()=>{t.style.borderColor="rgb(222, 222, 222)"}),500),void(s&&(s.value="",s.focus(),L(void 0)))}const l=a?a.color:function(){const e=["#FF5D99","#7CFF7B","#FFD234","#7BE4FF","#CE88EF","#EF8C43"];return e[Math.floor(Math.random()*e.length)]}(),d=document.createElement("li");d.classList.add("label"),d.innerHTML=`\n \n ${o}\n \n `,e.insertBefore(d,r),t.value="";const c=d.querySelector(".label-remove-button");c&&(c.onclick=t=>{w(e,i),t.preventDefault()});const m=e.closest("#omnivore-edit-labels-form");if(a){const e=m.querySelector(`[data-label-id='${a.id}']`);a.selected=!0,e.setAttribute("data-label-selected","on"),d.setAttribute("data-label-id",a.id)}else{const e=m.querySelector("#omnivore-edit-labels-list"),t={id:i,color:l,name:o,temporary:!0,selected:!0};n.push(t),d.setAttribute("data-label-id",t.id);const a=u(t),r=e.querySelector("button[data-label-id]");a.setAttribute("data-label-selected","on"),e.insertBefore(a,r)}s&&(s.focus(),L(void 0)),y()}function w(e,t){const o=e.closest("#omnivore-edit-labels-form"),a=e.querySelector(`[data-label-id='${t}']`);a&&a.remove();const i=o.querySelector(`[data-label-id='${t}']`);i&&i.setAttribute("data-label-selected","off");const r=n.find((e=>e.id===t));r&&(r.selected=!1),y()}function y(){d("#omnivore-edit-labels-status","loading","Updating Labels...",void 0);const e=n.filter((e=>e.selected)).map((e=>({name:e.name,color:e.color})));browserApi.runtime.sendMessage({action:ACTIONS.SetLabels,payload:{ctx:t,labels:e}})}async function C(){r(),await getStorageItem("labels").then((e=>{n=e})),c("#omnivore-edit-labels-row"),e.shadowRoot.querySelector("#omnivore-edit-label-input")?.focus();const t=e.shadowRoot.querySelector("#omnivore-edit-labels-list");e.shadowRoot.querySelector("#omnivore-edit-label-input").onkeydown=f,e.shadowRoot.querySelector("#omnivore-edit-label-editor").onclick=p,e.shadowRoot.querySelector("#omnivore-edit-label-input").addEventListener("input",(e=>{L(e.target.value)})),t&&(t.innerHTML="",n.sort(((e,t)=>e.name.localeCompare(t.name,void 0,{sensitivity:"base"}))).forEach((function(e,o){const n=u(e);t.appendChild(n)})))}async function L(t){const o=e.shadowRoot.querySelector("#omnivore-edit-labels-list");o&&(o.innerHTML="",t?n.filter((e=>e.name.toLowerCase().indexOf(t.toLowerCase())>-1)).sort(((e,t)=>e.name.localeCompare(t.name,void 0,{sensitivity:"base"}))).forEach((function(e){const t=u(e);o.appendChild(t)})):n.sort(((e,t)=>e.name.localeCompare(t.name,void 0,{sensitivity:"base"}))).forEach((function(e){const t=u(e);o.appendChild(t)})))}function S(){r(),e.shadowRoot.querySelector("#omnivore-toast-container").setAttribute("data-state","open"),t&&t.readerURL?window.open(t.readerURL,"_blank"):t?window.open(new URL(`/article?url=${encodeURI(t.originalURL)}`,t.omnivoreURL),"_blank"):alert("Error no URL found."),setTimeout((()=>{q()}),1e3)}function x(e){browserApi.runtime.sendMessage({action:ACTIONS.Archive,payload:{ctx:t}}),e.preventDefault()}function k(e){browserApi.runtime.sendMessage({action:ACTIONS.Delete,payload:{ctx:t}}),e.preventDefault()}function A(){r(),c("#omnivore-extra-buttons-row")}function q(){e.remove(),e=void 0}function R(){window.open(new URL("/login",t.omnivoreURL),"_blank"),setTimeout(q,2e3)}window.showToolbar=function(o){t=o.ctx,async function(t){document.body&&(e||(e=await async function(){const e=await fetch(browserApi.runtime.getURL("views/toast.html")),t=await e.text(),o=document.createElement("div");o.tabIndex=0,o.attachShadow({mode:"open"}),o.shadowRoot&&(o.shadowRoot.innerHTML="");const n=document.createElement("div");return n.id="#omnivore-toast",n.innerHTML=t,n.tabIndex=0,o.shadowRoot.appendChild(n),document.body.appendChild(o),function(e){const t=[{id:"#omnivore-toast-add-note-btn",func:g},{id:"#omnivore-toast-edit-title-btn",func:v},{id:"#omnivore-toast-edit-labels-btn",func:C},{id:"#omnivore-toast-read-now-btn",func:S},{id:"#omnivore-open-menu-btn",func:A},{id:"#omnivore-toast-close-btn",func:q},{id:"#omnivore-toast-login-btn",func:R},{id:"#omnivore-toast-archive-btn",func:x},{id:"#omnivore-toast-delete-btn",func:k}];for(const o of t){const t=e.shadowRoot.querySelector(o.id);t&&t.addEventListener("click",o.func)}if(window.matchMedia("(max-width: 500px)").matches){e.shadowRoot.querySelectorAll(".omnivore-top-button-label").forEach((e=>{e.style.display="none"}));const t=e.shadowRoot.querySelector("#omnivore-toast-container");t.style.width="280px",t.style.top="unset",t.style.bottom="20px"}}(o),function(e){e.addEventListener("keydown",(e=>{switch(e.key){case"r":S();break;case"l":C();break;case"m":A();break;case"t":v();break;case"n":e.preventDefault(),g()}e.cancelBubble=!0,e.stopPropogation&&e.stopPropogation()}))}(o),o}()),"loading"===t.type&&s({status:"loading",target:"page"}),document.querySelectorAll("#omnivore-toast").forEach((t=>{t!==e&&(console.log("removing current toast el: ",e),t.remove())})),e.focus({preventScroll:!0}))}(o).catch((e=>console.log("error showing toast",e)))},window.updateStatus=s,window.updateLabelsFromCache=function(e){(async()=>{await getStorageItem("labels").then((e=>{n&&n.filter((e=>e.selected)).forEach((t=>{const o=e.find((e=>e.name==t.name));o?o.selected=!0:e.push(t)})),n=e}))})()}}(); \ No newline at end of file +!function(){let e,t,o,n=[],a=!1;const i={spinner:'\n \n \n \n \n \n \n \n \n \n ',success:'\n \n \n \n ',failure:'\n \n \n \n ',close:'',animatedLoader:'\n \n
\n '};function r(){a=!0,o&&clearTimeout(o)}function s(o){if(e)switch(o.ctx&&(t={...t,...o.ctx}),o.target){case"logged_out":r(),l("failure"),c("#omnivore-logged-out-row"),d("#omnivore-logged-out-status","empty","You are not logged in."),["#omnivore-toast-edit-title-btn","#omnivore-toast-edit-labels-btn","#omnivore-toast-read-now-btn","#omnivore-toast-add-note-btn","#omnivore-open-menu-btn"].forEach((t=>{e.shadowRoot.querySelector(t).disabled=!0}));break;case"page":l(o.status);break;case"note":d("#omnivore-add-note-status",o.status,o.message,"success"==o.status?2500:void 0),"success"==o.status&&setTimeout((()=>{c("#omnivore-add-note-status")}),3e3);break;case"title":d("#omnivore-edit-title-status",o.status,o.message,"success"==o.status?2500:void 0),"success"==o.status&&setTimeout((()=>{c("#omnivore-edit-title-status")}),3e3);break;case"labels":d("#omnivore-edit-labels-status",o.status,o.message,"success"==o.status?2500:void 0);break;case"extra":d("#omnivore-extra-status",o.status,o.message,"success"==o.status?2500:void 0),"success"==o.status&&setTimeout((()=>{e.remove()}),3e3)}else console.log("no statusBox to update")}function l(t){const n=e.shadowRoot.querySelector(".omnivore-toast-statusBox");switch(t){case"loading":n.innerHTML=i.animatedLoader;break;case"success":const t=t=>{const n=t&&!Number.isNaN(Number(t))?Number(t):2500;console.log("setting dismiss time: ",n),o=setTimeout((function(){console.log("hiding toast timeout"),a||(e.remove(),e=void 0)}),n)};getStorageItem("autoDismissTime").then((e=>{t(e)})).catch((()=>{t("2500")})),getStorageItem("disableAutoDismiss").then((e=>{console.log("got disableAutoDismiss",e),e&&r()})),n.innerHTML=i.success;break;case"failure":n.innerHTML=i.failure}}function d(t,o,n,a){const r=e.shadowRoot.querySelector(t),s=(()=>{switch(o){case"loading":return i.animatedLoader;case"success":return i.success;case"failure":return i.failure;case"none":return"";default:return}})();r.innerHTML=s?`${s}${n}`:n,a&&setTimeout((()=>{r.innerHTML=""}),a)}function c(t){if(!e)return;const o=e.shadowRoot.querySelector(t),n=o?.getAttribute("data-state");if(e.shadowRoot.querySelectorAll(".omnivore-toast-func-row").forEach((e=>{e.setAttribute("data-state","closed")})),o&&n){const e="open"===n?"closed":"open";o.setAttribute("data-state",e)}}function u(e){const t=document.createElement("button"),o=document.createElement("span");o.style="width:10px;height:10px;border-radius:1000px;",o.style.setProperty("background-color",e.color);const n=document.createElement("span");n.style="margin-left: 10px;pointer-events: none;",n.innerText=e.name;const a=document.createElement("span");return a.style="margin-left: auto;pointer-events: none;",a.className="checkbox",a.innerHTML='\n \n \n \n ',t.appendChild(o),t.appendChild(n),t.appendChild(a),t.onclick=m,t.onkeydown=g,t.setAttribute("data-label-id",e.id),t.setAttribute("data-label-selected",e.selected?"on":"off"),t.setAttribute("tabIndex","-1"),t}function m(e){e.preventDefault();const t=e.target.getAttribute("data-label-id");b(e,t)}function b(e,t){const o=e.target.getAttribute("data-label-selected");if(!t||!o)return;const a="on"!=o;e.target.setAttribute("data-label-selected",a?"on":"off");const i=n.find((e=>e.id===t));i&&(i.selected=a);const r=e.target.form.querySelector("#label-list"),s=e.target.form.querySelector("#omnivore-edit-label-input");a?h(r,s,i.name):w(r,i.id)}function p(e){const t=e.target.querySelector("#omnivore-edit-label-input");t&&e.target!=t&&t.focus()}function g(e){switch(e.cancelBubble=!0,e.stopPropogation&&e.stopPropogation(),e.target.form&&"backspace"!==e.key.toLowerCase()&&e.target.form.querySelectorAll('.label[data-label-backspaced="on"]').forEach((e=>{e.removeAttribute("data-label-backspaced")})),e.key.toLowerCase()){case"arrowup":{if("omnivore-edit-label-input"==e.target.id)return;if(!e.target.getAttribute("data-label-id"))return;let t=e.target.previousElementSibling;t&&t.getAttribute("data-label-id")?t.focus():e.target.form.querySelector("#omnivore-edit-label-input")?.focus(),e.preventDefault();break}case"arrowdown":{let t;"omnivore-edit-label-input"==e.target.id?(idx=e.target.getAttribute("data-label-id"),t=e.target.closest("#omnivore-edit-labels-form").querySelector("#omnivore-edit-labels-list").querySelector("[data-label-id]")):t=e.target.nextElementSibling,t&&t.getAttribute("data-label-id")&&t.focus(),e.preventDefault();break}case"backspace":"omnivore-edit-label-input"==e.target.id&&0==e.target.value.length&&(e.target.form.querySelector("#label-list"),function(e,t){const o=t.closest("#label-entry-item").previousElementSibling;o&&(o.getAttribute("data-label-backspaced")?w(t.closest("#label-list"),o.getAttribute("data-label-id")):o.setAttribute("data-label-backspaced","on"))}(0,e.target));break;case"enter":{if("omnivore-edit-label-input"==e.target.id)return e.target.value&&h(e.target.form.querySelector("#label-list"),e.target,e.target.value),void e.preventDefault();const t=e.target.getAttribute("data-label-id");b(e,t),e.preventDefault();break}}}async function f(){const o=document.location?`cached-note-${document.location.href}`:void 0;r(),c("#omnivore-add-note-row");const n=e.shadowRoot.querySelector("#omnivore-add-note-textarea");if(n){if(o){const e=await getStorageItem(o);n.value=e}n.value?n.select():n.focus(),n.addEventListener("input",(e=>{(async()=>{const t={};t[o]=e.target.value,await setStorage(t)})()})),n.onkeydown=e=>{e.cancelBubble=!0,e.stopPropogation&&e.stopPropogation(),13==e.keyCode&&(e.metaKey||e.ctrlKey)&&(d("#omnivore-add-note-status","loading","Adding note..."),browserApi.runtime.sendMessage({action:ACTIONS.AddNote,payload:{ctx:t,note:n.value}}))}}e.shadowRoot.querySelector("#omnivore-add-note-form").onsubmit=e=>{d("#omnivore-add-note-status","loading","Adding note..."),browserApi.runtime.sendMessage({action:ACTIONS.AddNote,payload:{ctx:t,note:e.target.elements.title.value}}),e.preventDefault(),e.stopPropogation&&e.stopPropogation()}}function v(){r(),c("#omnivore-edit-title-row");const o=e.shadowRoot.querySelector("#omnivore-edit-title-textarea");o&&(o.focus(),o.onkeydown=e=>{e.cancelBubble=!0,e.stopPropogation&&e.stopPropogation()}),e.shadowRoot.querySelector("#omnivore-edit-title-form").onsubmit=e=>{d("#omnivore-edit-title-status","loading","Updating title..."),browserApi.runtime.sendMessage({action:ACTIONS.EditTitle,payload:{ctx:t,title:e.target.elements.title.value}}),e.preventDefault()}}function h(e,t,o){const a=n.find((e=>e.name===o)),i=a?a.id:([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,(e=>(e^crypto.getRandomValues(new Uint8Array(1))[0]&15>>e/4).toString(16))),r=e.querySelector("#label-entry-item"),s=r.querySelector("#omnivore-edit-label-input");if(a&&e.querySelector(`[data-label-id='${a.id}']`)){const t=e.querySelector(`[data-label-id='${a.id}']`);return t.setAttribute("data-item-highlighted","on"),setTimeout((()=>{t.style.borderColor="rgb(222, 222, 222)"}),500),void(s&&(s.value="",s.focus(),L(void 0)))}const l=a?a.color:function(){const e=["#FF5D99","#7CFF7B","#FFD234","#7BE4FF","#CE88EF","#EF8C43"];return e[Math.floor(Math.random()*e.length)]}(),d=document.createElement("li");d.classList.add("label"),d.innerHTML=`\n \n ${o}\n \n `,e.insertBefore(d,r),t.value="";const c=d.querySelector(".label-remove-button");c&&(c.onclick=t=>{w(e,i),t.preventDefault()});const m=e.closest("#omnivore-edit-labels-form");if(a){const e=m.querySelector(`[data-label-id='${a.id}']`);a.selected=!0,e.setAttribute("data-label-selected","on"),d.setAttribute("data-label-id",a.id)}else{const e=m.querySelector("#omnivore-edit-labels-list"),t={id:i,color:l,name:o,temporary:!0,selected:!0};n.push(t),d.setAttribute("data-label-id",t.id);const a=u(t),r=e.querySelector("button[data-label-id]");a.setAttribute("data-label-selected","on"),e.insertBefore(a,r)}s&&(s.focus(),L(void 0)),y()}function w(e,t){const o=e.closest("#omnivore-edit-labels-form"),a=e.querySelector(`[data-label-id='${t}']`);a&&a.remove();const i=o.querySelector(`[data-label-id='${t}']`);i&&i.setAttribute("data-label-selected","off");const r=n.find((e=>e.id===t));r&&(r.selected=!1),y()}function y(){d("#omnivore-edit-labels-status","loading","Updating Labels...",void 0);const e=n.filter((e=>e.selected)).map((e=>({name:e.name,color:e.color})));browserApi.runtime.sendMessage({action:ACTIONS.SetLabels,payload:{ctx:t,labels:e}})}async function C(){r(),await getStorageItem("labels").then((e=>{n=e})),c("#omnivore-edit-labels-row"),e.shadowRoot.querySelector("#omnivore-edit-label-input")?.focus();const t=e.shadowRoot.querySelector("#omnivore-edit-labels-list");e.shadowRoot.querySelector("#omnivore-edit-label-input").onkeydown=g,e.shadowRoot.querySelector("#omnivore-edit-label-editor").onclick=p,e.shadowRoot.querySelector("#omnivore-edit-label-input").addEventListener("input",(e=>{L(e.target.value)})),t&&(t.innerHTML="",n.sort(((e,t)=>e.name.localeCompare(t.name,void 0,{sensitivity:"base"}))).forEach((function(e,o){const n=u(e);t.appendChild(n)})))}async function L(t){const o=e.shadowRoot.querySelector("#omnivore-edit-labels-list");o&&(o.innerHTML="",t?n.filter((e=>e.name.toLowerCase().indexOf(t.toLowerCase())>-1)).sort(((e,t)=>e.name.localeCompare(t.name,void 0,{sensitivity:"base"}))).forEach((function(e){const t=u(e);o.appendChild(t)})):n.sort(((e,t)=>e.name.localeCompare(t.name,void 0,{sensitivity:"base"}))).forEach((function(e){const t=u(e);o.appendChild(t)})))}function S(){r(),e.shadowRoot.querySelector("#omnivore-toast-container").setAttribute("data-state","open"),t&&t.readerURL?window.open(t.readerURL,"_blank"):t?window.open(new URL(`/article?url=${encodeURI(t.originalURL)}`,t.omnivoreURL),"_blank"):alert("Error no URL found."),setTimeout((()=>{q()}),1e3)}function x(e){browserApi.runtime.sendMessage({action:ACTIONS.Archive,payload:{ctx:t}}),e.preventDefault()}function k(e){browserApi.runtime.sendMessage({action:ACTIONS.Delete,payload:{ctx:t}}),e.preventDefault()}function A(){r(),c("#omnivore-extra-buttons-row")}function q(){e.remove(),e=void 0}function R(){window.open(new URL("/login",t.omnivoreURL),"_blank"),setTimeout(q,2e3)}window.showToolbar=function(o){t=o.ctx,async function(t){document.body&&(e||(e=await async function(){const e=await fetch(browserApi.runtime.getURL("views/toast.html")),t=await e.text(),o=document.createElement("div");o.tabIndex=0,o.attachShadow({mode:"open"}),o.shadowRoot&&(o.shadowRoot.innerHTML="");const n=document.createElement("div");return n.id="#omnivore-toast",n.innerHTML=t,n.tabIndex=0,o.shadowRoot.appendChild(n),document.body.appendChild(o),function(e){const t=[{id:"#omnivore-toast-add-note-btn",func:f},{id:"#omnivore-toast-edit-title-btn",func:v},{id:"#omnivore-toast-edit-labels-btn",func:C},{id:"#omnivore-toast-read-now-btn",func:S},{id:"#omnivore-open-menu-btn",func:A},{id:"#omnivore-toast-close-btn",func:q},{id:"#omnivore-toast-login-btn",func:R},{id:"#omnivore-toast-archive-btn",func:x},{id:"#omnivore-toast-delete-btn",func:k}];for(const o of t){const t=e.shadowRoot.querySelector(o.id);t&&t.addEventListener("click",o.func)}if(window.matchMedia("(max-width: 500px)").matches){e.shadowRoot.querySelectorAll(".omnivore-top-button-label").forEach((e=>{e.style.display="none"}));const t=e.shadowRoot.querySelector("#omnivore-toast-container");t.style.width="280px",t.style.top="unset",t.style.bottom="20px"}}(o),function(e){e.addEventListener("keydown",(e=>{switch(e.key){case"r":S();break;case"l":C();break;case"m":A();break;case"t":v();break;case"n":e.preventDefault(),f()}e.cancelBubble=!0,e.stopPropogation&&e.stopPropogation()}))}(o),o}()),"loading"===t.type&&s({status:"loading",target:"page"}),document.querySelectorAll("#omnivore-toast").forEach((t=>{t!==e&&(console.log("removing current toast el: ",e),t.remove())})),e.focus({preventScroll:!0}))}(o).catch((e=>console.log("error showing toast",e)))},window.updateStatus=s,window.updateLabelsFromCache=function(e){(async()=>{await getStorageItem("labels").then((e=>{n&&n.filter((e=>e.selected)).forEach((t=>{const o=e.find((e=>e.name==t.name));o?o.selected=!0:e.push(t)})),n=e}))})()}}(); \ No newline at end of file diff --git a/apple/Sources/ShareExtension/ShareExtensionViewController.swift b/apple/Sources/ShareExtension/ShareExtensionViewController.swift index 73c8f6242..b8c282111 100644 --- a/apple/Sources/ShareExtension/ShareExtensionViewController.swift +++ b/apple/Sources/ShareExtension/ShareExtensionViewController.swift @@ -62,6 +62,9 @@ import Views import Cocoa class ShareViewController: NSViewController { + let labelsViewModel = LabelsViewModel() + let viewModel = ShareExtensionViewModel() + override func loadView() { view = NSView(frame: NSRect(x: 0, y: 0, width: 400, height: 600)) } @@ -69,7 +72,11 @@ import Views override func viewDidLoad() { super.viewDidLoad() embed( - childViewController: NSViewController.makeShareExtensionController(extensionContext: extensionContext) + childViewController: NSViewController.makeShareExtensionController( + viewModel: viewModel, + labelsViewModel: labelsViewModel, + extensionContext: extensionContext + ) ) } }