mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-09 17:44:56 +09:00
UI/AppKit: Replace the Task Manager window with about:processes
This commit is contained in:
parent
843209c6a9
commit
67a1dd72db
Notes:
github-actions[bot]
2025-03-19 14:04:32 +00:00
Author: https://github.com/trflynn89
Commit: 67a1dd72db
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3967
Reviewed-by: https://github.com/shannonbooth
8 changed files with 4 additions and 317 deletions
|
@ -15,22 +15,13 @@
|
|||
#import <Interface/TabController.h>
|
||||
#import <LibWebView/UserAgent.h>
|
||||
|
||||
#if defined(LADYBIRD_USE_SWIFT)
|
||||
// FIXME: Report this codegen error to Apple
|
||||
# define StyleMask NSWindowStyleMask
|
||||
# import <Ladybird-Swift.h>
|
||||
# undef StyleMask
|
||||
#else
|
||||
# import <Interface/TaskManagerController.h>
|
||||
#endif
|
||||
|
||||
#import <Utilities/Conversions.h>
|
||||
|
||||
#if !__has_feature(objc_arc)
|
||||
# error "This project requires ARC"
|
||||
#endif
|
||||
|
||||
@interface ApplicationDelegate () <TaskManagerDelegate>
|
||||
@interface ApplicationDelegate ()
|
||||
{
|
||||
Web::CSS::PreferredColorScheme m_preferred_color_scheme;
|
||||
Web::CSS::PreferredContrast m_preferred_contrast;
|
||||
|
@ -45,8 +36,6 @@
|
|||
|
||||
@property (nonatomic, strong) InfoBar* info_bar;
|
||||
|
||||
@property (nonatomic, strong) TaskManagerController* task_manager_controller;
|
||||
|
||||
@property (nonatomic, strong) NSMenuItem* toggle_devtools_menu_item;
|
||||
|
||||
- (NSMenuItem*)createApplicationMenu;
|
||||
|
@ -152,12 +141,6 @@
|
|||
- (void)removeTab:(TabController*)controller
|
||||
{
|
||||
[self.managed_tabs removeObject:controller];
|
||||
|
||||
if ([self.managed_tabs count] == 0u) {
|
||||
if (self.task_manager_controller != nil) {
|
||||
[self.task_manager_controller.window close];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (Web::CSS::PreferredColorScheme)preferredColorScheme
|
||||
|
@ -299,13 +282,9 @@
|
|||
|
||||
- (void)openTaskManager:(id)sender
|
||||
{
|
||||
if (self.task_manager_controller != nil) {
|
||||
[self.task_manager_controller.window makeKeyAndOrderFront:sender];
|
||||
return;
|
||||
}
|
||||
|
||||
self.task_manager_controller = [[TaskManagerController alloc] initWithDelegate:self];
|
||||
[self.task_manager_controller showWindow:nil];
|
||||
[self createNewTab:URL::URL::about("processes"_string)
|
||||
fromTab:self.active_tab
|
||||
activateTab:Web::HTML::ActivateTab::Yes];
|
||||
}
|
||||
|
||||
- (void)openLocation:(id)sender
|
||||
|
@ -864,11 +843,4 @@
|
|||
return YES;
|
||||
}
|
||||
|
||||
#pragma mark - TaskManagerDelegate
|
||||
|
||||
- (void)onTaskManagerClosed
|
||||
{
|
||||
self.task_manager_controller = nil;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -21,25 +21,6 @@ target_compile_options(ladybird_impl PUBLIC
|
|||
)
|
||||
target_compile_features(ladybird_impl PUBLIC cxx_std_23)
|
||||
|
||||
if (ENABLE_SWIFT)
|
||||
target_sources(ladybird_impl PRIVATE
|
||||
Interface/TaskManager.swift
|
||||
Interface/TaskManagerController.swift
|
||||
)
|
||||
target_compile_definitions(ladybird_impl PUBLIC LADYBIRD_USE_SWIFT)
|
||||
set_target_properties(ladybird_impl PROPERTIES Swift_MODULE_NAME "SwiftLadybird")
|
||||
|
||||
get_target_property(LADYBIRD_NATIVE_DIRS ladybird_impl INCLUDE_DIRECTORIES)
|
||||
_swift_generate_cxx_header(ladybird_impl "Ladybird-Swift.h"
|
||||
SEARCH_PATHS ${LADYBIRD_NATIVE_DIRS}
|
||||
)
|
||||
else()
|
||||
target_sources(ladybird_impl PRIVATE
|
||||
Interface/TaskManager.mm
|
||||
Interface/TaskManagerController.mm
|
||||
)
|
||||
endif()
|
||||
|
||||
add_executable(ladybird MACOSX_BUNDLE
|
||||
main.mm
|
||||
)
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Tim Flynn <trflynn89@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import <Interface/LadybirdWebViewWindow.h>
|
||||
|
||||
@class LadybirdWebView;
|
||||
|
||||
@interface TaskManager : LadybirdWebViewWindow
|
||||
|
||||
- (instancetype)init;
|
||||
|
||||
@end
|
|
@ -1,66 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Tim Flynn <trflynn89@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/String.h>
|
||||
#include <LibCore/Timer.h>
|
||||
#include <LibWebView/Application.h>
|
||||
|
||||
#import <Interface/LadybirdWebView.h>
|
||||
#import <Interface/TaskManager.h>
|
||||
|
||||
#if !__has_feature(objc_arc)
|
||||
# error "This project requires ARC"
|
||||
#endif
|
||||
|
||||
static constexpr CGFloat const WINDOW_WIDTH = 600;
|
||||
static constexpr CGFloat const WINDOW_HEIGHT = 400;
|
||||
|
||||
@interface TaskManager ()
|
||||
{
|
||||
RefPtr<Core::Timer> m_update_timer;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation TaskManager
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
auto tab_rect = [[NSApp keyWindow] frame];
|
||||
auto position_x = tab_rect.origin.x + (tab_rect.size.width - WINDOW_WIDTH) / 2;
|
||||
auto position_y = tab_rect.origin.y + (tab_rect.size.height - WINDOW_HEIGHT) / 2;
|
||||
auto window_rect = NSMakeRect(position_x, position_y, WINDOW_WIDTH, WINDOW_HEIGHT);
|
||||
|
||||
if (self = [super initWithWebView:nil windowRect:window_rect]) {
|
||||
__weak TaskManager* weak_self = self;
|
||||
|
||||
m_update_timer = Core::Timer::create_repeating(1000, [weak_self] {
|
||||
TaskManager* strong_self = weak_self;
|
||||
if (strong_self == nil) {
|
||||
return;
|
||||
}
|
||||
|
||||
[strong_self updateStatistics];
|
||||
});
|
||||
|
||||
[self setContentView:self.web_view];
|
||||
[self setTitle:@"Task Manager"];
|
||||
[self setIsVisible:YES];
|
||||
|
||||
[self updateStatistics];
|
||||
m_update_timer->start();
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)updateStatistics
|
||||
{
|
||||
WebView::Application::the().update_process_statistics();
|
||||
[self.web_view loadHTML:WebView::Application::the().generate_process_statistics_html()];
|
||||
}
|
||||
|
||||
@end
|
|
@ -1,46 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Tim Flynn <trflynn89@ladybird.org>
|
||||
* Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
import Ladybird.WebView
|
||||
import Ladybird.WebViewApplication
|
||||
import Ladybird.WebViewWindow
|
||||
import SwiftUI
|
||||
|
||||
public class TaskManager: LadybirdWebViewWindow {
|
||||
|
||||
private let WINDOW_WIDTH: CGFloat = 600
|
||||
private let WINDOW_HEIGHT: CGFloat = 400
|
||||
|
||||
private var timer: Timer?
|
||||
|
||||
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)
|
||||
|
||||
super.init(webView: nil, windowRect: window_rect)
|
||||
|
||||
self.timer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { [weak self] timer in
|
||||
if let strong_self = self {
|
||||
strong_self.updateStatistics()
|
||||
}
|
||||
}
|
||||
|
||||
self.contentView = self.web_view
|
||||
self.title = "Task Manager"
|
||||
self.setIsVisible(true)
|
||||
|
||||
self.updateStatistics()
|
||||
}
|
||||
|
||||
func updateStatistics() {
|
||||
WebView.Application.the().update_process_statistics()
|
||||
self.web_view.loadHTML(WebView.Application.the().generate_process_statistics_html().__bytes_as_string_viewUnsafe())
|
||||
}
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Tim Flynn <trflynn89@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@protocol TaskManagerDelegate <NSObject>
|
||||
|
||||
- (void)onTaskManagerClosed;
|
||||
|
||||
@end
|
||||
|
||||
@interface TaskManagerController : NSWindowController
|
||||
|
||||
- (instancetype)initWithDelegate:(id<TaskManagerDelegate>)delegate;
|
||||
|
||||
@end
|
|
@ -1,65 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Tim Flynn <trflynn89@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#import <Interface/LadybirdWebView.h>
|
||||
#import <Interface/TaskManager.h>
|
||||
#import <Interface/TaskManagerController.h>
|
||||
|
||||
#if !__has_feature(objc_arc)
|
||||
# error "This project requires ARC"
|
||||
#endif
|
||||
|
||||
@interface TaskManagerController () <NSWindowDelegate>
|
||||
|
||||
@property (nonatomic, weak) id<TaskManagerDelegate> delegate;
|
||||
|
||||
@end
|
||||
|
||||
@implementation TaskManagerController
|
||||
|
||||
- (instancetype)initWithDelegate:(id<TaskManagerDelegate>)delegate
|
||||
{
|
||||
if (self = [super init]) {
|
||||
self.delegate = delegate;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
#pragma mark - Private methods
|
||||
|
||||
- (TaskManager*)taskManager
|
||||
{
|
||||
return (TaskManager*)[self window];
|
||||
}
|
||||
|
||||
#pragma mark - NSWindowController
|
||||
|
||||
- (IBAction)showWindow:(id)sender
|
||||
{
|
||||
self.window = [[TaskManager alloc] init];
|
||||
[self.window setDelegate:self];
|
||||
[self.window makeKeyAndOrderFront:sender];
|
||||
}
|
||||
|
||||
#pragma mark - NSWindowDelegate
|
||||
|
||||
- (void)windowWillClose:(NSNotification*)notification
|
||||
{
|
||||
[self.delegate onTaskManagerClosed];
|
||||
}
|
||||
|
||||
- (void)windowDidResize:(NSNotification*)notification
|
||||
{
|
||||
[[[self taskManager] web_view] handleResize];
|
||||
}
|
||||
|
||||
- (void)windowDidChangeBackingProperties:(NSNotification*)notification
|
||||
{
|
||||
[[[self taskManager] web_view] handleDevicePixelRatioChange];
|
||||
}
|
||||
|
||||
@end
|
|
@ -1,50 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Tim Flynn <trflynn89@serenityos.org>
|
||||
* Copyright (c) 2024, Andrew Kaster <akaster@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
@objc
|
||||
public protocol TaskManagerDelegate where Self: NSObject {
|
||||
func onTaskManagerClosed()
|
||||
}
|
||||
|
||||
public class TaskManagerController: NSWindowController, NSWindowDelegate {
|
||||
|
||||
private weak var delegate: TaskManagerDelegate?
|
||||
|
||||
@objc
|
||||
public convenience init(delegate: TaskManagerDelegate) {
|
||||
self.init()
|
||||
self.delegate = delegate
|
||||
}
|
||||
|
||||
@IBAction public override func showWindow(_ sender: Any?) {
|
||||
self.window = TaskManager.init()
|
||||
self.window!.delegate = self
|
||||
self.window!.makeKeyAndOrderFront(sender)
|
||||
}
|
||||
|
||||
public func windowWillClose(_ sender: Notification) {
|
||||
self.delegate?.onTaskManagerClosed()
|
||||
}
|
||||
|
||||
public func windowDidResize(_ sender: Notification) {
|
||||
guard self.window != nil else { return }
|
||||
if !self.window!.inLiveResize {
|
||||
self.taskManager().web_view.handleResize()
|
||||
}
|
||||
}
|
||||
|
||||
public func windowDidChangeBackingProperties(_ sender: Notification) {
|
||||
self.taskManager().web_view.handleDevicePixelRatioChange()
|
||||
}
|
||||
|
||||
private func taskManager() -> TaskManager {
|
||||
return self.window as! TaskManager
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue