Refactoring
This commit is contained in:
parent
4d0d302900
commit
ee18182915
|
@ -11,12 +11,12 @@ import {
|
||||||
import ContextMenu from 'electron-context-menu'
|
import ContextMenu from 'electron-context-menu'
|
||||||
|
|
||||||
import Application from './main/Application'
|
import Application from './main/Application'
|
||||||
import ApplicationMenu from "./main/ApplicationMenu";
|
import ApplicationMenu from './main/ApplicationMenu'
|
||||||
|
|
||||||
export type PackageJson = typeof import('../package.json');
|
export type PackageJson = typeof import('../package.json')
|
||||||
import { author, contributors, homepage } from '../package.json'
|
import { author, contributors, homepage } from '../package.json'
|
||||||
import TheDeskInfo from '../info.json'
|
import TheDeskInfo from '../info.json'
|
||||||
export type TheDeskInfoObject = typeof TheDeskInfo;
|
export type TheDeskInfoObject = typeof TheDeskInfo
|
||||||
|
|
||||||
ipcMain.on('thedesk-info', (event: Event) => {
|
ipcMain.on('thedesk-info', (event: Event) => {
|
||||||
event.returnValue = Object.assign({
|
event.returnValue = Object.assign({
|
||||||
|
@ -24,13 +24,11 @@ ipcMain.on('thedesk-info', (event: Event) => {
|
||||||
author: author,
|
author: author,
|
||||||
contributors: contributors,
|
contributors: contributors,
|
||||||
homePage: homepage,
|
homePage: homepage,
|
||||||
versions: Object.assign(pick(process.versions, ["chrome", "electron", "node"]), { internal: app.getVersion() }),
|
versions: Object.assign(pick(process.versions, ['chrome', 'electron', 'node']), { internal: app.getVersion() }),
|
||||||
}, TheDeskInfo)
|
}, TheDeskInfo)
|
||||||
})
|
})
|
||||||
|
|
||||||
const isDevelopment = process.env.NODE_ENV !== 'production'
|
if (process.env.NODE_ENV !== 'production') {
|
||||||
|
|
||||||
if (isDevelopment) {
|
|
||||||
if (process.platform === 'win32') {
|
if (process.platform === 'win32') {
|
||||||
process.on('message', data => {
|
process.on('message', data => {
|
||||||
if (data === 'graceful-exit') {
|
if (data === 'graceful-exit') {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
import Vue from 'vue';
|
import Vue from 'vue'
|
||||||
import { upperFirst, camelCase } from 'lodash'
|
import { upperFirst, camelCase } from 'lodash'
|
||||||
|
|
||||||
const requireComponent = require.context('./globals', false, /Base[A-Z]\w+\.(vue|js)$/)
|
const requireComponent = require.context('./globals', false, /Base[A-Z]\w+\.(vue|js)$/)
|
||||||
|
|
|
@ -11,17 +11,17 @@ import Window from './Window'
|
||||||
const isDevelopment = process.env.NODE_ENV !== 'production'
|
const isDevelopment = process.env.NODE_ENV !== 'production'
|
||||||
|
|
||||||
export default class Application {
|
export default class Application {
|
||||||
private static _instance: Application;
|
private static _instance: Application
|
||||||
|
|
||||||
public static get shared() {
|
public static get shared() {
|
||||||
// Do you need arguments? Make it a regular static method instead.
|
// Do you need arguments? Make it a regular static method instead.
|
||||||
return this._instance || (this._instance = new this());
|
return this._instance || (this._instance = new this())
|
||||||
}
|
}
|
||||||
|
|
||||||
private constructor() {
|
private constructor() {
|
||||||
app.on('window-all-closed', () => this.onWindowAllClosed())
|
app.on('window-all-closed', () => this.onWindowAllClosed())
|
||||||
app.on('ready', () => this.onReady());
|
app.on('ready', () => this.onReady())
|
||||||
app.on('activate', () => this.onActivated());
|
app.on('activate', () => this.onActivated())
|
||||||
}
|
}
|
||||||
|
|
||||||
public setApplicationMenu(menu: Menu) {
|
public setApplicationMenu(menu: Menu) {
|
||||||
|
|
|
@ -3,10 +3,10 @@ import {
|
||||||
shell,
|
shell,
|
||||||
Menu,
|
Menu,
|
||||||
MenuItemConstructorOptions
|
MenuItemConstructorOptions
|
||||||
} from 'electron';
|
} from 'electron'
|
||||||
import Window from "./Window";
|
import Window from './Window'
|
||||||
import { bugs } from '../../package.json';
|
import { bugs } from '../../package.json'
|
||||||
import { documentURL } from '../../info.json';
|
import { documentURL } from '../../info.json'
|
||||||
|
|
||||||
const isMac = process.platform === 'darwin'
|
const isMac = process.platform === 'darwin'
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ export default class ApplicationMenu {
|
||||||
{ role: 'hide' },
|
{ role: 'hide' },
|
||||||
{ role: 'hideOthers' },
|
{ role: 'hideOthers' },
|
||||||
{ role: 'unhide' },
|
{ role: 'unhide' },
|
||||||
];
|
]
|
||||||
private static macOnlyEditMenu: MenuItemConstructorOptions[] = [
|
private static macOnlyEditMenu: MenuItemConstructorOptions[] = [
|
||||||
{ type: 'separator' },
|
{ type: 'separator' },
|
||||||
{
|
{
|
||||||
|
@ -29,38 +29,38 @@ export default class ApplicationMenu {
|
||||||
{ role: 'stopspeaking' },
|
{ role: 'stopspeaking' },
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
];
|
]
|
||||||
private static aboutMenuItem: MenuItemConstructorOptions = {
|
private static aboutMenuItem: MenuItemConstructorOptions = {
|
||||||
label: process.platform !== 'darwin' ? 'About' : `About ${app.getName()}`,
|
label: !isMac ? 'About' : `About ${app.getName()}`,
|
||||||
click: () => Window.About(),
|
click: () => Window.About(),
|
||||||
}
|
}
|
||||||
|
|
||||||
public static get menuConstruct(): MenuItemConstructorOptions[] {
|
public static get menuConstruct(): MenuItemConstructorOptions[] {
|
||||||
return [
|
return [
|
||||||
this.AppMenu(isMac),
|
this.AppMenu(),
|
||||||
this.EditMenu(isMac),
|
this.EditMenu(),
|
||||||
this.ViewMenu(),
|
this.ViewMenu(),
|
||||||
this.WindowMenu(isMac),
|
this.WindowMenu(),
|
||||||
this.HelpMenu(),
|
this.HelpMenu(),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
public static buildTemplate(): Menu {
|
public static buildTemplate(): Menu {
|
||||||
return Menu.buildFromTemplate(this.menuConstruct);
|
return Menu.buildFromTemplate(this.menuConstruct)
|
||||||
}
|
}
|
||||||
private static AppMenu(isMac: boolean): MenuItemConstructorOptions {
|
private static AppMenu(): MenuItemConstructorOptions {
|
||||||
let appMenu: MenuItemConstructorOptions[] = [
|
let appMenu: MenuItemConstructorOptions[] = [
|
||||||
this.aboutMenuItem,
|
this.aboutMenuItem,
|
||||||
...(isMac ? this.macOnlyAppMenu : []),
|
...(isMac ? this.macOnlyAppMenu : []),
|
||||||
{ type: 'separator' },
|
{ type: 'separator' },
|
||||||
{ role: 'quit' },
|
{ role: 'quit' },
|
||||||
];
|
]
|
||||||
return {
|
return {
|
||||||
label: app.getName(),
|
label: app.getName(),
|
||||||
submenu: appMenu,
|
submenu: appMenu,
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
private static EditMenu(isMac: boolean): MenuItemConstructorOptions {
|
private static EditMenu(): MenuItemConstructorOptions {
|
||||||
let editMenu: MenuItemConstructorOptions[] = [
|
let editMenu: MenuItemConstructorOptions[] = [
|
||||||
{ role: 'undo' },
|
{ role: 'undo' },
|
||||||
{ role: 'redo' },
|
{ role: 'redo' },
|
||||||
|
@ -72,11 +72,11 @@ export default class ApplicationMenu {
|
||||||
{ role: 'delete' },
|
{ role: 'delete' },
|
||||||
{ role: 'selectall' },
|
{ role: 'selectall' },
|
||||||
...(isMac ? this.macOnlyEditMenu : []),
|
...(isMac ? this.macOnlyEditMenu : []),
|
||||||
];
|
]
|
||||||
return {
|
return {
|
||||||
label: 'Edit',
|
label: 'Edit',
|
||||||
submenu: editMenu,
|
submenu: editMenu,
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
private static ViewMenu(): MenuItemConstructorOptions {
|
private static ViewMenu(): MenuItemConstructorOptions {
|
||||||
let viewMenu: MenuItemConstructorOptions[] = [
|
let viewMenu: MenuItemConstructorOptions[] = [
|
||||||
|
@ -85,13 +85,13 @@ export default class ApplicationMenu {
|
||||||
{ role: 'toggledevtools' },
|
{ role: 'toggledevtools' },
|
||||||
{ type: 'separator' },
|
{ type: 'separator' },
|
||||||
{ role: 'togglefullscreen' },
|
{ role: 'togglefullscreen' },
|
||||||
];
|
]
|
||||||
return {
|
return {
|
||||||
label: 'View',
|
label: 'View',
|
||||||
submenu: viewMenu
|
submenu: viewMenu
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
private static WindowMenu(isMac: boolean): MenuItemConstructorOptions {
|
private static WindowMenu(): MenuItemConstructorOptions {
|
||||||
let windowMenu: MenuItemConstructorOptions[] = isMac ? [
|
let windowMenu: MenuItemConstructorOptions[] = isMac ? [
|
||||||
{ role: 'close' },
|
{ role: 'close' },
|
||||||
{ role: 'minimize' },
|
{ role: 'minimize' },
|
||||||
|
@ -101,11 +101,11 @@ export default class ApplicationMenu {
|
||||||
] : [
|
] : [
|
||||||
{ role: 'minimize' },
|
{ role: 'minimize' },
|
||||||
{ role: 'close' },
|
{ role: 'close' },
|
||||||
];
|
]
|
||||||
return {
|
return {
|
||||||
label: 'Window',
|
label: 'Window',
|
||||||
submenu: windowMenu,
|
submenu: windowMenu,
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
private static HelpMenu(): MenuItemConstructorOptions {
|
private static HelpMenu(): MenuItemConstructorOptions {
|
||||||
let helpMenu: MenuItemConstructorOptions[] = [
|
let helpMenu: MenuItemConstructorOptions[] = [
|
||||||
|
@ -117,10 +117,10 @@ export default class ApplicationMenu {
|
||||||
label: 'Learn More',
|
label: 'Learn More',
|
||||||
click: () => shell.openExternal(documentURL),
|
click: () => shell.openExternal(documentURL),
|
||||||
}
|
}
|
||||||
];
|
]
|
||||||
return {
|
return {
|
||||||
label: 'Help',
|
label: 'Help',
|
||||||
submenu: helpMenu,
|
submenu: helpMenu,
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ import {
|
||||||
} from 'electron'
|
} from 'electron'
|
||||||
import { register as shortcutRegister } from 'electron-localshortcut'
|
import { register as shortcutRegister } from 'electron-localshortcut'
|
||||||
|
|
||||||
declare const __static: string;
|
declare const __static: string
|
||||||
const isDevelopment = process.env.NODE_ENV !== 'production'
|
const isDevelopment = process.env.NODE_ENV !== 'production'
|
||||||
|
|
||||||
export interface CreateWindowOptions {
|
export interface CreateWindowOptions {
|
||||||
|
@ -23,6 +23,8 @@ export interface CreateWindowOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class Window {
|
export default class Window {
|
||||||
|
public static ApplicationURL: string = process.env.WEBPACK_DEV_SERVER_URL /* `electron:serve`で起動した時 */ || 'app://./' /* ビルドしたアプリ */
|
||||||
|
|
||||||
public static single: Map<string, BrowserWindow> = new Map()
|
public static single: Map<string, BrowserWindow> = new Map()
|
||||||
public static list: BrowserWindow[]
|
public static list: BrowserWindow[]
|
||||||
|
|
||||||
|
@ -64,7 +66,7 @@ export default class Window {
|
||||||
lastAction: (win) => {
|
lastAction: (win) => {
|
||||||
win.setMenuBarVisibility(false)
|
win.setMenuBarVisibility(false)
|
||||||
win.webContents.on('before-input-event', (event: Event, input: Input) => {
|
win.webContents.on('before-input-event', (event: Event, input: Input) => {
|
||||||
this.single.get('about')!.webContents.setIgnoreMenuShortcuts((process.platform === 'darwin' ? input.meta : input.control) && input.key === "r")
|
this.single.get('about')!.webContents.setIgnoreMenuShortcuts((process.platform === 'darwin' ? input.meta : input.control) && input.key === 'r')
|
||||||
})
|
})
|
||||||
shortcutRegister(win, 'Esc', () => this.single.get('about')!.destroy())
|
shortcutRegister(win, 'Esc', () => this.single.get('about')!.destroy())
|
||||||
},
|
},
|
||||||
|
@ -89,7 +91,7 @@ export default class Window {
|
||||||
})
|
})
|
||||||
|
|
||||||
let openUrl = (event: Event, url: string) => {
|
let openUrl = (event: Event, url: string) => {
|
||||||
if (isDevelopment && url === process.env.WEBPACK_DEV_SERVER_URL + options.loadPath) {
|
if (url === this.ApplicationURL + options.loadPath) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
|
@ -102,13 +104,7 @@ export default class Window {
|
||||||
win.webContents.on('will-navigate', openUrl)
|
win.webContents.on('will-navigate', openUrl)
|
||||||
win.webContents.on('new-window', openUrl)
|
win.webContents.on('new-window', openUrl)
|
||||||
|
|
||||||
if (process.env.WEBPACK_DEV_SERVER_URL) {
|
win.loadURL(this.ApplicationURL + options.loadPath)
|
||||||
// `electron:serve`で起動した時の読み込み
|
|
||||||
win.loadURL(process.env.WEBPACK_DEV_SERVER_URL + options.loadPath)
|
|
||||||
} else {
|
|
||||||
// ビルドしたアプリでの読み込み
|
|
||||||
win.loadURL(`app://./${options.loadPath}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isDevelopment && options.openDevTools) win.webContents.openDevTools()
|
if (isDevelopment && options.openDevTools) win.webContents.openDevTools()
|
||||||
|
|
||||||
|
|
|
@ -42,8 +42,8 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Component, Vue } from "vue-property-decorator"
|
import { Component, Vue } from 'vue-property-decorator'
|
||||||
import { ipcRenderer } from "electron"
|
import { ipcRenderer } from 'electron'
|
||||||
|
|
||||||
type Versions = { [key: string]: string }
|
type Versions = { [key: string]: string }
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ interface Maintainer {
|
||||||
interface TheDeskInfo {
|
interface TheDeskInfo {
|
||||||
productName: string
|
productName: string
|
||||||
author: Maintainer
|
author: Maintainer
|
||||||
contributors: [Maintainer]
|
contributors: Maintainer[]
|
||||||
homePage: string
|
homePage: string
|
||||||
copyrightYear: string
|
copyrightYear: string
|
||||||
codeName: string
|
codeName: string
|
||||||
|
@ -66,7 +66,7 @@ interface TheDeskInfo {
|
||||||
export default class About extends Vue {
|
export default class About extends Vue {
|
||||||
public productName: string
|
public productName: string
|
||||||
public author: Maintainer
|
public author: Maintainer
|
||||||
public contributors: [Maintainer]
|
public contributors: Maintainer[]
|
||||||
public homePage: string
|
public homePage: string
|
||||||
public copyrightYear: string
|
public copyrightYear: string
|
||||||
public versions: Versions
|
public versions: Versions
|
||||||
|
@ -74,7 +74,7 @@ export default class About extends Vue {
|
||||||
public get ctrHtml(): string {
|
public get ctrHtml(): string {
|
||||||
return this.contributors.map(contributer => {
|
return this.contributors.map(contributer => {
|
||||||
return `<a href="${contributer.url}" target="_blank">${contributer.name}</a>`
|
return `<a href="${contributer.url}" target="_blank">${contributer.name}</a>`
|
||||||
}).join(", ")
|
}).join(', ')
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
<template>
|
<template>
|
||||||
<div id="app">
|
<div id="app">
|
||||||
<img alt="Vue logo" src="@/assets/logo.png" />
|
<img alt="Vue logo" src="@/assets/logo.png">
|
||||||
<Welcome />
|
<Welcome/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Component, Vue } from 'vue-property-decorator';
|
import { Component, Vue } from 'vue-property-decorator'
|
||||||
import Welcome from '@/components/Welcome.vue';
|
import Welcome from '@/components/Welcome.vue'
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
components: {
|
components: {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const { productName, author } = require("./package.json");
|
const { productName, author } = require('./package.json')
|
||||||
const { appId, copyrightYear } = require("./info.json");
|
const { appId, copyrightYear } = require('./info.json')
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
pages: {
|
pages: {
|
||||||
|
@ -32,29 +32,29 @@ module.exports = {
|
||||||
appId: appId,
|
appId: appId,
|
||||||
copyright: `Copyright © ${copyrightYear} ${author.name}`,
|
copyright: `Copyright © ${copyrightYear} ${author.name}`,
|
||||||
win: {
|
win: {
|
||||||
"target": [
|
'target': [
|
||||||
"nsis",
|
'nsis',
|
||||||
"portable",
|
'portable',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
nsis: {
|
nsis: {
|
||||||
oneClick: false,
|
oneClick: false,
|
||||||
allowToChangeInstallationDirectory: true,
|
allowToChangeInstallationDirectory: true,
|
||||||
artifactName: "TheDesk-Vue-setup.${ext}",
|
artifactName: 'TheDesk-Vue-setup.${ext}',
|
||||||
},
|
},
|
||||||
linux: {
|
linux: {
|
||||||
target: [
|
target: [
|
||||||
"snap",
|
'snap',
|
||||||
],
|
],
|
||||||
category: "Network",
|
category: 'Network',
|
||||||
},
|
},
|
||||||
mac: {
|
mac: {
|
||||||
darkModeSupport: true,
|
darkModeSupport: true,
|
||||||
target: [
|
target: [
|
||||||
"dmg",
|
'dmg',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
}
|
Loading…
Reference in New Issue
Block a user