Skip to content

Commit

Permalink
先頭と末尾にピンどめ、閉じると強制終了 (#21)
Browse files Browse the repository at this point in the history
* 先頭と末尾にピンどめ、閉じると強制終了

* fix

* 先頭と末尾のアプリケーションを並べ替える

* よさそう
  • Loading branch information
fruitriin authored Nov 5, 2023
1 parent 9c5a373 commit 89c5ebf
Show file tree
Hide file tree
Showing 10 changed files with 350 additions and 73 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
# If the commit is tagged with a version (e.g. "v1.0.0"),
# release the app after building
release: ${{ startsWith(github.ref, 'refs/tags/v') }}
args: --universal

env:
CSC_LINK: ~/.cert.p12
Expand Down
47 changes: 44 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 10 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "taskbar.fm",
"version": "1.6.1",
"version": "1.6.2",
"description": "Taskbar like windows for mac",
"main": "./out/main/index.js",
"author": "FruitRiin",
Expand All @@ -13,24 +13,30 @@
"typecheck": "npm run typecheck:node && npm run typecheck:web",
"start": "electron-vite preview",
"dev": "electron-vite dev",
"helper": "swiftc src/native/helper.swift -o resources/TaskbarHelper ",
"helper": "swiftc src/native/helper.swift -o resources/TaskbarHelper",
"build": "npm run typecheck && electron-vite build",
"postinstall": "electron-builder install-app-deps",
"build:win": "npm run build && electron-builder --win --config",
"build:mac": "npm run build && electron-builder --mac",
"build:mac": "npm run build && electron-builder --mac ",
"build:linux": "npm run build && electron-builder --linux --config",
"afterSign": "scripts/notarize.js",
"install-app": "rm -rf /Applications/taskbar.fm.app && cp -a dist/mac-arm64/taskbar.fm.app /Applications/taskbar.fm.app"
},
"dmg": {
"sign": false
},

"mac": {
"universal": true
},
"dependencies": {
"@electron-toolkit/preload": "^1.0.3",
"@electron-toolkit/utils": "^1.0.2",
"electron-updater": "^5.3.0",
"fast-sort": "^3.4.0",
"pinia": "^2.1.4",
"vue-router": "^4.2.4"
"vue-router": "^4.2.4",
"vuedraggable": "^4.1.0"
},
"devDependencies": {
"@electron-toolkit/tsconfig": "^1.0.1",
Expand Down
Binary file modified resources/TaskbarHelper
Binary file not shown.
55 changes: 54 additions & 1 deletion src/main/funcs/events.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// レンダラープロセスからのメッセージを受信する
import { createOptionWindow, createWindow, taskbars, windowPosition } from './windows'
import { activateWindow, grantPermission, macWindowProcesses } from './helper'
import { activateWindow, closeWindow, grantPermission, macWindowProcesses } from './helper'
import { app, ipcMain, screen } from 'electron'
import { Options, store } from './store'
import { Menu, MenuItem } from 'electron'
import { MacWindow } from '../type'

export function setEventHandlers() {
ipcMain.on('activeWindow', (_event, windowId) => {
Expand Down Expand Up @@ -44,6 +46,30 @@ export function setEventHandlers() {
app.relaunch()
app.quit()
})
// タスクを右クリックしたときのコンテキストメニュー
ipcMain.on('contextTask', (_event, value: MacWindow) => {
const menu = new Menu()
menu.append(moveAreaMenu(value.kCGWindowOwnerName, 'headers'))
menu.append(moveAreaMenu(value.kCGWindowOwnerName, 'footers'))
menu.append(
new MenuItem({
label: '閉じる',
click() {
activateWindow(value)
closeWindow(value)
}
})
)
menu.append(
new MenuItem({
label: '強制終了',
click() {
process.kill(value.kCGWindowOwnerPID)
}
})
)
menu.popup({})
})
screen.on('display-added', (_, newDisplay) => {
createWindow(newDisplay)
})
Expand All @@ -52,3 +78,30 @@ export function setEventHandlers() {
delete taskbars[oldDisplay.id]
})
}

function moveAreaMenu(kCGWindowOwnerName: string, area: 'headers' | 'footers') {
const position = store.store.options[area].indexOf(kCGWindowOwnerName)
const labelName = {
headers: '先頭',
footers: '末尾'
} as const

return new MenuItem({
click(_menuItem, _browserWindow) {
if (position < 0) {
store.set('options.' + area, [...store.store.options[area], kCGWindowOwnerName])
} else {
const tmp = store.store.options[area]
tmp.splice(position, 1)
store.set('options.' + area, tmp)
}
updateOptions()
},
label: position < 0 ? `${labelName[area]}へ追加` : `${labelName[area]}から削除`
})
}
function updateOptions() {
for (const taskbarsKey in taskbars) {
taskbars[taskbarsKey].webContents.send('updateOptions', store.store.options)
}
}
30 changes: 30 additions & 0 deletions src/main/funcs/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,36 @@ end tell
})
}

// ウィンドウを閉じるにする関数
export function closeWindow(window: MacWindow): void {
const script = `tell application "System Events"
set targetProcess to first application process whose unix id is ${window.kCGWindowOwnerPID}
set targetAppWindows to windows of targetProcess
repeat with currentWindow in targetAppWindows
if name of currentWindow contains "${escape(window.kCGWindowName)}" then
try
perform action "AXPress" of (first button of currentWindow whose subrole is "AXCloseButton")
exit repeat -- ウィンドウを閉じたらリピートから抜ける
on error
display dialog "閉じるボタンが見つかりません。"
exit repeat -- エラーが発生した場合もリピートから抜ける
end try
end try
end if
end repeat
end tell
`
exec(`osascript -e '${script}'`, (error, _stdout, _stderr) => {
if (error) {
console.error(`Error executing AppleScript: ${error}`)
return
}
// console.log(_stderr);
// console.log(_stdout);
})
}

/**
* 高さ・幅が低すぎるものと、store.filters から条件に一致するものを除外する
*/
Expand Down
4 changes: 3 additions & 1 deletion src/main/funcs/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ export const store = new ElectronStore({
defaults: {
options: {
layout: 'bottom' as LayoutType,
windowSortByPositionInApp: false
windowSortByPositionInApp: false,
headers: [] as string[],
footers: [] as string[]
},
filters: [
[{ property: 'kCGWindowIsOnscreen', is: false }],
Expand Down
Loading

0 comments on commit 89c5ebf

Please sign in to comment.