2024-07-16 11:33:39 +00:00
|
|
|
/*
|
2024-11-07 17:26:42 +00:00
|
|
|
* Copyright (c) 2024, Tim Flynn <trflynn89@ladybird.org>
|
2024-07-16 11:33:39 +00:00
|
|
|
* Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import Ladybird.WebView
|
|
|
|
import Ladybird.WebViewApplication
|
2024-11-07 17:26:42 +00:00
|
|
|
import Ladybird.WebViewWindow
|
2024-07-16 11:33:39 +00:00
|
|
|
import SwiftUI
|
|
|
|
|
2024-11-07 17:26:42 +00:00
|
|
|
public class TaskManager: LadybirdWebViewWindow {
|
2024-07-16 11:33:39 +00:00
|
|
|
|
2024-07-24 23:15:55 +00:00
|
|
|
private let WINDOW_WIDTH: CGFloat = 600
|
|
|
|
private let WINDOW_HEIGHT: CGFloat = 400
|
2024-07-16 11:33:39 +00:00
|
|
|
|
2024-07-24 23:15:55 +00:00
|
|
|
private var timer: Timer?
|
2024-07-16 11:33:39 +00:00
|
|
|
|
2024-07-24 23:15:55 +00:00
|
|
|
init() {
|
|
|
|
let tab_rect = NSApplication.shared.keyWindow!.frame
|
|
|
|
let position_x = tab_rect.origin.x + (tab_rect.size.width - WINDOW_WIDTH) / 2
|
|
|
|
let position_y = tab_rect.origin.y + (tab_rect.size.height - WINDOW_HEIGHT) / 2
|
|
|
|
let window_rect = NSMakeRect(position_x, position_y, WINDOW_WIDTH, WINDOW_HEIGHT)
|
2024-07-16 11:33:39 +00:00
|
|
|
|
2024-11-07 17:26:42 +00:00
|
|
|
super.init(webView: nil, windowRect: window_rect)
|
2024-07-16 11:33:39 +00:00
|
|
|
|
2024-07-24 23:15:55 +00:00
|
|
|
self.timer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { [weak self] timer in
|
|
|
|
if let strong_self = self {
|
|
|
|
strong_self.updateStatistics()
|
|
|
|
}
|
|
|
|
}
|
2024-07-16 11:33:39 +00:00
|
|
|
|
2024-11-07 17:26:42 +00:00
|
|
|
self.contentView = self.web_view
|
2024-07-24 23:15:55 +00:00
|
|
|
self.title = "Task Manager"
|
|
|
|
self.setIsVisible(true)
|
2024-07-16 11:33:39 +00:00
|
|
|
|
2024-07-24 23:15:55 +00:00
|
|
|
self.updateStatistics()
|
|
|
|
}
|
2024-07-16 11:33:39 +00:00
|
|
|
|
2024-07-24 23:15:55 +00:00
|
|
|
func updateStatistics() {
|
|
|
|
WebView.Application.the().update_process_statistics()
|
|
|
|
self.web_view.loadHTML(WebView.Application.the().generate_process_statistics_html().__bytes_as_string_viewUnsafe())
|
|
|
|
}
|
2024-07-16 11:33:39 +00:00
|
|
|
}
|