mirror of
https://github.com/neon443/StickerSlack.git
synced 2026-11-30 12:44:51 +00:00
added messagesrootviewcontroller for the split pane thingy added messagespacklistview to select packs n stuff added .description to packs for easier display updated stickerdatasource to take a pack for filtering messagesvc needs to be cleaned ps i tried a splitviewcontroller but it didnt do the split
138 lines
5.1 KiB
Swift
138 lines
5.1 KiB
Swift
//
|
|
// MessagesViewController.swift
|
|
// StickerSlackiMessageExtension
|
|
//
|
|
// Created by neon443 on 18/10/2025.
|
|
//
|
|
|
|
import UIKit
|
|
import Messages
|
|
import SwiftUI
|
|
|
|
class MessagesViewController: MSMessagesAppViewController {
|
|
var emojiHoarder: EmojiHoarder!
|
|
var dataSource: StickerBrowserDataSource!
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
|
|
self.emojiHoarder = EmojiHoarder(localOnly: true, skipIndex: true)
|
|
self.dataSource = StickerBrowserDataSource(hoarder: emojiHoarder, pack: nil)
|
|
}
|
|
|
|
// MARK: - Conversation Handling
|
|
|
|
override func willBecomeActive(with conversation: MSConversation) {
|
|
let stickerBrowser = MSStickerBrowserView(frame: .zero, stickerSize: .small)
|
|
stickerBrowser.dataSource = dataSource
|
|
|
|
guard stickerBrowser.dataSource?.numberOfStickers(in: stickerBrowser) != 0 else {
|
|
let swiftUIView = NoStickersView()
|
|
let hostingController = UIHostingController(rootView: swiftUIView)
|
|
hostingController.view.translatesAutoresizingMaskIntoConstraints = false
|
|
view.addSubview(hostingController.view)
|
|
|
|
NSLayoutConstraint.activate([
|
|
hostingController.view.leadingAnchor.constraint(equalTo: view.leadingAnchor),
|
|
hostingController.view.trailingAnchor.constraint(equalTo: view.trailingAnchor),
|
|
hostingController.view.topAnchor.constraint(equalTo: view.topAnchor),
|
|
hostingController.view.bottomAnchor.constraint(equalTo: view.bottomAnchor)
|
|
])
|
|
return
|
|
}
|
|
|
|
|
|
let browser = MSStickerBrowserView(frame: .zero, stickerSize: .small)
|
|
let dataSource = StickerBrowserDataSource(hoarder: emojiHoarder, pack: nil)
|
|
browser.dataSource = dataSource
|
|
let vc = UIViewController()
|
|
browser.translatesAutoresizingMaskIntoConstraints = false
|
|
vc.view.addSubview(browser)
|
|
browser.contentInset = .zero
|
|
NSLayoutConstraint.activate([
|
|
browser.leadingAnchor.constraint(equalTo: vc.view.leadingAnchor),
|
|
browser.trailingAnchor.constraint(equalTo: vc.view.trailingAnchor),
|
|
browser.topAnchor.constraint(equalTo: vc.view.topAnchor),
|
|
browser.bottomAnchor.constraint(equalTo: vc.view.bottomAnchor)
|
|
])
|
|
|
|
let splitView = MessagesRootViewController(
|
|
leading: MessagesPackListView(hoarder: emojiHoarder),
|
|
trailing: vc
|
|
)
|
|
self.addChild(splitView)
|
|
splitView.view.translatesAutoresizingMaskIntoConstraints = false
|
|
view.addSubview(splitView.view)
|
|
NSLayoutConstraint.activate([
|
|
splitView.view.leadingAnchor.constraint(equalTo: view.leadingAnchor),
|
|
splitView.view.trailingAnchor.constraint(equalTo: view.trailingAnchor),
|
|
splitView.view.topAnchor.constraint(equalTo: view.topAnchor),
|
|
splitView.view.bottomAnchor.constraint(equalTo: view.bottomAnchor)
|
|
])
|
|
return
|
|
|
|
// stickerBrowser.translatesAutoresizingMaskIntoConstraints = false
|
|
// view.addSubview(stickerBrowser)
|
|
// stickerBrowser.contentInset = .zero
|
|
// NSLayoutConstraint.activate([
|
|
// stickerBrowser.leadingAnchor.constraint(equalTo: view.leadingAnchor),
|
|
// stickerBrowser.trailingAnchor.constraint(equalTo: view.trailingAnchor),
|
|
// stickerBrowser.topAnchor.constraint(equalTo: view.topAnchor),
|
|
// stickerBrowser.bottomAnchor.constraint(equalTo: view.bottomAnchor)
|
|
// ])
|
|
|
|
// Called when the extension is about to move from the inactive to active state.
|
|
// This will happen when the extension is about to present UI.
|
|
|
|
// Use this method to configure the extension and restore previously stored state.
|
|
}
|
|
|
|
override func didResignActive(with conversation: MSConversation) {
|
|
// Called when the extension is about to move from the active to inactive state.
|
|
// This will happen when the user dismisses the extension, changes to a different
|
|
// conversation or quits Messages.
|
|
|
|
// Use this method to release shared resources, save user data, invalidate timers,
|
|
// and store enough state information to restore your extension to its current state
|
|
// in case it is terminated later.
|
|
}
|
|
|
|
override func didReceive(_ message: MSMessage, conversation: MSConversation) {
|
|
// Called when a message arrives that was generated by another instance of this
|
|
// extension on a remote device.
|
|
|
|
// Use this method to trigger UI updates in response to the message.
|
|
}
|
|
|
|
override func didStartSending(_ message: MSMessage, conversation: MSConversation) {
|
|
// Called when the user taps the send button.
|
|
}
|
|
|
|
override func didCancelSending(_ message: MSMessage, conversation: MSConversation) {
|
|
// Called when the user deletes the message without sending it.
|
|
|
|
// Use this to clean up state related to the deleted message.
|
|
}
|
|
|
|
override func willTransition(to presentationStyle: MSMessagesAppPresentationStyle) {
|
|
// Called before the extension transitions to a new presentation style.
|
|
|
|
// Use this method to prepare for the change in presentation style.
|
|
}
|
|
|
|
override func didTransition(to presentationStyle: MSMessagesAppPresentationStyle) {
|
|
// Called after the extension transitions to a new presentation style.
|
|
|
|
// Use this method to finalize any behaviors associated with the change in presentation style.
|
|
}
|
|
|
|
@objc
|
|
func openStickerSlack() {
|
|
if let url = URL(string: "stickerslack://") {
|
|
self.extensionContext?.open(url) { success in
|
|
print("open url: \(success)")
|
|
}
|
|
}
|
|
}
|
|
}
|