Skip to content

Commit

Permalink
Everything except icons
Browse files Browse the repository at this point in the history
  • Loading branch information
MarvNC committed Jul 24, 2023
1 parent bff54e1 commit 22e7cb9
Show file tree
Hide file tree
Showing 12 changed files with 649 additions and 37 deletions.
24 changes: 24 additions & 0 deletions forge.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,30 @@ module.exports = {
name: '@electron-forge/plugin-auto-unpack-natives',
config: {},
},
{
name: '@electron-forge/plugin-vite',
config: {
// `build` can specify multiple entry builds, which can be Main process, Preload scripts, Worker process, etc.
// If you are familiar with Vite configuration, it will look really familiar.
build: [
{
// `entry` is just an alias for `build.lib.entry` in the corresponding file of `config`.
entry: 'src/index.js',
config: 'vite.main.config.mjs',
},
{
entry: 'src/preload.js',
config: 'vite.preload.config.mjs',
},
],
renderer: [
{
name: 'main_window',
config: 'vite.renderer.config.mjs',
},
],
},
},
],

publishers: [
Expand Down
16 changes: 8 additions & 8 deletions src/index.html → index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8" />
<title>スタンプにゃあ~ | StampNyaa</title>
<link rel="stylesheet" href="../dist/index.css" />
<link rel="stylesheet" href="./dist/index.css" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
Expand Down Expand Up @@ -173,12 +173,12 @@ <h2>by MarvNC</h2>
<span class="material-symbols-outlined"> image </span>
<span class="material-symbols-outlined"> delete </span>
</div>
<script type="module" src="../libs/[email protected]_lib_draggable.bundle.js"></script>
<script type="module" src="./render/addStickerModal.js"></script>
<script type="module" src="./render/menuBar.js"></script>
<script type="module" src="./render/settingsModal.js"></script>
<script type="module" src="./render/stickerRenderer.js"></script>
<script type="module" src="./render/updateModal.js"></script>
<script type="module" src="./renderer.js"></script>
<script type="module" src="./libs/[email protected]_lib_draggable.bundle.js"></script>
<script type="module" src="./src/render/addStickerModal.js"></script>
<script type="module" src="./src/render/menuBar.js"></script>
<script type="module" src="./src/render/settingsModal.js"></script>
<script type="module" src="./src/render/stickerRenderer.js"></script>
<script type="module" src="./src/render/updateModal.js"></script>
<script type="module" src="./src/renderer.js"></script>
</body>
</html>
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"type": "git",
"url": "https://github.com/MarvNC/StampNyaa"
},
"main": "src/index.js",
"main": ".vite/build/index.js",
"scripts": {
"start": "electron-forge start",
"package": "electron-forge package",
Expand Down Expand Up @@ -43,6 +43,7 @@
"@electron-forge/maker-squirrel": "^6.2.1",
"@electron-forge/maker-zip": "^6.2.1",
"@electron-forge/plugin-auto-unpack-natives": "^6.2.1",
"@electron-forge/plugin-vite": "^6.2.1",
"@electron-forge/publisher-github": "^6.2.1",
"electron": "25.2.0",
"electron-builder": "^24.4.0",
Expand Down
35 changes: 28 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@ const {
globalShortcut,
ipcMain,
Menu,
nativeImage,
Tray,
shell,
screen,
} = require('electron');
const path = require('path');
const stickerHandler = require('./utils/stickerHandler');
const Store = require('electron-store');
const downloadPack = require('./utils/lineDownloader');
const checkUpdate = require('./utils/checkUpdate');
const sqlHandler = require('./utils/sqlHandler');

import stickerHandler from './utils/stickerHandler';
import downloadPack from './utils/lineDownloader';
import checkUpdate from './utils/checkUpdate';
import sqlHandler from './utils/sqlHandler';

// Vite URL imports
import ICON_ICO from '../assets/icon.ico';
import ICON_16X16 from '../assets/icon-16x16.png';

// Auto update, but not on first run
const args = process.argv.slice(1);
Expand Down Expand Up @@ -54,12 +60,20 @@ if (require('electron-squirrel-startup')) {
}

const createWindow = () => {
// Create image from ICO buffer
const buffer = Buffer.from(ICON_ICO, 'base64');
const icon = nativeImage.createFromBuffer(buffer);
console.log(icon);
// const icon = nativeImage.createFromBuffer(ICON_ICO);

// Create the browser window.
window = new BrowserWindow({
icon: path.join(__dirname, '../assets/icon.ico'),
icon: icon,
// icon: path.join(__dirname, '../assets/icon.ico'),
width: 930,
height: 900,
webPreferences: {
webSecurity: false,
preload: path.join(__dirname, 'preload.js'),
},
transparent: true,
Expand All @@ -70,7 +84,11 @@ const createWindow = () => {
});

// and load the index.html of the app.
window.loadFile(path.join(__dirname, 'index.html'));
if (MAIN_WINDOW_VITE_DEV_SERVER_URL) {
window.loadURL(MAIN_WINDOW_VITE_DEV_SERVER_URL);
} else {
window.loadFile(path.join(__dirname, `../renderer/${MAIN_WINDOW_VITE_NAME}/index.html`));
}

// open links in default browser
window.webContents.setWindowOpenHandler(({ url }) => {
Expand All @@ -95,7 +113,10 @@ app.on('ready', async () => {
globalShortcut.unregisterAll();
});

const appIcon = new Tray(path.join(__dirname, '../assets/icon-16x16.png'));
// const appIcon = new Tray(path.join(__dirname, '../assets/icon-16x16.png'));
const buffer = Buffer.from(ICON_16X16, 'base64');
const appIconImage = nativeImage.createFromBuffer(buffer);
const appIcon = new Tray(appIconImage);
const contextMenu = Menu.buildFromTemplate([
{
label: 'Quit',
Expand Down
2 changes: 1 addition & 1 deletion src/utils/checkUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ function compareVersionString(v1, v2) {
return false;
}

module.exports = checkUpdate;
export default checkUpdate;
2 changes: 1 addition & 1 deletion src/utils/lineDownloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,4 @@ async function checkImageValidity(imagePath) {
}
}

module.exports = downloadPack;
export default downloadPack;
2 changes: 1 addition & 1 deletion src/utils/sqlHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,4 @@ const sqlHandler = {
},
};

module.exports = sqlHandler;
export default sqlHandler;
2 changes: 1 addition & 1 deletion src/utils/stickerHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ function stripIllegalCharacters(string) {
return string.replace(/[/\\?%*:|"<>]/g, '');
}

module.exports = {
export default {
pasteStickerFromPath,
getAllStickerPacks,
};
10 changes: 10 additions & 0 deletions vite.main.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineConfig } from 'vite';

// https://vitejs.dev/config
export default defineConfig({
resolve: {
// Some libs that can run in both Web and Node.js, such as `axios`, we need to tell Vite to build them in Node.js.
browserField: false,
mainFields: ['module', 'jsnext:main', 'jsnext'],
},
});
4 changes: 4 additions & 0 deletions vite.preload.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { defineConfig } from 'vite';

// https://vitejs.dev/config
export default defineConfig({});
4 changes: 4 additions & 0 deletions vite.renderer.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { defineConfig } from 'vite';

// https://vitejs.dev/config
export default defineConfig({});
Loading

0 comments on commit 22e7cb9

Please sign in to comment.