main

mattermost/focalboard

Last updated at: 28/12/2023 01:34

WhatsNewViewController.swift

TLDR

This file contains a view controller class called WhatsNewViewController. It displays a text view, two buttons, and implements several methods for button actions and loading text from a file.

Methods

viewDidLoad

This method is called when the view controller's view is loaded. It calls the loadText method to load and display the text from a file.

loadText

This private method loads the content of a text file named "whatsnew.txt" from the application's bundle. It sets the loaded text as the string value of the textView property and applies some formatting to the text view.

rateButtonClicked

This method is called when the "rateButton" button is clicked. It opens the Mac App Store URL for writing a review and then closes the view controller's window.

cloudButtonClicked

This method is called when the "cloudButton" button is clicked. It invokes the openGetCloudServerUrl method of the Globals class.

closeButtonClicked

This method is called when the "closeButton" button is clicked. It closes the view controller's window.

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import Cocoa

class WhatsNewViewController:
	NSViewController {
	@IBOutlet var textView: NSTextView!
	@IBOutlet var rateButton: NSButton!
	@IBOutlet var cloudButton: NSButton!

	override func viewDidLoad() {
		super.viewDidLoad()
		loadText()
	}

	private func loadText() {
		guard let fileUrl = Bundle.main.url(forResource: "whatsnew", withExtension: "txt") else { assertionFailure("whatsnew"); return }
		guard let text = try? String(contentsOf: fileUrl, encoding: .utf8) else { assertionFailure("whatsnew"); return }

		textView.string = text
		textView.textStorage?.font = NSFont.systemFont(ofSize: 13)
		textView.textStorage?.foregroundColor = NSColor.textColor
	}

	@IBAction func rateButtonClicked(_ sender: Any) {
		let url = URL(string: "macappstore://itunes.apple.com/app/id1556908618?action=write-review")!
		NSWorkspace.shared.open(url)
		view.window?.close()
	}

	@IBAction func cloudButtonClicked(_ sender: Any) {
		Globals.openGetCloudServerUrl()
	}

	@IBAction func closeButtonClicked(_ sender: Any) {
		view.window?.close()
	}
}