本文整理匯總了TypeScript中electron.app.dock.setIcon方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript app.dock.setIcon方法的具體用法?TypeScript app.dock.setIcon怎麽用?TypeScript app.dock.setIcon使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類electron.app.dock
的用法示例。
在下文中一共展示了app.dock.setIcon方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: windowBounds
app.on("ready", () => {
const bounds = windowBounds();
let options: Electron.BrowserWindowConstructorOptions = {
webPreferences: {
experimentalFeatures: true,
experimentalCanvasFeatures: true,
},
titleBarStyle: "hidden",
resizable: true,
minWidth: 500,
minHeight: 300,
width: bounds.width,
height: bounds.height,
x: bounds.x,
y: bounds.y,
show: false,
};
const browserWindow = new BrowserWindow(options);
if (app.dock) {
app.dock.setIcon(nativeImage.createFromPath("build/icon.png"));
} else {
browserWindow.setIcon(nativeImage.createFromPath("build/icon.png"));
}
browserWindow.loadURL("file://" + __dirname + "/../views/index.html");
browserWindow.webContents.on("did-finish-load", () => {
browserWindow.show();
browserWindow.focus();
});
app.on("open-file", (_event, file) => browserWindow.webContents.send("change-working-directory", file));
});
示例2: createWindow
loading.then((loaded: [Config, WatchDog]) => {
const [config, dog] = loaded;
global.config = config;
const icon_path = path.join(__dirname, '..', '..', 'images', 'shibainu.png');
let win = createWindow(config, icon_path);
win.once('closed', function() {
win = null;
});
const html = 'file://' + path.join(__dirname, '..', '..', 'static', 'index.html');
win.loadURL(html);
dog.wakeup(win.webContents);
win.webContents.on('will-navigate', function(e: Event, url: string) {
e.preventDefault();
shell.openExternal(url);
});
menu.build(win);
if (process.argv[0].endsWith('Electron') && process.platform === 'darwin') {
// Note:
// If Shiba is run as npm package, replace dock app icon
app.dock.setIcon(icon_path);
}
if (process.env.NODE_ENV === 'development') {
win.webContents.once('devtools-opened', () => setImmediate(() => win.focus()));
win.webContents.openDevTools({mode: 'detach'});
}
}).catch(e => {
示例3: windowBounds
import {app, ipcMain, nativeImage, BrowserWindow, screen} from "electron";
import {readFileSync} from "fs";
import {windowBoundsFilePath} from "../utils/Common";
if (app.dock) {
app.dock.setIcon(nativeImage.createFromPath("build/icon.png"));
}
app.on("ready", () => {
const bounds = windowBounds();
let options: Electron.BrowserWindowOptions = {
webPreferences: {
experimentalFeatures: true,
experimentalCanvasFeatures: true,
},
titleBarStyle: "hidden",
resizable: true,
minWidth: 500,
minHeight: 300,
width: bounds.width,
height: bounds.height,
x: bounds.x,
y: bounds.y,
show: false,
};
const browserWindow = new BrowserWindow(options);
if (process.env.REACT_EXTENSION_PATH) {
BrowserWindow.addDevToolsExtension(process.env.REACT_EXTENSION_PATH);
}
示例4: createRootWindow
async function createRootWindow(store: IStore) {
const window = "root";
const role: ItchWindowRole = "main";
const userBounds = config.get(BOUNDS_CONFIG_KEY) || {};
const bounds = {
x: -1,
y: -1,
width: 1250,
height: 720,
...userBounds,
};
const { width, height } = bounds;
const center = bounds.x === -1 && bounds.y === -1;
let opts: Electron.BrowserWindowConstructorOptions = {
...commonBrowserWindowOpts(),
title: app.getName(),
width,
height,
center,
show: false,
};
const nativeWindow = new BrowserWindow(opts);
store.dispatch(
actions.windowOpened({
window,
role,
nativeId: nativeWindow.id,
initialURL: "itch://library",
})
);
if (os.platform() === "darwin") {
try {
app.dock.setIcon(getIconPath());
} catch (err) {
logger.warn(`Could not set dock icon: ${err.stack}`);
}
}
if (!center) {
nativeWindow.setPosition(bounds.x, bounds.y);
}
ensureWindowInsideDisplay(nativeWindow);
nativeWindow.on("close", (e: any) => {
const prefs = store.getState().preferences || { closeToTray: true };
let { closeToTray } = prefs;
if (env.integrationTests) {
// always let app close in testing
closeToTray = false;
}
if (closeToTray) {
logger.debug("Close to tray enabled");
} else {
logger.debug("Close to tray disabled, quitting!");
process.nextTick(() => {
store.dispatch(actions.quit({}));
});
return;
}
if (!nativeWindow.isVisible()) {
logger.info("Main window hidden, letting it close");
return;
}
if (!prefs.gotMinimizeNotification) {
store.dispatch(
actions.updatePreferences({
gotMinimizeNotification: true,
})
);
const i18n = store.getState().i18n;
store.dispatch(
actions.notify({
title: t(i18n, ["notification.see_you_soon.title"]),
body: t(i18n, ["notification.see_you_soon.message"]),
})
);
}
// hide, never destroy
e.preventDefault();
logger.info("Hiding main window");
nativeWindow.hide();
});
hookNativeWindow(store, window, nativeWindow);
nativeWindow.on("maximize", (e: any) => {
config.set(MAXIMIZED_CONFIG_KEY, true);
});
nativeWindow.on("unmaximize", (e: any) => {
config.set(MAXIMIZED_CONFIG_KEY, false);
});
//.........這裏部分代碼省略.........
示例5: createRootWindow
async function createRootWindow(store: Store) {
const wind = "root";
const role: WindRole = "main";
const userBounds = config.get(BOUNDS_CONFIG_KEY) || {};
const bounds = {
x: -1,
y: -1,
width: 1250,
height: 720,
...userBounds,
};
const { width, height } = bounds;
const center = bounds.x === -1 && bounds.y === -1;
let opts: Electron.BrowserWindowConstructorOptions = {
...commonBrowserWindowOpts(store),
title: app.getName(),
width,
height,
center,
};
const nativeWindow = new BrowserWindow(opts);
store.dispatch(
actions.windOpened({
wind,
role,
nativeId: nativeWindow.id,
initialURL: "itch://library",
})
);
if (process.platform === "darwin") {
try {
app.dock.setIcon(getIconPath());
} catch (err) {
logger.warn(`Could not set dock icon: ${err.stack}`);
}
}
if (!center) {
nativeWindow.setPosition(bounds.x, bounds.y);
}
ensureWindowInsideDisplay(nativeWindow);
nativeWindow.on("close", (e: any) => {});
hookNativeWindow(store, wind, nativeWindow);
nativeWindow.on("maximize", (e: any) => {
config.set(MAXIMIZED_CONFIG_KEY, true);
});
nativeWindow.on("unmaximize", (e: any) => {
config.set(MAXIMIZED_CONFIG_KEY, false);
});
nativeWindow.loadURL(makeAppURL({ wind, role }));
if (parseInt(process.env.DEVTOOLS || "0", 10) > 0) {
openAppDevTools(nativeWindow);
}
}
示例6: open_window
//.........這裏部分代碼省略.........
const twitter = new Twitter();
twitter.prepareClient({
consumer_key,
consumer_secret,
access_token: access.token,
access_token_secret: access.token_secret,
});
twitter.sender = new IpcSender(win.webContents);
if (should_use_dummy_data) {
twitter
.sendDummyAccount()
.then(() => twitter.sendDummyStream())
.catch(e => log.error('Unexpected error on dummy stream:', e));
return;
}
twitter
.sendAuthenticatedAccount()
.catch(err => {
if (!err || (err instanceof Error) || err[0].code !== 32) {
log.error('Unexpected error on verifying account:', err);
return;
}
log.debug('Retry authentication flow');
return authenticate(consumer_key, consumer_secret)
.then((a: AccessToken) => {
if (!a.token || !a.token_secret) {
log.error('Invalid access tokens:', a);
return;
}
twitter.prepareClient({
consumer_key,
consumer_secret,
access_token: a.token,
access_token_secret: a.token_secret,
});
})
.then(() => twitter.sendAuthenticatedAccount())
.catch(e => {
log.error('Give up: Second authentication try failed. If you use environment variables for tokens, please check them:', e);
});
})
.then(() => Promise.all([
twitter.fetchMuteIds(),
twitter.fetchNoRetweets(),
twitter.fetchBlockIds(),
twitter.fetchHomeTimeline(),
twitter.fetchMentionTimeline(),
]))
.then(([mute_ids, no_retweet_ids, block_ids, tweets, mentions]) => {
// Note: Merge mute list with block list
for (const m of mute_ids) {
if (block_ids.indexOf(m) === -1) {
block_ids.push(m);
}
}
log.debug('Total rejected ids: ', block_ids.length);
twitter.sender.send('yf:rejected-ids', block_ids);
twitter.sender.send('yf:no-retweet-ids', no_retweet_ids);
for (const tw of tweets) {
twitter.sender.send('yf:tweet', tw);
}
twitter.sender.send('yf:mentions', mentions);
})
.then(() => twitter.connectToStream())
.catch((e: any) => log.error('Unexpected error on streaming', e));
powerMonitor.on('suspend', () => {
log.debug("PC's going to suspend, stop streaming");
if (!should_use_dummy_data) {
twitter.stopStreaming();
}
});
powerMonitor.on('resume', () => {
log.debug("PC's resuming, will reconnect after 3secs: " + twitter.isStopped());
if (twitter.isStopped() && !should_use_dummy_data) {
twitter.sendConnectionFailure();
twitter.connectToStream();
}
});
});
} else {
log.error('Failed to get access tokens');
}
win.loadURL(index_html);
if (isRunFromNpmPackageOnDarwin()) {
app.dock.setIcon(icon_path);
}
setApplicationMenu(win);
if (process.env.NODE_ENV === 'development') {
win.webContents.on('devtools-opened', () => setImmediate(() => win.focus()));
win.webContents.openDevTools({mode: 'detach'});
}
}
示例7: createMainWindow
// This method will be called when Electron has done everything
// initialization and ready for creating browser windows.
app.on('ready', () => {
createMainWindow()
createReaderWindow()
})
app.on('activate', () => {
// On OS X it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (mainWindow === null) {
createMainWindow()
}
if (readerWindow === null) {
createReaderWindow()
}
})
// set dock icon on mac os x
if (process.platform === 'darwin') {
app.dock.setIcon(path.join(__dirname, '/app/assets/image/logo-128x128.png'))
}
// bind ipc actions
ipcMain.on('open-reader', (event, arg) => {
mainWindow.hide()
readerWindow.show()
readerWindow.webContents.send('reader-open-book', arg)
})