rebuild macos build

This commit is contained in:
2026-10-17 13:08:32 -06:00
parent 74d9e35b37
commit a2c0eb646f
24 changed files with 1798 additions and 44 deletions
+127
View File
@@ -0,0 +1,127 @@
/* Relocate resources before GTK, Fontconfig, GIO or OpenSSL initialize.
* GPL-2.0-or-later; see COPYING. */
#include "config.h"
#include "macos.h"
#include <gio/gio.h>
#include <mach-o/dyld.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
static char *locale_dir;
static void
set_path (const char *variable, const char *base, const char *relative)
{
char *path = g_build_filename (base, relative, NULL);
g_setenv (variable, path, TRUE);
g_free (path);
}
static void
relocate_cache (const char *resources, const char *name, const char *variable)
{
char *input = g_build_filename (resources, name, NULL);
char *contents = NULL;
GError *error = NULL;
if (g_file_get_contents (input, &contents, NULL, &error))
{
/* GTK cache files require absolute module paths. Write only data to
* the user cache, never into the signed/read-only application bundle. */
char **parts = g_strsplit (contents, "@ZOITECHAT_RESOURCES@", -1);
char *escaped = g_strescape (resources, NULL);
char *relocated = g_strjoinv (escaped, parts);
g_free (escaped);
char *digest = g_compute_checksum_for_string (G_CHECKSUM_SHA256, relocated, -1);
char *directory = g_build_filename (g_get_user_cache_dir (), "zoitechat", "modules", digest, NULL);
char *output = g_build_filename (directory, name, NULL);
if (g_mkdir_with_parents (directory, 0700) == 0 &&
g_file_set_contents (output, relocated, -1, &error))
g_setenv (variable, output, TRUE);
else
g_warning ("Cannot relocate %s: %s", name, error ? error->message : "cannot create cache directory");
g_free (output);
g_free (directory);
g_free (digest);
g_free (relocated);
g_strfreev (parts);
}
else
g_warning ("Cannot read %s: %s", input, error->message);
g_clear_error (&error);
g_free (contents);
g_free (input);
}
void
zoitechat_macos_init (void)
{
uint32_t size = 0;
char *raw, *executable, *macos, *contents, *resources, *marker;
char *ca;
GTlsDatabase *database;
GError *error = NULL;
_NSGetExecutablePath (NULL, &size);
raw = g_malloc (size);
if (_NSGetExecutablePath (raw, &size) != 0)
{
g_free (raw);
return;
}
executable = realpath (raw, NULL);
g_free (raw);
if (!executable)
return;
macos = g_path_get_dirname (executable);
free (executable);
contents = g_path_get_dirname (macos);
resources = g_build_filename (contents, "Resources", NULL);
marker = g_build_filename (resources, "zoitechat-bundle", NULL);
g_free (macos);
g_free (contents);
if (!g_file_test (marker, G_FILE_TEST_IS_REGULAR))
{
g_free (marker);
g_free (resources);
return; /* Ordinary Meson installs and build-tree runs retain their paths. */
}
g_free (marker);
g_setenv ("GDK_BACKEND", "quartz", TRUE);
set_path ("ZOITECHAT_MACOS_SHARE", resources, "share");
set_path ("XDG_DATA_DIRS", resources, "share");
set_path ("GSETTINGS_SCHEMA_DIR", resources, "share/glib-2.0/schemas");
set_path ("FONTCONFIG_FILE", resources, "fonts.conf");
set_path ("GIO_EXTRA_MODULES", resources, "lib/gio/modules");
set_path ("GIO_MODULE_DIR", resources, "lib/gio/modules");
set_path ("ZOITECHAT_LIBDIR", resources, "lib/zoitechat/plugins");
set_path ("ZOITECHAT_EMOJI_FONT", resources, "share/fonts/zoitechat/NotoColorEmoji.ttf");
set_path ("ZOITECHAT_ENCHANT_LIBRARY", resources, "lib/libenchant-2.dylib");
g_setenv ("ZOITECHAT_ENCHANT_PREFIX", resources, TRUE);
set_path ("SSL_CERT_FILE", resources, "certs/ca-bundle.crt");
set_path ("OPENSSL_MODULES", resources, "lib/ossl-modules");
locale_dir = g_build_filename (resources, "share/locale", NULL);
relocate_cache (resources, "pixbuf-loaders.cache", "GDK_PIXBUF_MODULE_FILE");
relocate_cache (resources, "gtk-immodules.cache", "GTK_IM_MODULE_FILE");
/* HTTPS previews use GIO; IRC uses OpenSSL. Give both the same CA set. */
ca = g_build_filename (resources, "certs/ca-bundle.crt", NULL);
database = g_tls_file_database_new (ca, &error);
if (database)
{
g_tls_backend_set_default_database (g_tls_backend_get_default (), database);
g_object_unref (database);
}
else
g_warning ("Cannot load bundled HTTPS trust database: %s", error->message);
g_clear_error (&error);
g_free (ca);
g_free (resources);
}
const char *
zoitechat_macos_locale_dir (void)
{
return locale_dir ? locale_dir : LOCALEDIR;
}
+6
View File
@@ -0,0 +1,6 @@
/* macOS bundle runtime; GPL-2.0-or-later, see COPYING. */
#ifndef ZOITECHAT_MACOS_H
#define ZOITECHAT_MACOS_H
void zoitechat_macos_init (void);
const char *zoitechat_macos_locale_dir (void);
#endif
+13 -2
View File
@@ -29,6 +29,10 @@ common_sources = [
'util.c'
]
if host_machine.system() == 'darwin'
common_sources += 'macos.c'
endif
secretstore_sources = files('secretstore.c')
common_sysinfo_deps = []
@@ -155,12 +159,19 @@ zoitechat_common = static_library('zoitechatcommon',
pic: true
)
# zoitechat.h exposes OpenSSL types whenever TLS is enabled. Propagate its
# header requirements even to standalone consumers that do not call OpenSSL.
zoitechat_common_header_deps = [libgio_dep]
if libssl_dep.found()
zoitechat_common_header_deps += libssl_dep.partial_dependency(compile_args: true, includes: true)
endif
zoitechat_common_dep = declare_dependency(
sources: [textevents, public_suffix_data] + marshal,
link_with: zoitechat_common,
include_directories: common_includes,
compile_args: common_cflags,
dependencies: libgio_dep,
dependencies: zoitechat_common_header_deps,
)
zoitechat_plugin_dep = declare_dependency(
@@ -176,7 +187,7 @@ gtk3_theme_service_tests = executable('gtk3_theme_service_tests',
'gtk3-theme-service.c',
],
include_directories: [config_h_include, include_directories('.')],
dependencies: [libgio_dep] + (libarchive_dep.found() ? [libarchive_dep] : []),
dependencies: zoitechat_common_header_deps + (libarchive_dep.found() ? [libarchive_dep] : []),
)
test('GTK3 Theme Service Tests', gtk3_theme_service_tests,
+7
View File
@@ -54,6 +54,9 @@
#include "text.h"
#include "url.h"
#include "zoitechatc.h"
#ifdef __APPLE__
#include "macos.h"
#endif
#if ! GLIB_CHECK_VERSION (2, 36, 0)
#include <glib-object.h> /* for g_type_init() */
@@ -1172,6 +1175,10 @@ main (int argc, char *argv[])
int i;
int ret;
#ifdef __APPLE__
zoitechat_macos_init ();
#endif
#ifdef WIN32
HRESULT coinit_result;
#endif
+19 -1
View File
@@ -21,6 +21,9 @@
#include <stdlib.h>
#include "fe-gtk.h"
#ifdef __APPLE__
#include "../common/macos.h"
#endif
#ifdef GDK_WINDOWING_WIN32
#include <gdk/gdkwin32.h>
@@ -372,7 +375,13 @@ fe_args (int argc, char *argv[])
g_free (locale_path);
g_free (base_path);
#else
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
bindtextdomain (GETTEXT_PACKAGE,
#ifdef __APPLE__
zoitechat_macos_locale_dir ()
#else
LOCALEDIR
#endif
);
#endif
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);
@@ -493,6 +502,15 @@ fe_args (int argc, char *argv[])
#endif
gtk_init (&argc, &argv);
#ifdef __APPLE__
if (g_getenv ("ZOITECHAT_MACOS_SHARE"))
{
char *icons = g_build_filename (g_getenv ("ZOITECHAT_MACOS_SHARE"), "icons", NULL);
gtk_icon_theme_prepend_search_path (gtk_icon_theme_get_default (), icons);
g_free (icons);
}
#endif
#ifdef WIN32
win32_configure_icon_theme ();
#endif
+16
View File
@@ -53,6 +53,15 @@ zoitechat_gtk_deps = [
gtk_dep = dependency('gtk+-3.0', version: '>= 3.22')
# Standalone GTK tests also include the common application's headers.
gtk_dep = declare_dependency(dependencies: [gtk_dep] + zoitechat_common_header_deps)
# fe-gtk.h exposes GtkosxApplication to every GTK consumer when enabled.
# Theme libraries and standalone UI tests need the same headers as the app.
if host_machine.system() == 'darwin' and gtk_mac_dep.found()
gtk_dep = declare_dependency(dependencies: [gtk_dep, gtk_mac_dep])
endif
zoitechat_theme_deps = [gtk_dep, zoitechat_common_dep]
if host_machine.system() != 'windows'
@@ -91,12 +100,18 @@ if host_machine.system() != 'windows'
endif
zoitechat_gtk_ldflags = []
zoitechat_gtk_objcflags = []
if host_machine.system() == 'windows'
zoitechat_gtk_sources += 'notifications/notification-windows.c'
zoitechat_gtk_deps += cc.find_library('dwmapi', required: true)
zoitechat_theme_deps += cc.find_library('dwmapi', required: true)
elif host_machine.system() == 'darwin'
add_languages('objc', required: true)
zoitechat_gtk_sources += 'notifications/notification-osx.m'
zoitechat_gtk_deps += dependency('appleframeworks', modules: ['Cocoa', 'UserNotifications'])
zoitechat_gtk_objcflags += '-fobjc-arc'
else
zoitechat_gtk_sources += 'notifications/notification-freedesktop.c'
endif
@@ -137,6 +152,7 @@ executable('zoitechat',
dependencies: zoitechat_gtk_deps,
link_with: zoitechat_theme_lib,
c_args: zoitechat_gtk_cflags,
objc_args: zoitechat_gtk_objcflags,
link_args: zoitechat_gtk_ldflags,
pie: true,
install: true,
+51 -38
View File
@@ -1,54 +1,67 @@
/* ZoiteChat
* Copyright (C) 2015 Patrick Griffis.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
/* Native macOS notifications; GPL-2.0-or-later, see COPYING. */
#import <Cocoa/Cocoa.h>
#include <gtkosxapplication.h>
#import <UserNotifications/UserNotifications.h>
void
notification_backend_show (const char *title, const char *text)
@interface ZoiteChatNotificationDelegate : NSObject <UNUserNotificationCenterDelegate>
@end
@implementation ZoiteChatNotificationDelegate
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler
{
NSString *str_title = [[NSString alloc] initWithUTF8String:title];
NSString *str_text = [[NSString alloc] initWithUTF8String:text];
completionHandler(UNNotificationPresentationOptionBanner | UNNotificationPresentationOptionSound);
}
@end
NSUserNotification *userNotification = [NSUserNotification new];
userNotification.title = str_title;
userNotification.informativeText = str_text;
static ZoiteChatNotificationDelegate *notification_delegate;
NSUserNotificationCenter *center = [NSUserNotificationCenter defaultUserNotificationCenter];
[center scheduleNotification:userNotification];
[str_title release];
[str_text release];
int
notification_backend_supported (void)
{
return [[NSBundle mainBundle] bundleIdentifier] != nil;
}
int
notification_backend_init (const char **error)
{
return 1;
if (!notification_backend_supported ())
{
*error = "macOS notifications require an application bundle";
return 0;
}
notification_delegate = [ZoiteChatNotificationDelegate new];
[UNUserNotificationCenter currentNotificationCenter].delegate = notification_delegate;
return 1;
}
void
notification_backend_show (const char *title, const char *text)
{
UNMutableNotificationContent *content = [UNMutableNotificationContent new];
content.title = [NSString stringWithUTF8String:title] ?: @"ZoiteChat";
content.body = [NSString stringWithUTF8String:text] ?: @"";
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
/* Ask only when the user first needs a notification, without blocking GTK. */
[center requestAuthorizationWithOptions:UNAuthorizationOptionAlert | UNAuthorizationOptionSound
completionHandler:^(BOOL granted, NSError *error) {
if (granted)
{
UNNotificationRequest *request = [UNNotificationRequest
requestWithIdentifier:[[NSUUID UUID] UUIDString] content:content trigger:nil];
[center addNotificationRequest:request withCompletionHandler:^(NSError *deliveryError) {
if (deliveryError)
NSLog(@"ZoiteChat notification failed: %@", deliveryError);
}];
}
else if (error)
NSLog(@"ZoiteChat notification authorization failed: %@", error);
}];
}
void
notification_backend_deinit (void)
{
}
int
notification_backend_supported (void)
{
return gtkosx_application_get_bundle_id () != NULL;
if (notification_delegate)
[UNUserNotificationCenter currentNotificationCenter].delegate = nil;
notification_delegate = nil;
}
+16 -1
View File
@@ -215,7 +215,22 @@ initialize_enchant (void)
#endif
};
for (i = 0; i < G_N_ELEMENTS(libnames); ++i)
#ifdef __APPLE__
const char *bundled_enchant = g_getenv ("ZOITECHAT_ENCHANT_LIBRARY");
if (bundled_enchant && *bundled_enchant)
{
enchant = g_module_open (bundled_enchant, 0);
if (enchant)
{
void (*set_prefix) (const char *) = NULL;
const char *prefix = g_getenv ("ZOITECHAT_ENCHANT_PREFIX");
if (prefix && g_module_symbol (enchant, "enchant_set_prefix_dir", (gpointer *) &set_prefix))
set_prefix (prefix);
have_enchant = TRUE;
}
}
#endif
for (i = 0; !have_enchant && i < G_N_ELEMENTS(libnames); ++i)
{
enchant = g_module_open(libnames[i], 0);
if (enchant)
@@ -21,6 +21,7 @@
#include "../../fe-gtk.h"
#include "../theme-application.h"
#include "../theme-css.h"
#include "../theme-policy.h"
#include "../../maingui.h"
#include "../../../common/zoitechat.h"
@@ -45,6 +46,13 @@ fe_message (char *msg, int flags)
message_calls++;
}
/* This test isolates input styling from the application's toplevel CSS. */
char *
theme_css_build_toplevel_classes (void)
{
return g_strdup ("");
}
void
theme_css_reload_input_style (gboolean enabled, const PangoFontDescription *font_desc)
{
+10 -1
View File
@@ -43,6 +43,9 @@
#include "../common/util.h"
#include "../common/fe.h"
#include "fe-text.h"
#ifdef __APPLE__
#include "../common/macos.h"
#endif
static int done = FALSE;
@@ -513,7 +516,13 @@ fe_args (int argc, char *argv[])
g_free (locale_path);
g_free (base_path);
#else
bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
bindtextdomain (GETTEXT_PACKAGE,
#ifdef __APPLE__
zoitechat_macos_locale_dir ()
#else
LOCALEDIR
#endif
);
#endif
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);