mirror of
https://github.com/colanode/colanode.git
synced 2025-12-29 00:25:03 +01:00
Fix asset loading for production build
This commit is contained in:
|
Before Width: | Height: | Size: 1.3 MiB After Width: | Height: | Size: 1.3 MiB |
@@ -10,9 +10,28 @@ import { FuseV1Options, FuseVersion } from '@electron/fuses';
|
||||
const config: ForgeConfig = {
|
||||
packagerConfig: {
|
||||
asar: true,
|
||||
ignore: [
|
||||
/^\/src/,
|
||||
/^\/test/,
|
||||
/^\/tools/,
|
||||
/^\/release/,
|
||||
/^\/docs/,
|
||||
/\.git/,
|
||||
/\.vscode/,
|
||||
/\.idea/,
|
||||
/^\/\.env/,
|
||||
// Don't ignore node_modules
|
||||
// /^\/node_modules/
|
||||
],
|
||||
extraResource: ['assets'],
|
||||
},
|
||||
rebuildConfig: {},
|
||||
makers: [new MakerSquirrel({}), new MakerZIP({}, ['darwin']), new MakerRpm({}), new MakerDeb({})],
|
||||
makers: [
|
||||
new MakerSquirrel({}),
|
||||
new MakerZIP({}, ['darwin']),
|
||||
new MakerRpm({}),
|
||||
new MakerDeb({}),
|
||||
],
|
||||
plugins: [
|
||||
new VitePlugin({
|
||||
// `build` can specify multiple entry builds, which can be Main process, Preload scripts, Worker process, etc.
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<title>Neuron</title>
|
||||
<meta
|
||||
http-equiv="Content-Security-Policy"
|
||||
content="script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: avatar: local-file:; "
|
||||
content="default-src 'self' 'unsafe-inline' data: avatar: local-file: asset:;"
|
||||
/>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@@ -30,7 +30,7 @@ export const getEmojiById = (id: string): Emoji | undefined => {
|
||||
};
|
||||
|
||||
export const getEmojiUrl = (id: string): string => {
|
||||
return `/assets/emojis/${id}.svg`;
|
||||
return `asset://emojis/${id}.svg`;
|
||||
};
|
||||
|
||||
export const searchEmojis = (query: string): Emoji[] => {
|
||||
|
||||
@@ -17,7 +17,7 @@ type IconPickerEmojiRow = {
|
||||
};
|
||||
|
||||
export const getIconUrl = (id: string): string => {
|
||||
return `/assets/icons/${id}.svg`;
|
||||
return `asset://icons/${id}.svg`;
|
||||
};
|
||||
|
||||
export const searchIcons = (query: string): Icon[] => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { app, ipcMain, BrowserWindow, protocol, dialog } from 'electron';
|
||||
import { app, ipcMain, BrowserWindow, protocol, dialog, net } from 'electron';
|
||||
import path from 'path';
|
||||
import { eventBus } from '@/lib/event-bus';
|
||||
import { MutationInput, MutationMap } from '@/operations/mutations';
|
||||
@@ -53,6 +53,20 @@ const createWindow = async () => {
|
||||
protocol.handle('local-file', (request) => {
|
||||
return fileManager.handleFileRequest(request);
|
||||
});
|
||||
|
||||
protocol.handle('asset', (request) => {
|
||||
const url = request.url.replace('asset://', '');
|
||||
if (MAIN_WINDOW_VITE_DEV_SERVER_URL) {
|
||||
return net.fetch(`${MAIN_WINDOW_VITE_DEV_SERVER_URL}/assets/${url}`);
|
||||
}
|
||||
|
||||
const localFileUrl = `file://${path.join(
|
||||
process.resourcesPath,
|
||||
'assets',
|
||||
url,
|
||||
)}`;
|
||||
return net.fetch(localFileUrl);
|
||||
});
|
||||
};
|
||||
|
||||
// This method will be called when Electron has finished
|
||||
|
||||
@@ -18,7 +18,7 @@ const Icon = React.forwardRef<SVGSVGElement, IconProps>((props, ref) => {
|
||||
width={computedSize}
|
||||
{...props}
|
||||
>
|
||||
<use xlinkHref={`/assets/icons.svg#ri-${props.name}`} />
|
||||
<use href={`asset://icons/sprite.svg#ri-${props.name}`} />
|
||||
</svg>
|
||||
);
|
||||
});
|
||||
|
||||
@@ -86,7 +86,7 @@
|
||||
|
||||
@font-face {
|
||||
font-family: 'neotrax';
|
||||
src: url('/assets/neotrax.otf') format('truetype');
|
||||
src: url('asset://fonts/neotrax.otf') format('truetype');
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user