Skip to content

Commit

Permalink
Mac: ネイティブの三色ボタン(最小化・最大化・閉じるボタン)を使うように変更 (VOICEVOX#621)
Browse files Browse the repository at this point in the history
* use native traffic light on mac

* update Vuex.spec.ts for test

* make disable dark mode for macOS

* fix quote

* trivial change

* artifact_name -> macos_artifact_name

* hard-coding mac app name

* ダークモード無効化をアプリ側で対応

* npm run fmt

* Mac の場合だけライトモード固定にするように変更

* Macでlightモード指定している理由をコメントに記載
  • Loading branch information
PickledChair authored Dec 29, 2021
1 parent cbf437e commit e49d172
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 4 deletions.
21 changes: 20 additions & 1 deletion src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@ import dotenv from "dotenv";
import treeKill from "tree-kill";
import Store from "electron-store";

import { app, protocol, BrowserWindow, dialog, Menu, shell } from "electron";
import {
app,
protocol,
BrowserWindow,
dialog,
Menu,
shell,
nativeTheme,
} from "electron";
import { createProtocol } from "vue-cli-plugin-electron-builder/lib";
import installExtension, { VUEJS3_DEVTOOLS } from "electron-devtools-installer";

Expand Down Expand Up @@ -441,6 +449,8 @@ async function createWindow() {
width: 800,
height: 600,
frame: false,
titleBarStyle: "hidden",
trafficLightPosition: { x: 6, y: 4 },
minWidth: 320,
show: false,
webPreferences: {
Expand All @@ -461,8 +471,17 @@ async function createWindow() {
}
if (isDevelopment) win.webContents.openDevTools();

// Macではdarkモードかつウィンドウが非アクティブのときに閉じるボタンなどが見えなくなるので、lightモードに固定
if (isMac) nativeTheme.themeSource = "light";

win.on("maximize", () => win.webContents.send("DETECT_MAXIMIZED"));
win.on("unmaximize", () => win.webContents.send("DETECT_UNMAXIMIZED"));
win.on("enter-full-screen", () =>
win.webContents.send("DETECT_ENTER_FULLSCREEN")
);
win.on("leave-full-screen", () =>
win.webContents.send("DETECT_LEAVE_FULLSCREEN")
);
win.on("always-on-top-changed", () => {
win.webContents.send(
win.isAlwaysOnTop() ? "DETECT_PINNED" : "DETECT_UNPINNED"
Expand Down
13 changes: 10 additions & 3 deletions src/components/MenuBar.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<template>
<q-bar class="bg-background q-pa-none relative-position">
<min-max-close-buttons v-if="$q.platform.is.mac" />
<div
v-if="$q.platform.is.mac && !isFullscreen"
class="mac-traffic-light-space"
></div>
<img v-else src="icon.png" class="window-logo" alt="application logo" />
<menu-button
v-for="(root, index) of menudata"
Expand Down Expand Up @@ -30,7 +33,6 @@
<script lang="ts">
import { defineComponent, ref, computed, ComputedRef, watch } from "vue";
import { useStore } from "@/store";
import MinMaxCloseButtons from "@/components/MinMaxCloseButtons.vue";
import MenuButton from "@/components/MenuButton.vue";
import TitleBarButtons from "@/components/TitleBarButtons.vue";
import { useQuasar } from "quasar";
Expand Down Expand Up @@ -75,7 +77,6 @@ export default defineComponent({
name: "MenuBar",
components: {
MinMaxCloseButtons,
MenuButton,
TitleBarButtons,
},
Expand All @@ -91,6 +92,7 @@ export default defineComponent({
const menubarLocked = computed(() => store.getters.MENUBAR_LOCKED);
const projectName = computed(() => store.getters.PROJECT_NAME);
const isEdited = computed(() => store.getters.IS_EDITED);
const isFullscreen = computed(() => store.getters.IS_FULLSCREEN);
const createNewProject = async () => {
if (!uiLocked.value) {
Expand Down Expand Up @@ -359,6 +361,7 @@ export default defineComponent({
menubarLocked,
projectName,
isEdited,
isFullscreen,
subMenuOpenFlags,
reassignSubMenuOpen,
menudata,
Expand Down Expand Up @@ -398,4 +401,8 @@ export default defineComponent({
text-overflow: ellipsis;
overflow: hidden;
}
.mac-traffic-light-space {
margin-right: 70px;
}
</style>
8 changes: 8 additions & 0 deletions src/plugins/ipcMessageReceiverPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ export const ipcMessageReceiver: Plugin = {
options.store.dispatch("DETECT_UNPINNED");
});

window.electron.onReceivedIPCMsg("DETECT_ENTER_FULLSCREEN", () =>
options.store.dispatch("DETECT_ENTER_FULLSCREEN")
);

window.electron.onReceivedIPCMsg("DETECT_LEAVE_FULLSCREEN", () =>
options.store.dispatch("DETECT_LEAVE_FULLSCREEN")
);

window.electron.onReceivedIPCMsg("CHECK_EDITED_AND_NOT_SAVE", () => {
options.store.dispatch("CHECK_EDITED_AND_NOT_SAVE");
});
Expand Down
15 changes: 15 additions & 0 deletions src/store/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,7 @@ export type UiStoreState = {
isAcceptRetrieveTelemetryDialogOpen: boolean;
isMaximized: boolean;
isPinned: boolean;
isFullscreen: boolean;
};

type UiStoreTypes = {
Expand Down Expand Up @@ -870,6 +871,20 @@ type UiStoreTypes = {
action(): void;
};

DETECT_ENTER_FULLSCREEN: {
mutation: undefined;
action(): void;
};

DETECT_LEAVE_FULLSCREEN: {
mutation: undefined;
action(): void;
};

IS_FULLSCREEN: {
getter: boolean;
};

CHECK_EDITED_AND_NOT_SAVE: {
action(): Promise<void>;
};
Expand Down
16 changes: 16 additions & 0 deletions src/store/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const uiStoreState: UiStoreState = {
isAcceptRetrieveTelemetryDialogOpen: false,
isMaximized: false,
isPinned: false,
isFullscreen: false,
};

export const uiStore: VoiceVoxStoreOptions<UiGetters, UiActions, UiMutations> =
Expand All @@ -52,6 +53,9 @@ export const uiStore: VoiceVoxStoreOptions<UiGetters, UiActions, UiMutations> =
SHOULD_SHOW_PANES(_, getters) {
return getters.ACTIVE_AUDIO_KEY != undefined;
},
IS_FULLSCREEN(state) {
return state.isFullscreen;
},
},

mutations: {
Expand Down Expand Up @@ -118,6 +122,12 @@ export const uiStore: VoiceVoxStoreOptions<UiGetters, UiActions, UiMutations> =
DETECT_UNPINNED(state) {
state.isPinned = false;
},
DETECT_ENTER_FULLSCREEN(state) {
state.isFullscreen = true;
},
DETECT_LEAVE_FULLSCREEN(state) {
state.isFullscreen = false;
},
},

actions: {
Expand Down Expand Up @@ -266,6 +276,12 @@ export const uiStore: VoiceVoxStoreOptions<UiGetters, UiActions, UiMutations> =
async DETECT_UNPINNED({ commit }) {
commit("DETECT_UNPINNED");
},
async DETECT_ENTER_FULLSCREEN({ commit }) {
commit("DETECT_ENTER_FULLSCREEN");
},
async DETECT_LEAVE_FULLSCREEN({ commit }) {
commit("DETECT_LEAVE_FULLSCREEN");
},
async CHECK_EDITED_AND_NOT_SAVE({ getters }) {
if (getters.IS_EDITED) {
const result: number = await window.electron.showInfoDialog({
Expand Down
10 changes: 10 additions & 0 deletions src/type/ipc.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,16 @@ type IpcSOData = {
return: void;
};

DETECT_ENTER_FULLSCREEN: {
args: [];
return: void;
};

DETECT_LEAVE_FULLSCREEN: {
args: [];
return: void;
};

CHECK_EDITED_AND_NOT_SAVE: {
args: [];
return: void;
Expand Down
1 change: 1 addition & 0 deletions tests/unit/store/Vuex.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ describe("store/vuex.js test", () => {
availableThemes: [],
},
isPinned: false,
isFullscreen: false,
presetItems: {},
presetKeys: [],
hotkeySettings: [],
Expand Down

0 comments on commit e49d172

Please sign in to comment.