From b0dcb9d834a0cc5e531fd9e919e62598af4962d0 Mon Sep 17 00:00:00 2001 From: Toinane Date: Fri, 18 Mar 2022 19:58:36 +0100 Subject: [PATCH] feat: add Windows support --- package.json | 1 + src/main/index.ts | 24 ++++- src/main/store/module/app.ts | 4 + src/main/types/index.d.ts | 1 + src/renderer/App.vue | 24 ++--- src/renderer/components/AppFileList.vue | 1 + src/renderer/components/AppTitleBar.vue | 116 ++++++++++++++++++++++++ src/renderer/components/ui/AppInput.vue | 3 +- src/renderer/types/components.d.ts | 3 +- src/scripts/dev-server.ts | 10 +- yarn.lock | 2 +- 11 files changed, 165 insertions(+), 24 deletions(-) create mode 100644 src/renderer/components/AppTitleBar.vue diff --git a/package.json b/package.json index b4e1e49..1b10814 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "main": "build/src/main/index.js", "scripts": { "dev": "tsc-watch -p tsconfig.electron.json --onSuccess 'npm run dev:server'", + "dev:win": "tsc-watch -p tsconfig.electron.json", "dev:server": "node build/src/scripts/dev-server.js", "build:ts": "tsc -p tsconfig.electron.json", "build": "npm run build:ts && node build/src/scripts/build.js ", diff --git a/src/main/index.ts b/src/main/index.ts index 220c79d..0ed54ee 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -1,5 +1,7 @@ import { app, BrowserWindow, ipcMain, Menu, shell } from 'electron' +import type { Rectangle } from 'electron' import path from 'path' +import { platform } from 'process' import { store } from './store' import { checkForUpdate } from './update-check' import { ImageOptimizer } from './image-compressor' @@ -8,12 +10,21 @@ import { createMenu } from './menu' const isDev = process.env.NODE_ENV === 'development' let mainWindow: BrowserWindow +function getPlatform () { + switch (platform) { + case 'darwin': return 'macos' + case 'win32': return 'windows' + default: return 'linux' + } +} + function createWindow () { - const bounds = store.app.get('bounds') + const { x, y } = store.app.get('bounds') as Rectangle mainWindow = new BrowserWindow({ width: 550, height: 370, - ...bounds, + x, + y, titleBarStyle: 'hidden', resizable: false, backgroundColor: '#212123', @@ -40,6 +51,7 @@ function createWindow () { } function init () { + store.app.set('os', getPlatform()) createWindow() checkForUpdate(mainWindow) Menu.setApplicationMenu(Menu.buildFromTemplate(createMenu(mainWindow))) @@ -72,6 +84,14 @@ ipcMain.on('drop', (_, files = []) => { optimizer.start() }) +ipcMain.on('toolbar', (_, type) => { + switch (type) { + case 'reduce': return mainWindow.minimize() + case 'maximize': return mainWindow.maximize() + case 'close': return mainWindow.close() + } +}) + ipcMain.on('open-url', (event, url) => { shell.openExternal(url) }) diff --git a/src/main/store/module/app.ts b/src/main/store/module/app.ts index 8ba9d92..1319c93 100644 --- a/src/main/store/module/app.ts +++ b/src/main/store/module/app.ts @@ -6,6 +6,10 @@ export default new Store({ watch: true, schema: { + os: { + type: 'string', + default: 'macos' + }, bounds: { type: 'object', default: {} diff --git a/src/main/types/index.d.ts b/src/main/types/index.d.ts index 507b7d6..1f1712f 100644 --- a/src/main/types/index.d.ts +++ b/src/main/types/index.d.ts @@ -23,6 +23,7 @@ declare global { } export interface StoreSchema { + os: ['macos', 'windows', 'linux'] bounds: object addToSubfolder: boolean addMinSuffix: boolean diff --git a/src/renderer/App.vue b/src/renderer/App.vue index 3bc2aac..dcd8132 100644 --- a/src/renderer/App.vue +++ b/src/renderer/App.vue @@ -1,5 +1,7 @@ -