Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Associate .chn with chaiNNer on MacOS #2115

Merged
merged 1 commit into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions forge.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ const deletePycFiles = async (directory) => {
const config = {
packagerConfig: {
executableName: process.platform === 'linux' ? 'chainner' : 'chaiNNer',
extraResource: './backend/src/',
extraResource: ['./backend/src/', './src/public/icons/mac/file_chn.icns'],
icon: './src/public/icons/cross_platform/icon',
appBundleId: 'app.chainner',
appCategoryType: 'public.app-category.graphics-design',
extendInfo: { LSMinimumSystemVersion: '11.0.0' },
extendInfo: './src/public/Info.plist',
},
publishers: [
{
Expand Down
50 changes: 32 additions & 18 deletions src/main/gui/main-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import EventSource from 'eventsource';
import { t } from 'i18next';
import { BackendEventMap } from '../../common/Backend';
import { Version, WindowSize } from '../../common/common-types';
import { isMac } from '../../common/env';
import { log } from '../../common/log';
import { BrowserWindowWithSafeIpc, ipcMain } from '../../common/safeIpc';
import { SaveFile, openSaveFile } from '../../common/SaveFile';
Expand Down Expand Up @@ -125,26 +126,39 @@ const registerEventHandlerPreSetup = (
mainWindow.webContents.send('window-blur');
});

// Opening file with chaiNNer
if (args.file) {
const result = openSaveFile(args.file);
ipcMain.handle('get-cli-open', () => result);
if (isMac) {
// Open file with chaiNNer on macOS
app.on('open-file', (event, filePath) => {
(async () => {
const file = filePath;
if (file) {
const result = await openSaveFile(file);
mainWindow.webContents.send('file-open', result);
}
})().catch(log.error);
});
} else {
ipcMain.handle('get-cli-open', () => undefined);
}
// Opening file with chaiNNer on other platforms
if (args.file) {
const result = openSaveFile(args.file);
ipcMain.handle('get-cli-open', () => result);
} else {
ipcMain.handle('get-cli-open', () => undefined);
}

app.on('second-instance', (_event, commandLine) => {
(async () => {
const { file } = parseArgs(commandLine.slice(app.isPackaged ? 2 : 3));
if (file) {
const result = await openSaveFile(file);
mainWindow.webContents.send('file-open', result);
}
// Focus main window if a second instance was attempted
if (mainWindow.isMinimized()) mainWindow.restore();
mainWindow.focus();
})().catch(log.error);
});
app.on('second-instance', (_event, commandLine) => {
(async () => {
const { file } = parseArgs(commandLine.slice(app.isPackaged ? 2 : 3));
if (file) {
const result = await openSaveFile(file);
mainWindow.webContents.send('file-open', result);
}
// Focus main window if a second instance was attempted
if (mainWindow.isMinimized()) mainWindow.restore();
mainWindow.focus();
})().catch(log.error);
});
}
};

const registerEventHandlerPostSetup = (
Expand Down
26 changes: 26 additions & 0 deletions src/public/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>LSMinimumSystemVersion</key>
<string>11.0.0</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>chn</string>
<string>CHN</string>
</array>
<key>CFBundleTypeIconFile</key>
<string>file_chn.icns</string>
<key>CFBundleTypeName</key>
<string>chaiNNer Chain File</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSHandlerRank</key>
<string>Default</string>
</dict>
</array>
</dict>
</plist>
Binary file added src/public/icons/mac/file_chn.icns
Binary file not shown.
Binary file modified src/public/icons/mac/icon.icns
Binary file not shown.