10
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Youtubeデスクトップ版もどきをElectronで(Windows用)

Last updated at Posted at 2023-02-04

ない・・・ない!

ないんですよ!デスクトップ版ようつべが!!!!

てんわけでElectronでYotubeのサイトを表示するだけのソフトを作りました。

electronインスコ

1.package.json生成&electronインスコ

npm init -y

npm i electron

2. 設定ファイル記述

const { app, BrowserWindow } = require('electron')
const path = require('path')

function createWindow () {
    const win = new BrowserWindow({
        width: 800,
        height: 600,
    })
    win.loadURL('https://youtube.com/')

    app.whenReady().then(() => {
        createWindow()

        app.on('activate', () => {
            if (BrowserWindow.getAllWindows().length === 0) {
                createWindow()
            }
        })
    })

    app.on('window-all-closed', () => {
        if (process.platform !== 'darwin') {
            app.quit()
        }
    })
}

3.デバック

npx electron .

4.ビルド

electron-builderもありますが、今回は簡易的なソフトを作るだけなのでelectron-packagerを使います。

npm i electron-packager

(windows only)
npx electron-packager . youtube-desktop-luncher --x64 --win32

追記

ちなみにnpm scriptsを使う場合は

...
"scripts" : {
    "electron" : "electron ."
}
...

で行けます

あとjsが}が抜けてたりしてたので修正しました( ノД`)シクシク…

あと私のブログもよろしくです。

続編(?)

10
7
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?