Skip to content

Commit

Permalink
Fix missing icon on mac & linux (#117 fixes #87)
Browse files Browse the repository at this point in the history
  • Loading branch information
nedtwigg authored Mar 15, 2023
2 parents 42d173d + 51ffa67 commit 1faf236
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 23 deletions.
1 change: 1 addition & 0 deletions plugin-gradle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format.

## [Unreleased]
- Fix branding for title bar and icon. ([#117](https://github.com/equodev/equo-ide/pull/117) fixes [#87](https://github.com/equodev/equo-ide/issues/87))

## [1.0.1] - 2023-03-13
### Fixed
Expand Down
2 changes: 2 additions & 0 deletions plugin-maven/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format.
## [Unreleased]
### Added
- `<m2e><autoImport>${project.basedir}</autoImport></m2e>` to automatically import the given repo on startup. ([#115](https://github.com/equodev/equo-ide/pull/115) implements [#18](https://github.com/equodev/equo-ide/issues/18))
### Fixed
- Fix branding for title bar and icon. ([#117](https://github.com/equodev/equo-ide/pull/117) fixes [#87](https://github.com/equodev/equo-ide/issues/87))

## [0.16.5] - 2023-03-13
### Fixed
Expand Down
2 changes: 2 additions & 0 deletions solstice/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format.
### Added
- Added `SignedJars` which can strip signatures when necessary (e.g. a signed Eclipse jar contributing classes to the same package as one of its nested jars). ([#116](https://github.com/equodev/equo-ide/pull/116))
- `NestedJars.transitiveDeps` is now smart about only adding `slf4j` deps when they are absent ([#115](https://github.com/equodev/equo-ide/pull/115/commits/6bcf66e9e35d2ca4ab1b6da1bae1ddbf0c17fd63))
### Fixed
- Fix branding for title bar and icon. ([#117](https://github.com/equodev/equo-ide/pull/117) fixes [#87](https://github.com/equodev/equo-ide/issues/87))

## [1.0.3] - 2023-03-13
### Fixed
Expand Down
112 changes: 89 additions & 23 deletions solstice/src/main/java/dev/equo/ide/IdeHookBranding.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,25 @@
*******************************************************************************/
package dev.equo.ide;

import com.diffplug.common.swt.os.OS;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import javax.annotation.Nullable;
import org.eclipse.core.internal.runtime.InternalPlatform;
import org.eclipse.core.runtime.IProduct;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.internal.ide.IDEInternalPreferences;
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@SuppressWarnings("serial")
Expand Down Expand Up @@ -52,6 +62,15 @@ public IdeHookInstantiated instantiate() {
}

class Instantiated implements IdeHookInstantiated {
Logger logger = LoggerFactory.getLogger(IdeHookBranding.class);

@Override
public void isClean(boolean isClean) throws Exception {
if (OS.getRunning().isMac()) {
System.setProperty("com.apple.mrj.application.apple.menu.about.name", title);
}
}

private Shell splash;

private Image loadImage(Display display, File file, String defaultResource) {
Expand All @@ -74,6 +93,57 @@ private Image loadImage(Display display, File file, String defaultResource) {
}
}

@Override
public void afterOsgi(BundleContext context) {
var internal = InternalPlatform.getDefault();
try {
var product = internal.getClass().getDeclaredField("product");
product.setAccessible(true);
product.set(
internal,
new IProduct() {
@Override
public String getApplication() {
return title;
}

@Override
public String getName() {
return title;
}

@Override
public String getDescription() {
return title;
}

@Override
public String getId() {
return title;
}

@Override
public String getProperty(String key) {
return null;
}

@Override
public Bundle getDefiningBundle() {
return Arrays.stream(context.getBundles())
.filter(bundle -> bundle.getSymbolicName().equals("dev.equo.ide"))
.findFirst()
.get();
}
});

IPreferenceStore ps = IDEWorkbenchPlugin.getDefault().getPreferenceStore();
ps.setValue(IDEInternalPreferences.SHOW_LOCATION_NAME, false);
ps.setValue(IDEInternalPreferences.SHOW_PRODUCT_IN_TITLE, true);
} catch (Exception e) {
logger.warn("problem defining product", e);
}
}

@Override
public void afterDisplay(Display display) {
var cursor = display.getCursorLocation();
Expand All @@ -89,7 +159,7 @@ public void afterDisplay(Display display) {
int imgX = image.getBounds().width;
int imgY = image.getBounds().height;
splash = new Shell(display, SWT.NO_TRIM | SWT.ON_TOP);
splash.setText("Branding");
splash.setText(title);
splash.setBounds(
bestMonitor.x + (bestMonitor.width - imgX / 2) / 2,
bestMonitor.y + (bestMonitor.height - imgY / 2) / 2,
Expand All @@ -106,38 +176,34 @@ public void afterDisplay(Display display) {
splash.open();
splash.forceActive();

Display.setAppName(title);
while (display.readAndDispatch())
// pump the event loop enough to show the branding
;

// now set the application icon
Image icon =
loadImage(Display.getDefault(), IdeHookBranding.this.icon, "dev/equo/ide/equo_icon.png");
var bounds = icon.getBounds();
if (bounds.width != bounds.height) {
LoggerFactory.getLogger(IdeHookBranding.class)
.warn("Icon should be square, but is instead {} by {}", bounds.width, bounds.height);
}
Window.setDefaultImage(icon);
}

@Override
public void postStartup() {
splash.dispose();
splash = null;

Display.getDefault()
.asyncExec(
() -> {
var display = Display.getCurrent();
if (display == null) {
// early shutdown
return;
}
Display.setAppName(title);
Image icon =
loadImage(
Display.getDefault(),
IdeHookBranding.this.icon,
"dev/equo/ide/equo_icon.png");
Shell[] shells = display.getShells();
for (var shell : shells) {
shell.setText(title);
shell.setImage(icon);
shell.forceActive();
}
});
// setup the task item
var taskBar = Display.getDefault().getSystemTaskBar();
if (taskBar != null) {
var item = taskBar.getItem(null);
if (item != null) {
item.setText(title);
}
}
}
}
}

0 comments on commit 1faf236

Please sign in to comment.