Skip to content

Commit

Permalink
🖥️ wip: attempts to make frameless window draggable
Browse files Browse the repository at this point in the history
  • Loading branch information
KiritoKing committed Apr 15, 2023
1 parent 3b7de5e commit c3c40c6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/main/Handlers/SaveConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ import { writeFileSync } from 'fs';
import path from 'path';
import { getConfig } from '../util';
import { IConfig, ipcHanlder } from '../typing';
import { setWindowTitle } from '../main';

// SendMessage: 入参要求:arg[0]=IConfig对象
const saveConfigHandler: ipcHanlder = (_event, args) => {
if (!(args && args[0])) return; // 参数不正确
const newConfig = args[0] as IConfig;
if (newConfig?.title) setWindowTitle(newConfig.title);
const oldConfig = getConfig();
const configPath = path.join(oldConfig.workFolder, 'config.json');
writeFileSync(configPath, JSON.stringify(newConfig));
Expand Down
12 changes: 11 additions & 1 deletion src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import path from 'path';
import { app, BrowserWindow, ipcMain, Menu } from 'electron';
import { resolveHtmlPath } from './util';
import { getConfig, resolveHtmlPath } from './util';
import importFileHandler from './Handlers/ImportFile';
import openFolderHandler from './Handlers/OpenFolder';
import saveResultHandler from './Handlers/SaveResultHandler';
Expand Down Expand Up @@ -61,6 +61,7 @@ const createWindow = async () => {
? path.join(__dirname, 'preload.js')
: path.join(__dirname, '../../.erb/dll/preload.js'),
},
// frame: isDebug,
});

mainWindow.loadURL(resolveHtmlPath('index.html'));
Expand All @@ -74,6 +75,8 @@ const createWindow = async () => {
} else {
mainWindow.show();
}
const title = getConfig()?.title;
if (title) mainWindow.title = title;
});

mainWindow.on('closed', () => {
Expand Down Expand Up @@ -121,3 +124,10 @@ app
}
})
.catch(console.log);

// eslint-disable-next-line import/prefer-default-export
export const setWindowTitle = (title: string) => {
if (mainWindow) {
mainWindow.setTitle(title);
}
};
7 changes: 6 additions & 1 deletion src/renderer/Components/HeadBar/styles.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@
user-select: none;
-webkit-user-select: none;
max-height: 60px;
// -webkit-app-region: drag;
-webkit-app-region: drag !important;
}

// .titleBar button,
// .titleBar a {
// -webkit-app-region: no-drag;
// }

0 comments on commit c3c40c6

Please sign in to comment.