5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-04 01:00:21 +08:00

Handle no tray icons

This commit is contained in:
Lea Anthony 2020-12-28 14:49:15 +11:00
parent 25f464c177
commit e18ba0eb81
No known key found for this signature in database
GPG Key ID: 33DAF7BB90A58405
2 changed files with 22 additions and 15 deletions

View File

@ -684,10 +684,6 @@ void closeWindow(id self, SEL cmd, id sender) {
app->sendMessageToBackend("WC");
}
void willFinishLaunching(id self, SEL cmd, id sender) {
struct Application *app = (struct Application *) objc_getAssociatedObject(self, "application");
}
bool isDarkMode(struct Application *app) {
id userDefaults = msg(c("NSUserDefaults"), s("standardUserDefaults"));
const char *mode = cstr(msg(userDefaults, s("stringForKey:"), str("AppleInterfaceStyle")));
@ -703,19 +699,25 @@ void ExecJS(struct Application *app, const char *js) {
);
}
void willFinishLaunching(id self, SEL cmd, id sender) {
struct Application *app = (struct Application *) objc_getAssociatedObject(self, "application");
messageFromWindowCallback("Ej{\"name\":\"wails:launched\",\"data\":[]}");
}
void emitThemeChange(struct Application *app) {
bool currentThemeIsDark = isDarkMode(app);
if (currentThemeIsDark) {
messageFromWindowCallback("ETT");
messageFromWindowCallback("Ej{\"name\":\"wails:system:themechange\",\"data\":[true]}");
} else {
messageFromWindowCallback("ETF");
messageFromWindowCallback("Ej{\"name\":\"wails:system:themechange\",\"data\":[false]}");
}
}
void themeChanged(id self, SEL cmd, id sender) {
struct Application *app = (struct Application *)objc_getAssociatedObject(
self, "application");
bool currentThemeIsDark = isDarkMode(app);
// emitThemeChange(app);
bool currentThemeIsDark = isDarkMode(app);
if ( currentThemeIsDark ) {
ExecJS(app, "window.wails.Events.Emit( 'wails:system:themechange', true );");
} else {
@ -2571,7 +2573,7 @@ void Run(struct Application *app, int argc, char **argv) {
// Emit theme change event to notify of current system them
// emitThemeChange(app);
emitThemeChange(app);
// If we want the webview to be transparent...
if( app->webviewIsTranparent == 1 ) {

View File

@ -5,6 +5,7 @@ package build
import (
"fmt"
"github.com/leaanthony/slicer"
"github.com/wailsapp/wails/v2/internal/fs"
"io/ioutil"
"log"
"path/filepath"
@ -27,13 +28,14 @@ func (d *DesktopBuilder) processTrayIcons(assetDir string, options *Options) err
// Get all the tray icon filenames
trayIconDirectory := filepath.Join(options.ProjectData.Path, "trayicons")
trayIconFilenames, err := filepath.Glob(trayIconDirectory + "/*.png")
if err != nil {
log.Fatal(err)
return err
var trayIconFilenames []string
if fs.DirExists(trayIconDirectory) {
trayIconFilenames, err = filepath.Glob(trayIconDirectory + "/*.png")
if err != nil {
log.Fatal(err)
return err
}
}
// Setup target
targetFilename := "trayicons"
targetFile := filepath.Join(assetDir, targetFilename+".c")
@ -88,7 +90,10 @@ func (d *DesktopBuilder) processTrayIcons(assetDir string, options *Options) err
// Write out main trayIcons data
cdata.WriteString("const unsigned char *trayIcons[] = { ")
cdata.WriteString(variableList.Join(", "))
cdata.WriteString(", 0x00 };\n")
if len(trayIconFilenames) > 0 {
cdata.WriteString(", ")
}
cdata.WriteString("0x00 };\n")
err = ioutil.WriteFile(targetFile, []byte(cdata.String()), 0600)
if err != nil {